Files
MyAiConfiguration/shared/rules/security/references/web.md
T
Julian Lechner c3e22eb902
CI / CI configuration security checks (push) Successful in 6s
CI / Python tests and compilation (push) Failing after 12s
CI / QMD unit tests (push) Skipped
CI / Capabilities and shell quality (push) Successful in 1m50s
CI / Build and inspect generated packages (push) Skipped
CI / Bash integration and installation guards (push) Skipped
CI / Installed client configuration smoke tests (push) Skipped
CI / PowerShell tests on Ubuntu (push) Failing after 7m24s
corrections
2026-11-19 10:30:43 +01:00

16 lines
2.3 KiB
Markdown

# Web and frontend security
Apply these rules when changing browser code, cookies, redirects, or defenses against XSS and CSRF.
* Escape or sanitize untrusted content; never inject untrusted HTML. Bypass framework sanitization (for example Angular `bypassSecurityTrust*` or React `dangerouslySetInnerHTML`) only for compile-time constants, developer-controlled values, or the output of a maintained sanitizer, and state the reason in a comment at the call site.
* Encode output for its exact context (HTML, attributes, JavaScript, CSS, or URL). Prefer text APIs and framework-safe templates; use a maintained sanitizer only when rich HTML is required.
* Protect state-changing browser requests from CSRF where applicable; validate origin or anti-CSRF tokens and do not treat CORS as authorization.
* Use `HttpOnly`, `Secure`, and appropriate `SameSite` cookie settings for sensitive sessions; session rotation follows the authentication rule.
* Validate redirect targets against an allowlist. Avoid sensitive data in URLs, referrers, browser history, analytics, and error reports.
* Apply a restrictive Content Security Policy and clickjacking protection (`frame-ancestors`) where applicable. Do not weaken security headers to accommodate unsafe inline content without a reviewed design.
* Treat frontend code, source maps, and browser storage as visible, and never rely on client-side checks for authorization.
* Never place server secrets (API keys, client secrets, signing or encryption keys, connection strings) in frontend code, bundles, public runtime configuration, or browser storage.
* For user sessions in browser apps, prefer `HttpOnly` cookies or a backend-for-frontend (BFF) that keeps OAuth tokens on the server. If the browser app must hold tokens, keep access tokens in memory and short-lived, use refresh-token rotation, and never store refresh tokens in `localStorage` or `sessionStorage` (RFC 10017, OAuth 2.0 for Browser-Based Applications). This is the single rule for browser token handling; language and framework rules defer to it.
* Protect state-changing operations against unintended form submissions; require explicit confirmation for high-impact actions.
* Keep dependencies and third-party scripts minimal. Apply integrity and origin controls to externally hosted resources where supported.