Permissions & Security
Htmx is a standalone runtime framework with zero custom ProcessWire RBAC permissions of its own. Instead, it enforces defense-in-depth at every hypermedia trust boundary and lets your Component classes enforce ProcessWire’s native $user->isLoggedin(), $user->hasPermission(), and $page->editable() checks.
1. HKDF-SHA256 Signed Component State (SignedStateCodec)
Section titled “1. HKDF-SHA256 Signed Component State (SignedStateCodec)”Every stateful Component encodes its serialized properties into an authenticated hx__state payload:
- Key Derivation: Derives a domain-separated key via
hash_hkdf('sha256', $config->userAuthSalt, 32, 'totoglu-htmx:component-state:v1'). Throws an exception ifuserAuthSaltis shorter than 16 characters. - 5-Claim Context Binding: Every signed payload binds
__uid(user ID),__sid(session binding),__ep(normalized endpoint path),__pid(page ID), and__adm(admin vs. frontend flag). - Tamper & Replay Protection: Modifying any property, replaying a payload from another user or page, or submitting an expired/corrupted signature fails verification before
hydrate()executes.
2. Automatic CSRF & Action Verb Enforcement
Section titled “2. Automatic CSRF & Action Verb Enforcement”| Action Type | Allowed HTTP Methods | CSRF Validation | Intended Use |
|---|---|---|---|
Mutating Action (e.g., saveBooking(), deleteItem()) |
POST, PUT, PATCH, DELETE |
Automatic via $session->CSRF->validate() |
Creating, updating, or deleting pages/entries/state |
Read-Only Query Action (query*, e.g., queryFilter()) |
GET, QUERY |
Not required (must be side-effect free) | Search filters, sorting, pagination, live previews |
Always keep query* methods strictly read-only. Never mutate pages, entries, or user sessions inside a query* method.
3. Component Authorization (authorize() & authorizeAction())
Section titled “3. Component Authorization (authorize() & authorizeAction())”Override authorize() for component-wide access control and authorizeAction(string $action) for per-action permission checks:
protected function authorize(): bool{ return $this->wire()->user->isLoggedin();}
protected function authorizeAction(string $action): bool{ if ($action === 'deleteDraft') { return $this->wire()->user->hasPermission('charter-manage'); }
return true;}4. Explicit Component Allowlisting
Section titled “4. Explicit Component Allowlisting”Keep allowComponentPaths set to false (default) in production and register every callable component explicitly in site/ready.php via $htmx->registerComponent('charter-filter', CharterFilterComponent::class). Unregistered classes cannot be invoked over /hx/req.
5. XSS-Safe AttributeBag & Confined Views
Section titled “5. XSS-Safe AttributeBag & Confined Views”AttributeBag: Automatically HTML-escapes attribute values and strips/blocks inline JavaScript event handlers (on*,hx-on*,data-hx-on*) from untrusted attribute merges.ConfinedViewRenderer: RestrictsComponent::setView()paths strictly to the configuredcomponentsPathdirectory, rejecting..traversal and symlinks outside the root.- Asset URL Validation:
Htmx::isSafeAssetUrl()validates extension and script URLs before injecting<script>tags, andenforceDemoModeGuard()blocks unsafe mutations in demo mode.