

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# Rust Security67> This file extends [common/security.md](../common/security.md) with Rust-specific content.89## Secrets Management1011- Never hardcode API keys, tokens, or credentials in source code12- Use environment variables: `std::env::var("API_KEY")`13- Fail fast if required secrets are missing at startup14- Keep `.env` files in `.gitignore`1516```rust17// BAD18const API_KEY: &str = "sk-abc123...";1920// GOOD — environment variable with early validation21fn load_api_key() -> anyhow::Result<String> {22 std::env::var("PAYMENT_API_KEY")23 .context("PAYMENT_API_KEY must be set")24}25```2627## SQL Injection Prevention2829- Always use parameterized queries — never format user input into SQL strings30- Use query builder or ORM (sqlx, diesel, sea-orm) with bind parameters3132```rust33// BAD — SQL injection via format string34let query = format!("SELECT * FROM users WHERE name = '{name}'");35sqlx::query(&query).fetch_one(&pool).await?;3637// GOOD — parameterized query with sqlx38// Placeholder syntax varies by backend: Postgres: $1 | MySQL: ? | SQLite: $139sqlx::query("SELECT * FROM users WHERE name = $1")40 .bind(&name)41 .fetch_one(&pool)42 .await?;43```4445## Input Validation4647- Validate all user input at system boundaries before processing48- Use the type system to enforce invariants (newtype pattern)49- Parse, don't validate — convert unstructured data to typed structs at the boundary50- Reject invalid input with clear error messages5152```rust53// Parse, don't validate — invalid states are unrepresentable54pub struct Email(String);5556impl Email {57 pub fn parse(input: &str) -> Result<Self, ValidationError> {58 let trimmed = input.trim();59 let at_pos = trimmed.find('@')60 .filter(|&p| p > 0 && p < trimmed.len() - 1)61 .ok_or_else(|| ValidationError::InvalidEmail(input.to_string()))?;62 let domain = &trimmed[at_pos + 1..];63 if trimmed.len() > 254 || !domain.contains('.') {64 return Err(ValidationError::InvalidEmail(input.to_string()));65 }66 // For production use, prefer a validated email crate (e.g., `email_address`)67 Ok(Self(trimmed.to_string()))68 }6970 pub fn as_str(&self) -> &str {71 &self.072 }73}74```7576## Unsafe Code7778- Minimize `unsafe` blocks — prefer safe abstractions79- Every `unsafe` block must have a `// SAFETY:` comment explaining the invariant80- Never use `unsafe` to bypass the borrow checker for convenience81- Audit all `unsafe` code during review — it is a red flag without justification82- Prefer `safe` FFI wrappers around C libraries8384```rust85// GOOD — safety comment documents ALL required invariants86let widget: &Widget = {87 // SAFETY: `ptr` is non-null, aligned, points to an initialized Widget,88 // and no mutable references or mutations exist for its lifetime.89 unsafe { &*ptr }90};9192// BAD — no safety justification93unsafe { &*ptr }94```9596## Dependency Security9798- Run `cargo audit` to scan for known CVEs in dependencies99- Run `cargo deny check` for license and advisory compliance100- Use `cargo tree` to audit transitive dependencies101- Keep dependencies updated — set up Dependabot or Renovate102- Minimize dependency count — evaluate before adding new crates103104```bash105# Security audit106cargo audit107108# Deny advisories, duplicate versions, and restricted licenses109cargo deny check110111# Inspect dependency tree112cargo tree113cargo tree -d # Show duplicates only114```115116## Error Messages117118- Never expose internal paths, stack traces, or database errors in API responses119- Log detailed errors server-side; return generic messages to clients120- Use `tracing` or `log` for structured server-side logging121122```rust123// Map errors to appropriate status codes and generic messages124// (Example uses axum; adapt the response type to your framework)125match order_service.find_by_id(id) {126 Ok(order) => Ok((StatusCode::OK, Json(order))),127 Err(ServiceError::NotFound(_)) => {128 tracing::info!(order_id = id, "order not found");129 Err((StatusCode::NOT_FOUND, "Resource not found"))130 }131 Err(e) => {132 tracing::error!(order_id = id, error = %e, "unexpected error");133 Err((StatusCode::INTERNAL_SERVER_ERROR, "Internal server error"))134 }135}136```137138## References139140See skill: `rust-patterns` for unsafe code guidelines and ownership patterns.141See skill: `security-review` for general security checklists.142
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ThanhTrunggDEV/DontBeLazy.cursor/rules/zh-agents.mdc · 6 | Cursor rules | no sections | 50/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/zh-patterns.mdc · 6 | Cursor rules | api | 30/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.agent/AGENTS.md · 6 | AGENTS.md | buildteststylearch+4 | 77/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/AGENTS.md · 6 | AGENTS.md | buildteststylearch+4 | 77/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-agents.mdc · 6 | Cursor rules | agent-behaviour | 50/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-code-review.mdc · 6 | Cursor rules | styletesting-strategygitsecurity+3 | 65/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-coding-style.mdc · 6 | Cursor rules | style | 54/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-development-workflow.mdc · 6 | Cursor rules | gitagent-behaviour | 39/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-git-workflow.mdc · 6 | Cursor rules | lint-formatgitagent-behaviour | 43/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-hooks.mdc · 6 | Cursor rules | styletypessecuritydo-not | 36/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-patterns.mdc · 6 | Cursor rules | lint-formatstyleapi | 52/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-performance.mdc · 6 | Cursor rules | buildperformance | 48/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-security.mdc · 6 | Cursor rules | security | 39/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/common-testing.mdc · 6 | Cursor rules | testtesting-strategyagent-behaviour | 34/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-coding-style.mdc · 6 | Cursor rules | lint-formatstyle | 52/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-hooks.mdc · 6 | Cursor rules | buildlint-formatdeployment | 60/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-patterns.mdc · 6 | Cursor rules | style | 54/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-security.mdc · 6 | Cursor rules | securityperformancedo-not | 73/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/cpp-testing.mdc · 6 | Cursor rules | testtesting-strategy | 55/100 | 14 days ago | |
| ThanhTrunggDEV/DontBeLazy.cursor/rules/csharp-coding-style.mdc · 6 | Cursor rules | lint-formatstyletypes | 66/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| bybren-llc/safe-agentic-workflow.cursor/rules/10-backend-python.mdc · 399 | Cursor rules | testlint-formatstylegit+4 | 97/100 | today |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/thanhtrunggdev-dontbelazy-cursor-rules-rust-security)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.