Skip to content

fix(config): refuse to start with an empty SECRET_KEY#41299

Open
rusackas wants to merge 1 commit into
masterfrom
fix/secret-key-fail-closed
Open

fix(config): refuse to start with an empty SECRET_KEY#41299
rusackas wants to merge 1 commit into
masterfrom
fix/secret-key-fail-closed

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

check_secret_key() already refuses to start (in non-debug/non-testing mode) when SECRET_KEY equals the well-known placeholder constant, logging guidance and exiting. However, an explicitly empty SECRET_KEY was not covered: the environment fallback only substitutes the placeholder when the env var is unset, so a deployment that sets SECRET_KEY = "" (e.g. in superset_config.py) could reach the app with an empty key.

This treats a missing/empty SECRET_KEY the same as the placeholder — warn in debug/testing, refuse to start otherwise — closing the remaining gap with the existing guard.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — startup validation behavior.

TESTING INSTRUCTIONS

Unit tests added in tests/unit_tests/test_check_secret_key.py:

  • Empty / None / placeholder keys fail closed (SystemExit) in non-debug mode.
  • The same keys warn but start in debug/testing mode.
  • A strong key starts with no warning.

Run: pytest tests/unit_tests/test_check_secret_key.py

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

check_secret_key already refused to start (in non-debug/non-testing mode) when
SECRET_KEY equalled the well-known placeholder. An explicitly empty SECRET_KEY
(e.g. SECRET_KEY = "" set in superset_config.py) was not covered: the env
fallback only substitutes the placeholder, so an empty value could reach the
app unguarded.

Treat a missing/empty SECRET_KEY the same as the placeholder: warn in
debug/testing, and refuse to start otherwise.

Adds unit tests covering empty/None/placeholder keys (fail closed in
production, warn in debug) and a strong key (no warning).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rusackas rusackas added the asvs label Jun 23, 2026
@dosubot dosubot Bot added authentication Related to authentication install:config Installation - Configuration settings labels Jun 23, 2026
@bito-code-review

bito-code-review Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #10f5fc

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/initialization/__init__.py - 1
  • tests/unit_tests/test_check_secret_key.py - 1
    • Missing type annotations on helper · Line 27-27
Review Details
  • Files reviewed - 2 · Commit Range: a5b039d..a5b039d
    • superset/initialization/__init__.py
    • tests/unit_tests/test_check_secret_key.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

from superset.initialization import SupersetAppInitializer


def _make_initializer(secret_key, *, debug=False, testing=False):

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.

Suggestion: Add explicit type annotations for all parameters and the return type on this helper function to satisfy the fully-typed new Python code rule. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a newly added Python helper function, and it omits type annotations for its parameters and return value. The custom rule requires new Python code to be fully typed, so this is a real violation.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/test_check_secret_key.py
**Line:** 27:27
**Comment:**
	*Custom Rule: Add explicit type annotations for all parameters and the return type on this helper function to satisfy the fully-typed new Python code rule.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎



@pytest.mark.parametrize("secret_key", ["", None, CHANGE_ME_SECRET_KEY])
def test_check_secret_key_refuses_to_start_when_insecure(secret_key):

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.

Suggestion: Add a type annotation for secret_key and an explicit -> None return annotation for this new test function. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This newly added test function has an untyped parameter and no return annotation. The rule explicitly requires new Python functions to be fully typed, so the violation is present.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/test_check_secret_key.py
**Line:** 39:39
**Comment:**
	*Custom Rule: Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎



@pytest.mark.parametrize("secret_key", ["", None, CHANGE_ME_SECRET_KEY])
def test_check_secret_key_warns_but_starts_in_debug(secret_key):

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.

Suggestion: Add a type annotation for secret_key and an explicit -> None return annotation for this new test function. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a new Python test function without type annotations on its parameter or its return type. That directly violates the fully-typed new Python code rule.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/test_check_secret_key.py
**Line:** 48:48
**Comment:**
	*Custom Rule: Add a type annotation for `secret_key` and an explicit `-> None` return annotation for this new test function.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎



def test_check_secret_key_accepts_strong_key():
"""A non-empty, non-placeholder key starts without warning or exit."""

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.

Suggestion: Add an explicit -> None return type annotation to this new test function to keep new Python code fully typed. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This newly added function has no return type annotation. Since the custom rule requires new Python functions to be fully typed, the suggestion identifies a real violation.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/test_check_secret_key.py
**Line:** 57:57
**Comment:**
	*Custom Rule: Add an explicit `-> None` return type annotation to this new test function to keep new Python code fully typed.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.34%. Comparing base (3b46a5f) to head (a5b039d).

Files with missing lines Patch % Lines
superset/initialization/__init__.py 18.18% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41299      +/-   ##
==========================================
- Coverage   64.34%   64.34%   -0.01%     
==========================================
  Files        2653     2653              
  Lines      144952   144956       +4     
  Branches    33433    33434       +1     
==========================================
- Hits        93273    93269       -4     
- Misses      49995    50001       +6     
- Partials     1684     1686       +2     
Flag Coverage Δ
hive 39.27% <18.18%> (+<0.01%) ⬆️
mysql 58.00% <18.18%> (-0.01%) ⬇️
postgres 58.06% <18.18%> (-0.01%) ⬇️
presto 40.86% <18.18%> (+<0.01%) ⬆️
python 59.50% <18.18%> (-0.01%) ⬇️
sqlite 57.72% <18.18%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asvs authentication Related to authentication install:config Installation - Configuration settings size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants