feat(security): validate nation_slug + idempotent Stripe webhook (fixes #13)#26
Merged
ianpatrickhines merged 3 commits intoJun 22, 2026
Merged
Conversation
#13) - Add shared/validation.py: nation_slug must match ^[a-z0-9-]{1,63}$, rejected with 400 at every entry point (used in DDB keys, Secrets Manager names, NB API URLs) - Make Stripe webhook idempotent: persist processed event IDs in DynamoDB with TTL; no-op on duplicate delivery (Stripe retries) - Tests cover invalid slugs and replayed webhook events (+23) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
17 tasks
…wline
Independent review caught a bypass: ^[a-z0-9-]{1,63}$ with .match()
accepts a trailing newline (Python $ matches before a final \n), so
"legit-slug\n" passed validation and flowed into Secrets Manager paths,
NB API URLs, and DynamoDB keys. Switched $ -> \Z in all four pattern
copies (shared/validation.py + 3 inlined handler copies). Added newline
regression cases to INVALID_SLUGS.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ate-slug-idempotent-webhook # Conflicts: # infrastructure/template.yaml # src/lambdas/nb_oauth_callback/handler.py
ianpatrickhines
deleted the
claude/issue-13-validate-slug-idempotent-webhook
branch
June 22, 2026 15:29
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13.
What
src/lambdas/shared/validation.py): enforces^[a-z0-9-]{1,63}$at every entry point; invalid values rejected with 400 before the slug is used in DynamoDB keys, Secrets Manager names, or NB API URLs.Verified
pytest -q→ 596 passed (+23 new: invalid-slug and duplicate-event cases)mypy src/→ clean (23 files)Provenance
Authored by a pr-driver Opus drive that hit the 80-turn ceiling before it could commit/push; the working tree was preserved, independently re-verified (tests + mypy) from the main session, then committed and opened here. No adversarial self-review ran (the drive was cut off before that step) — worth a careful human/
/shipreview of the validation entry points and the webhook idempotency table wiring.