-
Notifications
You must be signed in to change notification settings - Fork 721
Adds code for an interactive journalizing app #173
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
Conversation
| def search_entries(q: str, version: int = 1): | ||
| """Search entries using vector search, grouped by entry.""" | ||
| db = get_database() | ||
| logger.info(f"Searching entries with query: {q[:50]}... (version={version})") |
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>apps/interactive-journal/backend/app/routers/routes.py</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/mongodb-developer/GenAI-Showcase/blob/4499ef5b6f301c8d397af73649f61daaf348e9a3/apps/interactive-journal/backend/app/routers/routes.py#L99 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 99] version</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/mongodb-developer/GenAI-Showcase/blob/4499ef5b6f301c8d397af73649f61daaf348e9a3/apps/interactive-journal/backend/app/routers/routes.py#L99 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 99] version</a>"]
end
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/mongodb-developer/GenAI-Showcase/blob/4499ef5b6f301c8d397af73649f61daaf348e9a3/apps/interactive-journal/backend/app/routers/routes.py#L102 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 102] f"Searching entries with query: {q[:50]}... (version={version})"</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
| logger.info(f"Searching entries with query: {q[:50]}... (version={version})") | |
| # Sanitize user input to prevent log injection | |
| clean_q = q.replace('\n', ' ').replace('\r', ' ')[:50] | |
| logger.info(f"Searching entries with query: {clean_q}... (version={version})") |
View step-by-step instructions
- Avoid logging user-provided search queries directly using f-strings, as this may include malicious content in your logs.
- If you need to record user input for debugging, log a masked or length-limited version, and always use structured logging with separate fields. For example, use
logger.info("Searching entries", extra={"query": q[:50], "version": version}). - Alternatively, if you must include the value in the log message, sanitize the input by replacing newlines and special characters. For example:
clean_q = q.replace('\n', ' ').replace('\r', ' ')[:50]then log:logger.info(f"Searching entries with query: {clean_q}... (version={version})"). - Make sure to never log the full query if it may contain sensitive or user-controlled data to minimize risk of log injection.
Structured logging lets log processors or SIEM tools better handle and filter potentially unsafe or multiline user data.
💬 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.
🛟 Help? Slack #semgrep-help or go/semgrep-help.
Resolution Options:
- Fix the code
- Reply
/fp $reason(if security gap doesn’t exist) - Reply
/ar $reason(if gap is valid but intentional; add mitigations/monitoring) - Reply
/other $reason(e.g., test-only)
You can view more details about this finding in the Semgrep AppSec Platform.
No description provided.