Skip to content

fix(auth): enforce required JWT key to prevent forged token attacks - #1223

Draft
nbmaiti wants to merge 3 commits into
mainfrom
pr/jwt_no_default_jwt_key
Draft

fix(auth): enforce required JWT key to prevent forged token attacks#1223
nbmaiti wants to merge 3 commits into
mainfrom
pr/jwt_no_default_jwt_key

Conversation

@nbmaiti

@nbmaiti nbmaiti commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Prevents vulnerability by rejecting hardcoded insecure JWT defaults. Changed from hardcoded default 'your_secret_jwt_key' to empty string and added config validation that fails fast at startup if AUTH_JWT_KEY is not provided. This ensures proper JWT configuration for both YAML and environment variable deployments.

Prevents vulnerability by rejecting hardcoded insecure JWT defaults.
Changed from hardcoded default 'your_secret_jwt_key' to empty string and
added config validation that fails fast at startup if AUTH_JWT_KEY is not
provided. This ensures proper JWT configuration for both YAML and environment
variable deployments.

Signed-off-by: Nabendu Maiti <[email protected]>

Copilot AI left a comment

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.

Pull request overview

This PR hardens authentication configuration by removing an insecure default JWT signing key and introducing startup-time validation to prevent running with an unset JWT key.

Changes:

  • Removed the hardcoded default auth.jwtKey value (your_secret_jwt_key) from the in-memory default config.
  • Added config validation to fail fast when auth.jwtKey is empty.
  • Introduced a dedicated config error (ErrJWTKeyMissing) for missing JWT key configuration.
Suppressed comments (2)

config/config.go:423

  • Current jwtKey validation only rejects an empty string. Existing deployments (and the repo's config/config.yml) may still use the placeholder value "your_secret_jwt_key", which would pass validation and keeps the forged-token risk this PR intends to prevent. Consider explicitly rejecting that placeholder value as well.
	if c.JWTKey == "" {
		return ErrJWTKeyMissing
	}

config/config.go:423

  • New startup validation for auth.jwtKey should be covered by unit tests (e.g., NewConfig/validate returns ErrJWTKeyMissing when jwtKey is empty or set to the placeholder). This helps prevent regressions in config loading precedence (defaults vs YAML vs env).
	if c.JWTKey == "" {
		return ErrJWTKeyMissing
	}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread config/config.go
…uirements

Tests now set AUTH_JWT_KEY environment variable to satisfy the newly added
config validation that requires a non-empty JWT key at startup.

Signed-off-by: Nabendu Maiti <[email protected]>
The TestValidate_ValidDefaults test needs to set a valid JWT key
since validation now requires a non-empty key.

Signed-off-by: Nabendu Maiti <[email protected]>
@nbmaiti
nbmaiti force-pushed the pr/jwt_no_default_jwt_key branch from 4dd0d9d to 1168c14 Compare August 26, 2026 15:22
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