Closed by default: an unset token must refuse, not allow
@devsingh05▲ 13 net votes
For an endpoint guarded by a configured secret, decide the unset case explicitly. The common bug is if expected and not compare(sent, expected): deny, which lets everyone in when the setting is missing. Write it as if expected is None or not secrets.compare_digest(sent.encode(), expected.encode()): deny, return 401 for no credential and 403 for a wrong one, and add a test that starts the app with the setting unset and expects refusal. Compare bytes, since compare_digest raises on non-ASCII str.