Skip to content

fix: reject public JWT placeholders during production startup - #66

Merged
DevSidd2006 merged 3 commits into
DevSidd2006:mainfrom
Senthil455:fix/jwt-placeholder-secret
Oct 28, 2026
Merged

DevSidd2006 merged 3 commits into
DevSidd2006:mainfrom
Senthil455:fix/jwt-placeholder-secret

Conversation

@Senthil455

@Senthil455 Senthil455 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #65.

Problem

Production startup rejected only one hard-coded JWT placeholder:

DEV_JWT_SECRET_KEY = "dev-secret-key-change-in-production"
return self.jwt_secret_key == DEV_JWT_SECRET_KEY

But .env.example, which is the starting point for most deployments, ships a different value:

JWT_SECRET_KEY=your_secure_random_32_byte_jwt_secret_key

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 empty JWT_SECRET_KEY= was accepted too.

Changes

  • core/config.py: added INSECURE_JWT_SECRET_KEYS containing both published values.
  • jwt_secret_is_default now 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=production with the example placeholder or a blank secret now raises ConfigurationError during startup.
  • Development remains zero-configuration: the development default is still allowed outside production.
  • A real secret is still accepted.

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:

  • Expose separate admin status indicators for unconfigured and repository-known JWT secrets.

Bug Fixes:

  • Prevent production startup with blank, example, test, or development JWT secrets that could allow forged authentication tokens.
  • Provide distinct startup diagnostics for missing versus public placeholder JWT secrets.

Enhancements:

  • Track all repository-published JWT values as insecure and normalize configured secrets before validation.

Documentation:

  • Document the relationship between the example JWT value and production startup validation.

Tests:

  • Add regression coverage for public and blank production secrets and for preserving JWT status flags through the admin response schema.

@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Production 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 validation

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Expand production JWT startup validation to reject every published placeholder and blank secret.
  • Centralize the development and example placeholder values in an insecure-key set.
  • Trim configured secrets and classify empty, whitespace-only, and published values as insecure.
  • Preserve acceptance of real secrets and development defaults outside production.
core/config.py
Add regression coverage for public and blank JWT secret values during production startup.
  • Parameterize startup-validation tests for the example placeholder, whitespace-only input, and an empty value.
  • Retain coverage for the existing development default and valid real-secret behavior.
tests/test_backend_foundation.py
Document the relationship between the example JWT placeholder and the production startup check.
  • Add an explanatory comment next to the example configuration value to reduce future drift.
.env.example

Assessment against linked issues

Issue Objective Addressed Explanation
#65 Reject the development key, the .env.example placeholder, and blank or whitespace-only JWT secrets in production, while continuing to allow the development default outside production and accepting a real secret. ✅
#65 Add regression coverage for the .env.example placeholder and blank secrets while retaining coverage for the existing default, a real secret, and development behavior. ✅
#65 Add a comment next to the JWT placeholder in .env.example linking it to the startup validation. ❌ The provided diff does not include a change to .env.example, so the requested comment is not present.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

👋 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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread core/config.py Resolved
Comment thread core/config.py Resolved
@Senthil455
Senthil455 force-pushed the fix/jwt-placeholder-secret branch from 82195f2 to e549441 Compare October 23, 2026 15:41
@DevSidd2006
DevSidd2006 merged commit ad1074e into DevSidd2006:main Oct 28, 2026
5 of 6 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Thanks for the contribution, @Senthil455! This PR has been merged. We appreciate you helping improve OpenHire.

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.

[BUG] Production startup accepts the public JWT secret from .env.example

2 participants