estack-security
Phoenix security
Read the installed framework versions and existing authentication/policy code. Preserve established mechanisms and assess the specific trust boundary; generic rules do not replace a threat model or security review.
Inputs and authorization
- Treat LiveView params, hidden fields,
phx-value-*, API payloads, and job inputs as untrusted. - Derive ownership and tenant membership from authenticated server-side state. Do not cast client-supplied ownership, roles, or administrative flags.
- Scope data access and authorize the requested action. Being allowed to see a resource does not imply permission to edit, refund, or delete it.
- Check authorization at context/Ash-action boundaries for every transport. Recheck sensitive state during mutations; a previous mount check is not enough.
- Test unauthorized roles, different tenants, direct IDs, preloads, and writes. UI hiding and opaque IDs are not security controls.
Injection and unsafe conversion
Use explicit allowlists for keys and tool names. Do not create atoms from untrusted strings; String.to_existing_atom alone is not an authorization allowlist and can still raise.
Bind values in Ecto/SQL queries. Allowlist dynamic identifiers, operators, and ordering separately; value binding does not sanitize SQL syntax. Let HEEx escape user content. Sanitize intentionally supported HTML with a maintained allowlist before rendering it as raw.
PostgreSQL text rejects NUL bytes; validate or reject them at the appropriate boundary rather than claiming the database server crashes. Do not silently alter signed webhook bodies or security-sensitive values before verification.