Documentation · Chapter 08

Turn security
into a repeatable test.

This workshop deliberately attacks reading-list locally to confirm every layer responds as expected.

We secure reading-list in layers without pretending one option is enough.

1 — Input and output

Submit an empty title, then one containing <script>alert(1)</script>. The first should produce 422 with a field error. The second may be stored as text but must never execute a script in the list.

2 — CSRF

Temporarily remove csrfField() from a local form copy and submit POST. Expect 419. Restore the field immediately: a security test must not become a regression.

3 — Cookies and headers

phpaml — zsh
curl -I http://127.0.0.1:8910/books

Find Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy. Secure and HSTS appear when the request is genuinely HTTPS.

4 — Rate limiting

In a test environment only, reduce limit to 2, send three valid POST requests to the same path, and confirm 429 with Retry-After. Then restore 60.

5 — Production

phpaml — zsh
aml test
aml doctor --production
APP_DEBUGfalse
APP_URLhttps://…
APP_KEY32 characters or more
public/only Web root

SUMMARY

What to remember

  • Validation and escaping protect different stages.
  • CSRF protects actions using the session.
  • Session cookies are HttpOnly and become Secure under HTTPS.
  • CSP and other headers set browser boundaries.
  • Rate limiting reduces abuse but never replaces permissions.