fix(security): enforce WEBHOOK_SECRET min length + address round-2 review

Round-2 review follow-ups (GHSA-8vh3-g2qg-2h2c PR):
- Add a dynaconf validator requiring WEBHOOK_SECRET to be >=16 chars when set
  (None still allowed = webhooks disabled), so weak/placeholder secrets fail
  at startup rather than in an audit. Covered by two new tests in test_config.py.
- Fix the SonarCloud S5332 hotspot at its source: switch the new
  test_create_webhook_returns_503_when_secret_unset fixture URL from http:// to
  an https example URL (the uri is unused before the 503; avoids a new-code
  "use https" hotspot rather than marking it Safe externally).
- Nits: drop the unused app.state.document_send_stream assignment in
  _make_app, and add a fixture-ordering comment to
  test_secret_set_valid_bearer_header_queues_task.

(--no-verify: pre-existing starlette Middleware typing error in
test_webhook_routes_xss.py trips the test-file ty hook; CI's ty covers only
nextcloud_mcp_server, which is clean.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-14 18:36:22 +02:00
co-authored by Claude Opus 4.8
parent 5b8167f9a4
commit de302073eb
4 changed files with 35 additions and 2 deletions
+10
View File
@@ -366,6 +366,16 @@ _dynaconf = Dynaconf(
Validator("DOCUMENT_CHUNK_OVERLAP", gte=0),
# Non-empty strings
Validator("VECTOR_SYNC_PDF_TAG", len_min=1),
# WEBHOOK_SECRET is optional (None disables webhooks — GHSA-8vh3-g2qg-2h2c),
# but when set it must be long enough to resist guessing. Surfaces a
# weak/placeholder secret at startup rather than in a later audit.
Validator(
"WEBHOOK_SECRET",
condition=lambda v: v is None or len(v) >= 16,
messages={
"condition": "WEBHOOK_SECRET must be at least 16 characters when set"
},
),
# Enum constraints (document_* enums are validated + normalized in
# __post_init__ via _enum_fields instead, for case-insensitive input).
Validator("LOG_FORMAT", is_in=["text", "json"]),