-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [CRITICAL/HIGH] Fix hardcoded JWT secret and restrict CORS #1
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
Closed
davidraehles
wants to merge
3
commits into
main
from
sentinel-backend-hardening-15109285565255988971
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8140ed2
π‘οΈ Sentinel: Fix hardcoded JWT secret and harden CORS configuration
google-labs-jules[bot] a52b2f0
fix: address review feedback - stricter env validation for JWT_SECRETβ¦
OpenCode 3ac7b46
π‘οΈ Sentinel: Harden JWT_SECRET and ALLOWED_ORIGINS checks
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Sentinel's Journal - Secure Notes Web App | ||
|
|
||
| ## 2025-05-15 - [Critical] Hardcoded JWT Secret and Open CORS | ||
| **Vulnerability:** The application had a hardcoded fallback for `JWT_SECRET` in `backend/src/middleware/auth.ts`, which would be used if the environment variable was missing. Additionally, CORS was configured to allow all origins in `backend/src/server.ts`. | ||
| **Learning:** Hardcoded secrets in code are a major risk as they often end up in version control and can be easily discovered by attackers. Overly permissive CORS allows any website to make requests to the API, increasing the risk of CSRF and other cross-origin attacks. | ||
| **Prevention:** Always require secrets to be provided via environment variables, especially in production. Fail fast if they are missing. Use restrictive CORS configurations that only allow trusted origins. |
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
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
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.
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.
The CORS configuration falls back to localhost origins when ALLOWED_ORIGINS is not set. While this is acceptable for development, consider adding a production safety check similar to the JWT_SECRET validation. In production, allowing localhost origins could be a security issue. Consider adding validation before the CORS middleware to ensure ALLOWED_ORIGINS is set in production environments.
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.
Fixed. Added a matching ALLOWED_ORIGINS production check before the CORS middleware β uses the same stricter pattern (throws when NODE_ENV is undefined or 'production').
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.
Fixed. Added a matching ALLOWED_ORIGINS production check before the CORS middleware β uses the same stricter pattern (throws when NODE_ENV is undefined or 'production').