Skip to content

🛡️ Sentinel: [CRITICAL] Fix hardcoded JWT secret fallback in templates#185

Closed
Tuntii wants to merge 1 commit into
mainfrom
sentinel/fix-jwt-secret-fallback-3037792376267280363
Closed

🛡️ Sentinel: [CRITICAL] Fix hardcoded JWT secret fallback in templates#185
Tuntii wants to merge 1 commit into
mainfrom
sentinel/fix-jwt-secret-fallback-3037792376267280363

Conversation

@Tuntii
Copy link
Copy Markdown
Owner

@Tuntii Tuntii commented May 22, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The full project template in cargo-rustapi provided a hardcoded default string ("dev-secret-change-in-production") if the JWT_SECRET environment variable was missing.
🎯 Impact: Applications generated from this template could be inadvertently deployed to production with a known, insecure default secret if the environment configuration was missed, leading to critical authentication bypasses.
🔧 Fix: Replaced .unwrap_or_else() with .map_err(), returning an ApiError::internal("JWT_SECRET environment variable is not set") when the secret is missing.
Verification: Verified by running cargo check and cargo test -p cargo-rustapi to ensure no functionality is broken and templates are correctly generated.


PR created automatically by Jules for task 3037792376267280363 started by @Tuntii

The `full.rs` code generation template in `cargo-rustapi` previously used `.unwrap_or_else()` to fall back to a hardcoded string ("dev-secret-change-in-production") if the `JWT_SECRET` environment variable was missing. This patch modifies the logic to use `.map_err()` to return a secure internal server error instead, ensuring applications generated from this template fail securely rather than silently adopting an insecure default secret.
@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.

Copilot AI review requested due to automatic review settings May 22, 2026 15:40
Copy link
Copy Markdown
Contributor

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 updates the cargo-rustapi “full” project template to avoid generating applications that can silently fall back to a known default JWT signing secret when JWT_SECRET is missing, instead returning an error.

Changes:

  • Removed the hardcoded JWT secret fallback in the generated login handler.
  • Converts a missing/invalid JWT_SECRET into an ApiError::internal(...) error rather than continuing with an insecure secret.

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

Comment on lines 172 to +173
let jwt_secret = std::env::var("JWT_SECRET")
.unwrap_or_else(|_| "dev-secret-change-in-production".to_string());
.map_err(|_| ApiError::internal("JWT_SECRET environment variable is not set"))?;
@Tuntii Tuntii closed this May 24, 2026
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.

2 participants