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
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:
1 parent
79694fbaa2
commit
6159c6373c
62 files changed
+453
-300
No files matched your search
@@ -2,11 +2,11 @@
|
||||
|
||||
Apply these rules when implementing promises, I/O, streams, subscriptions, timers, or other long-lived work.
|
||||
|
||||
* Handle every rejected promise. Do not leave floating promises; for intentional fire-and-forget work, attach error handling and make its owner and lifetime explicit.
|
||||
* Handle every rejected promise. Do not leave floating promises; for intentional fire-and-forget work, attach error handling and make its owner and lifetime explicit. Where the project uses typescript-eslint, keep `no-floating-promises` and `no-misused-promises` enabled.
|
||||
* Use `await` when sequencing or error handling depends on completion. Use `Promise.all` only for independent, bounded work that can safely run together.
|
||||
* Limit concurrency for large workloads with a queue or limiter. Apply backpressure to streams and producer/consumer flows instead of buffering without a bound.
|
||||
* Support cancellation with `AbortSignal` when callers need to stop I/O or long-running work. Propagate it through nested calls and release resources when cancellation occurs.
|
||||
* Avoid synchronous blocking and long CPU-bound work on the Node.js event loop or browser main thread. Move substantial CPU work to a worker or split it into bounded tasks when measurements justify it.
|
||||
* Remove event listeners, timers, subscriptions, streams, and abort handlers when their owner is done. Avoid retaining closures or resources beyond their intended lifetime.
|
||||
* Remove event listeners, timers, subscriptions, streams, and abort handlers when their owner is done. Prefer `using` and `await using` with `Symbol.dispose`/`Symbol.asyncDispose` for scoped resources when the target supports them (TypeScript 5.2+; native in Node 24+ and current browsers). Avoid retaining closures or resources beyond their intended lifetime.
|
||||
* Keep shared mutable state safe and deterministic when asynchronous operations can overlap. Prevent stale responses from overwriting newer state when request ordering matters.
|
||||
* Retry only failures known to be transient, with bounded attempts and delay. Preserve idempotency and cancellation; avoid multiplying retries across layers.
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
Apply these rules when changing package dependencies, module structure, imports, or public exports.
|
||||
|
||||
* Follow the project's existing module system consistently; avoid mixing ESM and CommonJS without a compatibility need.
|
||||
* Follow the project's existing module system and `tsconfig` consistently. For new configuration, use `module`/`moduleResolution` `nodenext` for code that Node runs directly (with explicit file extensions in relative imports) and `bundler` for bundled applications; `node`/`node10` resolution is deprecated since TypeScript 6.0.
|
||||
* Enable `verbatimModuleSyntax` in new configuration and use `import type` for type-only imports.
|
||||
* When code runs through Node's built-in type stripping (on by default since Node 22.18 and 23.6, stable since 24.12), enable `erasableSyntaxOnly` (TypeScript 5.8+): enums, namespaces with runtime code, parameter properties, and `import =` aliases fail there.
|
||||
* Avoid mixing ESM and CommonJS without a compatibility need. `require()` of ES modules works by default from Node 20.19 and 22.12; on older runtimes, CommonJS cannot `require` an ES module.
|
||||
* Keep modules focused and boundaries intentional. Avoid circular dependencies and unnecessary public exports.
|
||||
* Separate transport models from domain logic where that boundary exists. Do not leak implementation details through public APIs.
|
||||
* Prefer built-in platform APIs or installed packages before adding a dependency. Keep dependencies minimal, supported, and compatible with the lockfile.
|
||||
|
||||
@@ -6,8 +6,8 @@ Apply these rules when handling API payloads, user input, browser data, or other
|
||||
* Validate untrusted data at system boundaries before storing it, using it for authorization, or passing it to sensitive operations. Use schema validation when external contracts are complex.
|
||||
* Handle `null` and `undefined` intentionally, and narrow values before use. Avoid implicit coercion and unsafe dynamic property access.
|
||||
* Prefer allowlists for security-sensitive input. Prevent prototype pollution when merging untrusted objects; avoid unsafe recursive merges and dynamic writes to ordinary object prototypes.
|
||||
* Treat URL, path, header, query, and redirect destinations as untrusted. Server-side fetches must restrict schemes and destinations, validate every redirect, and enforce response size and timeout limits.
|
||||
* Treat URL, path, header, query, and redirect destinations as untrusted; server-side fetches follow the shared network security rule.
|
||||
* Use framework-safe text binding and automatic output encoding. Avoid `innerHTML`, `dangerouslySetInnerHTML`, and equivalent escape hatches unless sanitized content is required and a maintained sanitizer is applied.
|
||||
* For cookie-based authentication, preserve secure cookie attributes and the application's CSRF protections. Do not store authentication secrets in browser-accessible storage without an explicit threat model and security design.
|
||||
* For cookie-based authentication, preserve secure cookie attributes and the application's CSRF protections. Handle session tokens as the shared web security rule defines: prefer `HttpOnly` cookies or a backend-for-frontend, keep tokens the app must hold in memory, and never store refresh tokens in `localStorage` or `sessionStorage`.
|
||||
* Never expose secrets or sensitive data in output, logs, or errors. Client-side validation and route guards do not replace server-side authentication, authorization, or validation.
|
||||
* Bound input size, nesting, parsing work, and response size before processing untrusted JSON or other structured data.
|
||||
@@ -1,13 +1,12 @@
|
||||
# TypeScript Security
|
||||
|
||||
Apply these rules when implementing or reviewing security-sensitive TypeScript code. Load the matching shared security rule for the affected API, identity, data, browser, file, network, cryptographic, or dependency boundary as well.
|
||||
Apply these rules when implementing or reviewing security-sensitive TypeScript or JavaScript code. Load the shared security rule for each affected boundary (API, auth, web, data, files, network, crypto, supply chain, AI); this file adds only TypeScript and JavaScript specifics. Runtime validation lives in the runtime-safety rule.
|
||||
|
||||
* Validate external data at runtime before using it in authorization decisions, database operations, filesystem access, or privileged actions. A type assertion is not validation.
|
||||
* Enforce authentication, authorization, tenant scoping, and input validation on the server. Browser checks, hidden controls, route guards, and TypeScript types do not create a security boundary.
|
||||
* Keep credentials and private keys on trusted servers. Never embed secrets in frontend bundles, source maps, browser storage, or public runtime configuration.
|
||||
* Use cryptographically secure platform randomness for tokens and security-sensitive identifiers. Do not use `Math.random()` for secrets, session values, or authorization codes.
|
||||
* Use parameterized database APIs and allowlists for dynamic identifiers. Avoid constructing SQL, shell commands, HTML, or other interpreted input by string concatenation.
|
||||
* For server-side URL fetching, restrict protocols and destinations, validate redirects, and bound time, response size, and concurrency to reduce SSRF and resource-exhaustion risk.
|
||||
* Use the framework's safe output encoding and preserve CSP, TLS, cookie, and CSRF protections. Do not disable these controls to make a request or test pass.
|
||||
* Review untrusted object merges for prototype pollution, unsafe deserialization, and mass assignment. Copy only fields the caller is allowed to control.
|
||||
* Review dependency additions and upgrades for source, package identity, install scripts, transitive risk, and lockfile changes.
|
||||
* A type, generic parameter, or assertion is not validation; construct trusted values only after a runtime check.
|
||||
* Use `crypto.randomUUID()` or `crypto.getRandomValues()` (Node: `node:crypto`) for tokens and security-sensitive identifiers, never `Math.random()`. Compare secrets with `crypto.timingSafeEqual` in Node.
|
||||
* Run processes with `execFile` or `spawn` and an argument array; never use `exec` or `shell: true` with interpolated input.
|
||||
* Never pass untrusted strings to `eval`, `new Function`, or the string forms of `setTimeout` and `setInterval`.
|
||||
* Use `Map` or `Object.create(null)` for untrusted keys, and reject `__proto__`, `constructor`, and `prototype` when merging untrusted objects.
|
||||
* Use Trusted Types where the Content Security Policy enforces them, instead of disabling the policy.
|
||||
* In Node, resolve file paths with `path.resolve(root, input)` and require the result to start with `root + path.sep`; use `fs.realpath` when symlinks matter.
|
||||
* Use the database driver's parameter binding or a query builder's parameterized API; never build SQL with template literals.
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
Apply these rules when defining TypeScript types, public function contracts, or domain data models.
|
||||
|
||||
* Prefer `strict: true`, precise types, and `unknown` for values whose shape has not been validated. Avoid `any`, broad assertions, and non-null assertions that hide uncertainty.
|
||||
* Keep `strict` enabled (the default since TypeScript 6.0; set it explicitly on older versions) and never weaken it to make code compile. Enable `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes` for new projects where the codebase allows it.
|
||||
* Use precise types and `unknown` for values whose shape has not been validated. Avoid `any`, broad assertions, and non-null assertions that hide uncertainty. Use `satisfies` to check a literal against a type without widening it.
|
||||
* Model variants with discriminated unions and use literal unions for constrained values. Make invalid states difficult to represent.
|
||||
* Prefer `readonly` and immutable data when mutation is unnecessary. Use interfaces for implementation contracts or declaration merging; use type aliases for unions and compositions.
|
||||
* Give exported APIs, callbacks, and non-trivial functions explicit contracts; rely on inference for simple local values where it keeps code clearer.
|
||||
|
||||
Reference in new issue
Block a user