Refund Admin Check Failed in Production When Python Ran With -O Flag
A refund endpoint relied on an assert statement to verify staff permissions, which passed all tests during development. After a release set PYTHONOPTIMIZE=1 in the environment, nothing visibly broke, yet all such checks silently stopped running from that point on. The article explains that Python's -O flag strips assert statements entirely, so they are not reliable for enforcing access control or other security logic. The recommended fix is to replace asserts with explicit conditional checks that raise errors, and to use linters such as Bandit or Ruff to flag assert use outside test code. The author also advises running security tests against the same image and flags used in production.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in