⚠️ MANDATORY: All AI-generated code MUST comply with this policy. Violations are treated as critical bugs.
- Default to safe Rust.
unsafeis forbidden unless absolutely necessary for FFI or performance-critical paths. - Every
unsafeblock MUST have an inline// SAFETY:comment explaining:- What invariant is being upheld
- Why safe Rust cannot express this
- How the caller/callee guarantees validity
- NEVER use
unsafeto silence compiler errors. Refactor instead. - Prefer abstractions like
Arc<Mutex<T>>, channels, or typed wrappers over raw pointers.
.unwrap(),.expect(),panic!()are FORBIDDEN in production code paths.- Allowed ONLY in:
- Unit/integration tests
- Build scripts (
build.rs) - Explicitly documented startup assertions that SHOULD crash if violated
- All public APIs MUST return
Result<T, E>orOption<T>. - Error types MUST implement
std::error::Errorand provide meaningful context.
- NEVER trust data from IPC (Tauri commands), HTTP, files, or environment variables.
- Validate ALL external inputs at the boundary BEFORE processing.
- Use strong typing (newtypes, enums) over primitives for domain values.
- For medical/financial calculations: validate ranges, units, and precision explicitly.
- String inputs MUST be validated for length, encoding, and injection patterns.
- NEVER implement custom cryptographic algorithms.
- NEVER hardcode secrets, API keys, tokens, or passwords in source code.
- Use vetted crates only:
rustls,argon2,chacha20poly1305. - Secrets MUST be loaded from secure storage (OS keychain, env vars at runtime).
- Sensitive data MUST be zeroized after use (
zeroizecrate).
- Before adding ANY new dependency:
- Verify it exists on crates.io with legitimate publisher
- Check maintenance status, download count, and known CVEs
- Prefer crates already audited in
supply-chain/if cargo-vet is configured
- NEVER use yanked, deprecated, or unmaintained crates.
- Pin exact versions for security-critical dependencies.
- Report suspicious crate recommendations immediately.
- Enable Tauri's CSP (Content Security Policy) in
tauri.conf.json. - Disable
devtoolsin production builds. - Use allowlists for shell, filesystem, and network access — never enable global permissions.
- Validate and sanitize ALL IPC command parameters server-side (in Rust), not just client-side.
- Never expose internal file paths, system info, or debug endpoints via IPC.
- Use Tauri's built-in secure storage over localStorage for sensitive data.
- NEVER log PII, credentials, tokens, medical records, or financial data.
- Log messages MUST NOT contain user-supplied strings without sanitization.
- Use structured logging with explicit field selection over format strings.
- Production builds MUST NOT include debug-level logging by default.
- Treat ALL AI-generated code as UNTRUSTED until manually reviewed.
- AI frequently hallucinates non-existent APIs — verify every function signature against official docs.
- AI often suggests outdated or vulnerable crate versions — always cross-check.
- When AI generates
unsafecode, assume it is INCORRECT until proven otherwise. - Request test cases BEFORE implementation for security-critical logic.
Before considering any AI-generated code complete:
- Passes
clippy::pedantic+clippy::nurserywith zero warnings - No
unwrap/expect/panicin non-test code - All external inputs validated at boundary
- No hardcoded secrets or PII in logs
-
unsafeblocks have complete SAFETY comments (if any) - New dependencies verified and audited
- Unit tests cover edge cases and invalid inputs