Skip to content

fix(backend): harden email/OAuth/CORS/error-handling + backend review#9

Open
StockerMC wants to merge 2 commits into
mainfrom
fix/backend-hardening
Open

fix(backend): harden email/OAuth/CORS/error-handling + backend review#9
StockerMC wants to merge 2 commits into
mainfrom
fix/backend-hardening

Conversation

@StockerMC
Copy link
Copy Markdown
Owner

Summary

Backend security/robustness fixes + a full review doc (docs/backend-review.md). Backend is undeployed, so these are pre-deploy hardening; all changes verified with py_compile (no runtime available in review env).

Fixed in this PR

Area Fix
Email HTML injection utils/email.py now HTML-escapes custom_message, creator_name, product titles (were interpolated raw into HTML)
OAuth state expiry /shopify/callback now enforces expires_at (was only checking the used flag → infinite CSRF window)
Query int 500s added _qint() guard; bad ?limit=abc returns default instead of crashing
CORS added https://www.maatchaa.co + https://maatchaa.co (prod origin; was only vercel/localhost)
Error status codes 4 returns changed from status=200 to proper 400/404/500

Documented, NOT fixed here (see doc)

  • 🔴 No auth on non-OAuth endpoints — the big one. Needs a shared-secret (INTERNAL_API_KEY) guard across ~40 handlers before deploy; left out because it can't be runtime-tested here and belongs with the deploy work. Sample decorator included in the doc.
  • 🔴 Open email relay + unauthenticated discount creation — both gated on the auth layer above.
  • 🟢 API.py monolith + routes duplicated in partnerships_api.py; legacy routes on dead v2 tables.

Note

The demo is unaffected (backend not deployed). Verified separately that the live dashboard demo still works post-RLS.

Localized, inspection-verified fixes (backend is undeployed; py_compile-checked):
- email: HTML-escape custom_message, creator_name, product titles (was injectable)
- oauth callback: enforce state expires_at (was only checking used flag)
- query ints: add _qint() guard so bad ?limit/?offset return defaults not 500
- CORS: add https://www.maatchaa.co + https://maatchaa.co (prod origin)
- error returns: 4 spots changed from status=200 to proper 400/404/500

docs/backend-review.md captures the full review, incl. the remaining big item:
no auth layer on non-OAuth endpoints (needs a shared-secret guard before deploy).
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
maatchaa Ready Ready Preview, Comment May 31, 2026 8:57pm

Follow-up: the prior commit only added the html import; the escape call sites
did not land (string mismatch). This escapes custom_message (+ line breaks),
creator_name, shop_name, and product titles where interpolated into the HTML.
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