-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add prompt library with theme organization #80
base: main
Are you sure you want to change the base?
Conversation
Co-Authored-By: [email protected] <[email protected]>
Co-Authored-By: [email protected] <[email protected]>
Co-Authored-By: [email protected] <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: [email protected] <[email protected]>
Semgrep found 1 CORS policy allows any origin (using wildcard '*'). This is insecure and should be avoided. View Dataflow Graphflowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>llm_gateway/app.py</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L62 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 62] ["*"]</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L62 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 62] origins</a>"]
end
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L66 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 66] origins</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
Traces0:::invis
File0:::invis
%% Connections
Source --> Traces0
Traces0 --> Sink
|
|
||
@api.exception_handler(SQLAlchemyError) | ||
async def sqlalchemy_exception_handler(request: Request, exc: SQLAlchemyError): | ||
logging.error(f"Database error in {request.url.path}: {str(exc)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep identified an issue in your code:
Detected a logger that logs user input without properly neutralizing the output. The log message could contain characters like
and
and cause an attacker to forge log entries or include malicious content into the logs. Use proper input validation and/or output encoding to prevent log entries from being forged.
Dataflow graph
flowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>llm_gateway/app.py</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L49 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 49] request</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L49 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 49] request</a>"]
end
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/wealthsimple/llm-gateway/blob/66a0538d8fd74b608835e9ed9fabf6e69f486332/llm_gateway/app.py#L50 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 50] f"Database error in {request.url.path}: {str(exc)}"</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
Traces0:::invis
File0:::invis
%% Connections
Source --> Traces0
Traces0 --> Sink
To resolve this comment:
✨ Commit Assistant fix suggestion
logging.error(f"Database error in {request.url.path}: {str(exc)}") | |
import re | |
def sanitize_input(input_str): | |
# Allow only alphanumeric characters, slashes, underscores, and hyphens | |
return re.sub(r'[^a-zA-Z0-9/_-]', '', input_str) | |
@api.exception_handler(SQLAlchemyError) | |
async def sqlalchemy_exception_handler(request: Request, exc: SQLAlchemyError): | |
logging.error(f"Database error in {sanitize_input(request.url.path)}: {str(exc)}") | |
if hasattr(exc, "detail"): | |
return JSONResponse(status_code=503, content={"detail": exc.detail}) | |
return JSONResponse( | |
status_code=503, | |
content={"detail": "Database operation failed. Please try again later."}, | |
) |
View step-by-step instructions
- Sanitize the
request.url.path
before logging it to prevent log injection. You can use a simple sanitization function that removes or escapes potentially dangerous characters. - Define a sanitization function, for example:
def sanitize_input(input_str): return input_str.replace('\n', '').replace('\r', '').replace('\t', '')
- Use the sanitization function on
request.url.path
before logging:logging.error(f"Database error in {sanitize_input(request.url.path)}: {str(exc)}")
- Alternatively, if you want to ensure that only alphanumeric characters and a few safe symbols are logged, you can use a regular expression to filter the input:
import re def sanitize_input(input_str): return re.sub(r'[^a-zA-Z0-9/_-]', '', input_str)
- Replace the logging statement with the sanitized version:
logging.error(f"Database error in {sanitize_input(request.url.path)}: {str(exc)}")
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>
for false positive/ar <comment>
for acceptable risk/other <comment>
for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by tainted-log-injection-stdlib-fastapi.
You can view more details about this finding in the Semgrep AppSec Platform.
Add prompt library feature with theme-based organization
This PR adds a new prompt library feature that allows users to:
Technical Details
Testing
Link to Devin run: https://app.devin.ai/sessions/2430149b78eb49f6bff9c52e97afdb17
Requested by: [email protected]