docs(rules): fix contradictions, update technical rules, enforce rule structure
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s

- Resolve contradictions: authorization is never a skipped "boundary check";
  one browser token policy (BFF/HttpOnly cookies first, RFC 10017); one
  sanitizer-bypass rule; Angular responses are unknown until validated.
- Add security rules for AI/LLM integration and Java XXE, concrete crypto
  and password-hashing parameters, and RFC 8725 JWT validation.
- Update version-dependent guidance after checking official sources:
  Angular 22, TypeScript 6/7, Node 24+, .NET 10/C# 14, JDK 21-25, Spring
  Boot 4; add a Spring Boot and Spring Security topic.
- Give every rule a unique level-1 title and scope line, keep language
  security files to language specifics, and fix routing for inbound vs
  outbound HTTP, XML parsing, and WPF/Angular parent rules.
- Validate rule structure and routing in validate-config.py, with tests.
- Fix CI issues found by a local run: shellcheck directive order, pinned
  ruff rule set, Invoke-Python test mock, CRLF-tolerant package checks,
  Windows-only credential test, and refreshed prompt-budget baselines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian LechnerandClaude Opus 5.5 committed 2026-11-05 10:51:08 +01:00
1 parent 79694fbaa2
commit 6159c6373c
62 files changed
+453 -300

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# AI and LLM integration security
Apply these rules to code that calls language models, builds prompts, runs agents or tools, or retrieves content for a model (RAG).
* Treat model output as untrusted input. Never pass it unvalidated to SQL, shell commands, file paths, URL fetches, HTML rendering, code evaluation, or deserialization; validate it against the expected structure, preferably a schema for structured output.
* Treat everything the model reads as potential prompt injection: user input, retrieved documents, web pages, emails, file contents, and tool results. Instructions found in that content carry no authority; keep system instructions and untrusted content in separate, clearly delimited message parts.
* Authorize every tool call with the end user's permissions, not the agent's or the service account's. Give each tool the narrowest scope it needs, and require explicit human confirmation before destructive, financial, or externally visible actions.
* Keep secrets, credentials, and other users' or tenants' data out of prompts, context, and retrieval indexes. Enforce tenant and permission filters at retrieval time, not by asking the model to ignore data.
* Do not rely on the system prompt for security. Assume it can be extracted, and enforce every control in code.
* Bound model work: input and output tokens, cost, request rate, recursion depth, tool-call loops, and total run time. Fail closed when a limit is reached.
* Pin model identifiers and versions where the provider allows it. Review third-party models, prompts, plugins, and MCP servers as dependencies under the supply-chain rule.
* Log prompts, tool calls, and responses for audit without sensitive data, and make outputs that reach users or other systems traceable to their inputs.
* Do not present model output as verified fact in security-relevant decisions; require deterministic checks or human review for those.
+1
View File
@@ -8,5 +8,6 @@
* Define safe retry and idempotency behavior for state-changing requests. Protect against replay and duplicate side effects where relevant.
* Return only authorized fields. Do not expose stack traces, internal models, secrets, or implementation details in API responses or errors.
* Prefer explicit DTOs and schemas; reject unknown or ambiguous fields when accepting them could alter privileged state.
* Deserialize request bodies into explicit types. Never let the payload choose the runtime type (polymorphic type names, class names, or default typing) unless the allowed subtypes are registered explicitly; bound body size and nesting depth. Parse XML with external entities and DTDs disabled.
* Keep authorization, validation, serialization, and error responses consistent with the published schema and supported clients.
* Test malformed, oversized, unauthenticated, unauthorized, cross-user, cross-tenant, and duplicate requests within the user's requested scope.
+6 -2
View File
@@ -1,11 +1,15 @@
# Authentication and authorization security
* Use established authentication standards and password hashing; never store plaintext or reversibly encrypted passwords.
* Use a maintained password-hashing scheme configured for the deployment environment. Never create password schemes or reduce work factors merely to improve latency.
* Hash passwords with Argon2id (at least m=19 MiB, t=2, p=1); if unavailable, scrypt (N=2^17, r=8, p=1), bcrypt (cost 10 or higher; inputs beyond 72 bytes are truncated, so reject or pre-handle longer passwords), or PBKDF2-HMAC-SHA256 with at least 600,000 iterations where FIPS compliance requires it (OWASP Password Storage Cheat Sheet). Never create password schemes or reduce work factors merely to improve latency; rehash on login when parameters are raised.
* Enforce authorization server-side for every sensitive operation and verify resource ownership and tenant boundaries.
* Deny by default and check authorization on every request, including background jobs and alternate API paths. Do not trust role or identity values supplied by clients.
* Use least-privilege roles, short-lived sessions or tokens, secure renewal and revocation, and invalidate credentials after password, recovery, or privilege changes.
* Validate token algorithm, issuer, audience, signature, expiry, and any required not-before or key identifier claims before trusting it. Reject unexpected algorithms and malformed claims.
* Validate JWTs as RFC 8725 recommends:
* Fix the accepted algorithms on the server, bind each key to exactly one algorithm, and never take the algorithm from the token header; reject `none`.
* Validate signature, issuer, audience, expiry, and not-before, with bounded clock skew. Use explicit typing (`typ`, for example `at+jwt`) or distinct audiences to prevent substituting one token kind for another, such as an ID token for an access token.
* Resolve the `kid` header only against a trusted key set, and treat it as untrusted input. Never fetch keys from token-supplied `jku`, `x5u`, or `jwk` headers.
* Signed JWT payloads are readable by anyone; keep sensitive data out of them.
* Protect login, recovery, reset, MFA, and privileged actions against brute force, enumeration, replay, CSRF, and privilege escalation.
* Store session identifiers securely; rotate them after authentication or privilege changes and invalidate them on logout or account recovery.
* Test unauthenticated, unauthorized, cross-user, cross-tenant, expired-token, revoked-session, and recovery-flow paths.
+7 -3
View File
@@ -1,9 +1,13 @@
# Cryptography and secrets security
* Never implement custom cryptographic primitives or use obsolete algorithms.
* Use maintained platform cryptography with authenticated encryption, secure randomness, and verified signatures and certificates. Use safe, documented parameter choices rather than inventing formats or defaults.
* Never implement custom cryptographic primitives. Never use MD5 or SHA-1 for security purposes, DES, 3DES, RC4, ECB mode, or unauthenticated CBC.
* Use maintained platform cryptography with authenticated encryption, secure randomness, and verified signatures and certificates. Minimum choices (as of OWASP and NIST guidance in 2025; check current guidance when starting a project):
* Symmetric encryption: AES-256-GCM with a unique 96-bit nonce per key and message, never reused, or ChaCha20-Poly1305.
* Hashing and MACs: SHA-256 or stronger; HMAC-SHA-256 or stronger.
* Signatures and key exchange: Ed25519, ECDSA or ECDH with P-256 or stronger, or RSA with at least 2048 bits (3072 for keys that must stay secure beyond 2030), with RSA-OAEP or RSA-PSS padding.
* Transport: TLS 1.2 or newer, TLS 1.3 preferred; never disable certificate or hostname validation.
* Keep key generation, storage, access, rotation, revocation, and backup separate from application data where practical. Restrict each key to its intended purpose.
* Treat tokens, private keys, connection strings, and credentials as secrets; keep them out of source, URLs, command lines, logs, fixtures, error messages, and frontend code.
* Treat tokens, private keys, connection strings, and credentials as secrets; keep them out of source, URLs, command lines, logs, fixtures, and error messages. Keep server-side credentials out of frontend code; browser handling of user session tokens follows the web security rule.
* Use environment-appropriate secret storage, separate environments, and rotate compromised or overexposed credentials. Do not silently fall back to a weaker key or algorithm when configuration is missing.
* Compare secret-derived values with established constant-time APIs when the comparison is security-sensitive.
* Do not log plaintext or retain decrypted sensitive data longer than required. Apply secure disposal only where the runtime and data type provide meaningful guarantees.
+2 -1
View File
@@ -5,6 +5,7 @@
* Restrict filesystem permissions to the intended identity and directory. Use safe temporary-file creation and avoid predictable names or permissive shared locations.
* Validate upload content using limits and format-aware parsing; do not trust names or client-supplied MIME types. Store untrusted uploads outside executable or public paths.
* Limit archive entry count, nesting, total expanded size, and path destinations to prevent traversal and resource exhaustion.
* Do not execute uploaded or untrusted files. Avoid shell execution; when a process is required, fix the executable and pass validated arguments through structured process APIs.
* Do not execute uploaded or untrusted files. Avoid shell execution; when a process is required, fix the executable by absolute path and pass validated arguments through structured process APIs. On Windows, never pass untrusted arguments to `.bat` or `.cmd` targets, because `cmd.exe` re-parses them.
* Treat local files, IPC, and deserialized input as untrusted at relevant boundaries. Use explicit deserialization types and bound depth, size, and processing time.
* Parse untrusted XML with DTD processing and external entity resolution disabled (XXE); the language rules name the parser settings. Never let serialized input choose arbitrary runtime types.
* Avoid insecure temporary-file handoff and check permissions and ownership before consuming files from shared or attacker-writable locations.
+7 -5
View File
@@ -1,11 +1,13 @@
# Web and frontend security
* Escape or sanitize untrusted content; never inject untrusted HTML or bypass framework sanitization.
* 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. Rotate session IDs after authentication and privilege changes.
* 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 restrictive Content Security Policy and clickjacking protections 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. Never place secrets there or rely on client-side checks for authorization.
* Protect state-changing operations against clickjacking and unintended form submissions when relevant; require explicit confirmation for high-impact actions.
* 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.