Skip to content

Add logging to AltchaField for validation failures and misconfigurations#40

Open
hleroy wants to merge 1 commit intoaboutcode-org:mainfrom
hleroy:main
Open

Add logging to AltchaField for validation failures and misconfigurations#40
hleroy wants to merge 1 commit intoaboutcode-org:mainfrom
hleroy:main

Conversation

@hleroy
Copy link
Copy Markdown

@hleroy hleroy commented Apr 5, 2026

Adds a module-level logger and a log_warning() method on AltchaField (overridable by subclasses) that emits warnings in the following cases:

  • ALTCHA_VERIFICATION_ENABLED is False — silent bypass of CAPTCHA protection is now visible in logs
  • altcha.verify_solution raises an unexpected exception
  • Token verification fails (with the reason returned by the library)
  • Payload base64/JSON decoding fails
  • A replay attack is detected

Without logging, all these failure paths were silent, making it difficult to distinguish misconfiguration from attacks or bugs in production.

… attacks

- Add a module-level logger using logging.getLogger(__name__)
- Log a warning when ALTCHA_VERIFICATION_ENABLED is False, making it
  clear that the CAPTCHA provides no protection in that state
- Log a warning with the exception message when verification raises an
  unexpected error, aiding debugging without leaking details to the user
- Log a warning when verification returns a failed result, including the
  error detail from the altcha library
- Log a warning with the challenge hash when a replay attack is detected
- Log a warning with the exception message when payload decoding fails

Signed-off-by: Hervé Le Roy <hleroy@hleroy.com>
@hleroy
Copy link
Copy Markdown
Author

hleroy commented Apr 13, 2026

I have replaced the percent-style string formatting (%s) with f-strings. Checks should be passing now. Could you please re-run the workflow? Thanks

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.

1 participant