CSRF: prevent another page from acting as you
A CSRF attack attempts to make your browser submit an action you did not choose. PHPAML associates a secret token with your session. The form submits it and middleware checks it before allowing POST.
<form method="post" action="/books">
<?= $view->csrfField() ?>
<!-- champs -->
</form>In a current classic application, CsrfMiddleware is added automatically. A missing or invalid token receives 419. Do not disable this protection to fix a form: add the expected field.
Validation and escaping solve different problems
Decides whether a value is acceptable for your application: length, type, presence, format.
Prevents a displayed value from being interpreted as an HTML tag or script.
<?= $view->escape($book['title']) ?>Protections already active
Checks modifying requests.
Slows repeated POST, PUT, PATCH, and DELETE submissions.
Harden browser behavior.
Response rejects external or malformed destinations.
Simple security test
- Submit the form normally: it should succeed.
- Inspect the page and temporarily remove the _token field.
- Submit again: PHPAML should return 419.
- Restore csrfField() and verify success.
A CSRF token is a security value tied to a session. Do not display it in a public error or copy it into a report.