Feat/cursor semgrep after file edit autofix#60
Open
brandong1 wants to merge 19 commits into
Open
Conversation
fix vuln
merging local changes
…zation
Fix IDOR vulnerability in the profile page that allowed users to access other users' profiles by manipulating the user_id cookie.
## Changes
- Fixed NameError where `user.password` was referenced before `user` was defined
- Reordered logic to fetch user from database before validating session token
- Added null checks for both `user_id` and `session_token` cookies
- Added authorization check to verify the session token belongs to the requested user
## Why
The original code had two critical issues:
1. The session_token check on line 40 referenced an undefined variable `user`, causing a NameError on every request
2. Even if the check worked, there was no verification that the authenticated session corresponded to the user_id being accessed
The fix ensures that the session_token in the cookie must match the password hash of the user whose profile is being requested. This binds the session to a specific user and prevents attackers from accessing other profiles by simply changing the user_id cookie value.
## Semgrep Finding Details
The idor_profile_page function reads user_id directly from a user-controllable cookie (line 44: request.cookies.get('user_id')) and uses it to query the database for that user's profile without any ownership verification. The session_token check on line 40 references an undefined variable 'user', causing a NameError that makes the authentication check non-functional. Even if the session check worked, there is no authorization logic verifying that the authenticated user's session corresponds to the requested user_id.
@36804960 requested Semgrep Assistant generate this pull request to fix [a finding](https://semgrep.dev/orgs/bg_demo/ai-findings/739590370).
fix IDOR vulnerability in idor_profile_page by adding session authorization
…arden SSRF download, parameterize SQL, remove MD5 auth and hardcoded Java JWT secrets
Introduce a narrow Semgrep rule (semgrep/autofix-demo.yml) that matches app.run(..., debug=True) in the __main__ block and autofixes to debug=False. Wire Cursor project hooks to run semgrep --autofix on agent file edits so the finding is corrected automatically after saves. Made-with: Cursor
Run in Terminal.app to load id_ed25519, verify github.com host keys, test ssh -T, and optionally register the key via gh ssh-key add. Made-with: Cursor
- path_traversal.py: replace f-string path concat with werkzeug safe_join, which raises NotFound on ../ sequences, absolute paths, and encoded variants; add isfile check to avoid 500 leaking server layout - ssrf.py: replace narrow hostname blocklist with pre-request DNS resolution + ipaddress checks covering all private/loopback/link-local/reserved ranges; add allow_redirects=False to close redirect-chain bypass to internal endpoints Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.