Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix hardcoded JWT secret and restrict CORS#1

Closed
davidraehles wants to merge 3 commits intomainfrom
sentinel-backend-hardening-15109285565255988971
Closed

🛡️ Sentinel: [CRITICAL/HIGH] Fix hardcoded JWT secret and restrict CORS#1
davidraehles wants to merge 3 commits intomainfrom
sentinel-backend-hardening-15109285565255988971

Conversation

@davidraehles
Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL/HIGH
💡 Vulnerability: Hardcoded fallback for JWT_SECRET and wide-open CORS policy.
🎯 Impact: Attackers could potentially exploit the known secret to forge tokens or perform cross-origin attacks.
🔧 Fix: Removed hardcoded secret fallback (enforced in production) and restricted CORS origins.
✅ Verification: Verified build success and correct logic via code review.


PR created automatically by Jules for task 15109285565255988971 started by @davidraehles

- Remove hardcoded fallback for JWT_SECRET in production
- Restrict CORS origins to trusted domains only
- Add security journaling in .jules/sentinel.md

Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 18, 2026 18:44
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses critical security vulnerabilities related to hardcoded JWT secrets and overly permissive CORS configuration. The changes enforce environment-based configuration for sensitive security settings while maintaining development-friendly fallbacks.

Changes:

  • Enforced JWT_SECRET environment variable requirement in production with fail-fast validation
  • Restricted CORS to specific origins using environment-based configuration with localhost development fallbacks
  • Added Sentinel journal documentation describing the vulnerabilities and preventive measures

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
backend/src/middleware/auth.ts Added production environment check for JWT_SECRET with development fallback, preventing hardcoded secrets in production
backend/src/server.ts Replaced open CORS policy with origin whitelist based on ALLOWED_ORIGINS environment variable
.jules/sentinel.md Added security journal entry documenting the hardcoded secret and CORS vulnerabilities with lessons learned

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/src/middleware/auth.ts Outdated

const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key-change-in-production';
// 🛡️ Sentinel: Ensure JWT_SECRET is set in environment, especially in production
if (!process.env.JWT_SECRET && process.env.NODE_ENV === 'production') {
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production check uses a top-level throw statement that executes at module load time. This is good for fail-fast behavior, but consider that if NODE_ENV is not set (undefined), the check will pass even in production environments. Consider making the check more strict by also validating when NODE_ENV is undefined or empty. For example:

if (!process.env.JWT_SECRET && (!process.env.NODE_ENV || process.env.NODE_ENV === 'production'))

This ensures that the JWT_SECRET is required unless explicitly running in a known development environment.

Suggested change
if (!process.env.JWT_SECRET && process.env.NODE_ENV === 'production') {
if (
!process.env.JWT_SECRET &&
(!process.env.NODE_ENV || process.env.NODE_ENV === 'production')
) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Expanded the condition to also require JWT_SECRET when NODE_ENV is undefined — now only explicitly set dev/test environments skip the check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Expanded the condition to also require JWT_SECRET when NODE_ENV is undefined — now only explicitly set dev/test environments skip the check.

Comment thread backend/src/server.ts
Comment on lines +16 to +22
app.use(cors({
origin: process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',').map(s => s.trim())
: ['http://localhost:5173', 'http://localhost:3000'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization']
}));
Copy link

Copilot AI Feb 18, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

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').

Copy link
Copy Markdown
Contributor

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').

OpenCode and others added 2 commits February 18, 2026 21:14
- Require JWT_SECRET and ALLOWED_ORIGINS when NODE_ENV is 'production' or undefined
- Improve CORS configuration with origin trimming
- Update security journal with latest learnings

Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
davidraehles pushed a commit that referenced this pull request Feb 18, 2026
davidraehles added a commit that referenced this pull request Feb 18, 2026
…6-7-8-10-11-12-13-14

Merge PRs #1, #2, #3, #4, #5, #6, #7, #8, #10, #11, #12, #13, #14 into main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants