Tereta/Security Module

Overview

Security module. Provides CSRF attack protection and applies secure HTTP headers.

CSRF Protection

A token is generated automatically and stored in the session. A hidden _csrf field is added to forms:

use Tereta\Security\Services\Csrf;

// Get token for a form
$token = Csrf::singleton()->getToken();
$field = Csrf::singleton()->getFieldName(); // '_csrf'

// Validate on form submission
Csrf::singleton()->assertValid($submittedToken); // throws exception on mismatch

HTTP Headers

Applied automatically during web request processing:

HeaderPurpose
X-Content-Type-OptionsPrevents MIME type sniffing
X-Frame-OptionsClickjacking protection
Referrer-PolicyControls referrer information sharing
Permissions-PolicyBlocks access to camera, microphone, geolocation
Content-Security-PolicyControls resource loading (CSP with nonce for inline scripts)
No configuration required — the module works out of the box.

Author and License

Author: Tereta Alexander
Website: tereta.dev
License: Apache License 2.0. See LICENSE.

 www.████████╗███████╗██████╗ ███████╗████████╗ █████╗
     ╚══██╔══╝██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔══██╗
        ██║   █████╗  ██████╔╝█████╗     ██║   ███████║
        ██║   ██╔══╝  ██╔══██╗██╔══╝     ██║   ██╔══██║
        ██║   ███████╗██║  ██║███████╗   ██║   ██║  ██║
        ╚═╝   ╚══════╝╚═╝  ╚═╝╚══════╝   ╚═╝   ╚═╝  ╚═╝
                                                      .dev

Copyright (c) 2024-2026 Tereta Alexander