Repository navigation
fix: reject public JWT placeholders during production startup - #66
Conversation
Reviewer's GuideProduction startup now blocks the repository's JWT placeholders as well as empty or whitespace-only secrets, preventing token forgery when deployments copy the example configuration; the change centralizes insecure values, documents the coupling, and adds focused regression tests while preserving development zero-configuration and valid production secrets. Sequence diagram for production JWT secret validationsequenceDiagram
participant App as Application
participant Settings as AppSettings
participant Startup as validate_startup_configuration
participant Error as ConfigurationError
App->>Settings: jwt_secret_is_default
Settings->>Settings: strip()
Settings->>Settings: Check blank or INSECURE_JWT_SECRET_KEYS
Settings-->>Startup: insecure status
alt production and insecure secret
Startup->>Error: Raise ConfigurationError
else real secret or non-production default
Startup-->>App: Continue startup
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
👋 Thanks for opening this PR! A maintainer will review it soon. In the meantime, please make sure you've read CONTRIBUTING.md and filled out the PR template, including screenshots for any visual changes. |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="core/config.py" line_range="109-111" />
<code_context>
+# `.env.example` is the value most deployments actually start from, and it
+# was previously accepted because the check compared against one constant.
+INSECURE_JWT_SECRET_KEYS = frozenset({
+ DEV_JWT_SECRET_KEY,
+ "your_secure_random_32_byte_jwt_secret_key",
+})
+
</code_context>
<issue_to_address>
**Known test key forges sessions**
When production is configured with the published test fixture secret, `INSECURE_JWT_SECRET_KEYS` omits the published test fixture, so `validate_startup_configuration` permits startup and `AuthService` signs and verifies tokens with a repository-known key; anyone who read the repository can forge sessions for any account.
Add the published test fixture value to `INSECURE_JWT_SECRET_KEYS` so production startup rejects it.
</issue_to_address>
### Comment 2
<location path="core/config.py" line_range="308" />
<code_context>
+ `DEV_JWT_SECRET_KEY`, so both are treated as insecure.
+ """
+ secret = self.jwt_secret_key.strip()
+ return not secret or secret in INSECURE_JWT_SECRET_KEYS
@property
</code_context>
<issue_to_address>
**Blank secrets are labeled as placeholders**
When the configured JWT secret is blank and the system-status page or startup error is shown, `jwt_secret_is_default` also returns true for an empty secret, but `AdminService.get_system_status` exposes that result as `jwt_secret_is_placeholder` and the admin page renders it as “JWT secret: PLACEHOLDER.” For blank values, operators see a placeholder diagnosis even though no key is configured.
Report the broader insecure-secret state without calling every case a placeholder, or distinguish blank values from published placeholders in the status and error descriptions.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: core/config.py:111, core/config.py:308
82195f2 to
e549441
Compare
|
🎉 Thanks for the contribution, @Senthil455! This PR has been merged. We appreciate you helping improve OpenHire. |
Fixes #65.
Problem
Production startup rejected only one hard-coded JWT placeholder:
But
.env.example, which is the starting point for most deployments, ships a different value:Copying the example, setting
ENVIRONMENT=production, and deploying therefore passed validation while signing tokens with a key published in the repository. Anyone who read the source could mint a token for any account. An emptyJWT_SECRET_KEY=was accepted too.Changes
core/config.py: addedINSECURE_JWT_SECRET_KEYScontaining both published values.jwt_secret_is_defaultnow trims the configured value, treats a blank secret as insecure, and checks membership in that set..env.example: added a comment tying the placeholder to the startup check so the two are less likely to drift again.tests/test_backend_foundation.py: parametrized regression test for the example placeholder, whitespace-only and empty values. The existing real-secret and development-default tests remain in place.Behaviour
ENVIRONMENT=productionwith the example placeholder or a blank secret now raisesConfigurationErrorduring startup.Tests
python -m pytest tests/test_backend_foundation.py -q-> 77 passed.Summary by Sourcery
Reject blank and repository-published JWT secrets in production while clearly reporting their configuration status in the admin interface.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: