agentleFS
subhash-arabhisubhash-arabhi/saas-playbook/skills/security-and-hardening/SKILL.md

security-and-hardening

Skill1 starsChanged 31 days agoMITView on GitHub

Hardens code against vulnerabilities. Use when handling untrusted input, authentication, sessions, data storage, file uploads, webhooks, outside services or LLM calls; when auditing a handler or login flow against the OWASP Top Ten; when auditing dependencies or assessing a new package; or when personal data is involved. Privacy decisions (purpose, retention, deletion, sharing) are made when the data is added; legal pages and consent come before launching to real users.

  • Reads credentials

88 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use constraint-driven-development, deprecation-and-migration and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 16 projects that use this

  • HK-hubSkill

    deprecation-and-migration

    Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

    Also in 40 projects that use this

  • HK-hubSkill

    source-driven-development

    Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.

    Also in 43 projects that use this

  • seikaikyoSkill

    doubt-driven-development

    對非平凡決策啟動新鮮 context 對抗審查(找碴不背書),在修正還便宜的時候抓出錯誤方向。適用:高風險改動(production、資安敏感邏輯、不可逆操作)、不熟的程式碼、要宣稱「這樣是安全的 / 可行的」之前。機械性操作與一行修改不適用。

    Also in 39 projects that use this

  • seikaikyoSkill

    interview-me

    需求不明時的意圖萃取訪談:一次一題、每題附上自己的猜測、聽出「真正想要 vs 覺得應該要」,直到能預測使用者反應(約 95% 信心)才動工。適用:需求缺少對象 / 動機 / 成功標準 / 約束,或使用者點名「訪談我」「先確認一下」「我們確定嗎」。明確自足的指示、純資訊查詢、機械性操作不適用。

    Also in 36 projects that use this

  • jarosser06Skill

    test-strategy

    Plans pytest test strategies for Drift's 90%+ coverage requirement using coverage analysis, edge case identification, and test suite design. Use when determining what tests to write, analyzing coverage gaps, or planning test strategies.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 8 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 83 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Project rules first: If the project has .agents/rules/ (installed with the SaaS playbook), read .agents/rules/security.md and …

    line 8
  2. Very specific:

    Treat every external input as hostile.

    line 12
  3. Distinctive:

    The API is the security boundary: All validation, authentication and authorization run there.

    line 21
  4. Very specific:

    Prefer one origin (API under /api), so no CORS.

    line 23
  5. Distinctive:

    Never log passwords, tokens, card numbers or other sensitive data.

    line 28
  6. Distinctive:

    Check the staged diff before committing.

    line 48
  7. Very specific:

    Use the package manager that the lockfile, packageManager and CI agree on.

    line 52
  8. Distinctive:

    Follow the reference procedure when adding or upgrading dependencies.

    line 57
  9. Distinctive:

    Keep it out of logs, telemetry and LLM prompts.

    line 61
  10. Distinctive:

    Keep it findable: tables keyed by user/owner, not free-text blobs.

    line 62
  11. Distinctive:

    Before launching to real users: privacy policy, consent UI, vendor DPAs, and a final check that the record matches the code.

    line 64
  12. Distinctive:

    Keep secrets, other tenants' data and the full system prompt out of the context.

    line 70

“Common” is measured: kept by at least 6 in 10 of the 83 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- Adapted from addyosmani/agent-skills@1401c8b (MIT, see licenses/). Changes: layered (general guidance here, playbook decisions in .agents/rules/); cloud-agnostic; web app baseline, secret store and managed identity, shared-store rate limiting, private file storage, pre-PR checks, privacy decided when data is added (legal pages at launch); trimmed (detail in references/). -->

Project rules first. If the project has .agents/rules/ (installed with the SaaS playbook), read .agents/rules/security.md and .agents/rules/database.md and follow them: they override this skill where they differ. Without them, follow this skill as written.

Security and Hardening

Treat every external input as hostile. When you write code for a rule below, read its section in references/hardening-patterns.md.

1. Threat model first (five minutes)

  1. Map trust boundaries: requests, uploads, webhooks, outside APIs, queues, LLM output, and local values another party wrote (process command lines, shared-volume filenames, job payloads). Trust follows who wrote a value.
  2. Name the assets: credentials, personal data, payments, admin actions.
  3. Run STRIDE over each boundary.
  4. Write abuse cases next to use cases; the first test is "how would I misuse this?"

2. Web app baseline

  • The API is the security boundary. All validation, authentication and authorization run there. Trust nothing the browser sends; never rely on a proxy, CDN or gateway for a check.
  • VITE_* / NEXT_PUBLIC_* variables reach the browser: never secrets or privileged keys.
  • Prefer one origin (API under /api), so no CORS. Otherwise allow exact origins from config only; never *.
  • Session cookies: host-only, Secure, HttpOnly, SameSite=Lax/Strict, bounded Max-Age. No auth tokens in localStorage.
  • Personalised responses: Cache-Control: private, no-store.
  • Security headers on every response (CSP from default-src 'self', only tightened; HSTS; frame protection; nosniff). Never disable them. HTTPS everywhere.
  • Return an explicit public shape (never passwordHash, reset tokens). Error bodies are generic; stack traces go to server logs only.
  • Never log passwords, tokens, card numbers or other sensitive data.

3. Ask the user first

Auth logic changes · new sensitive-data categories · new outside integrations · CORS changes · upload handlers · rate-limit changes · elevated roles.

4. Controls

  • Injection: parameterize every query; never build SQL, NoSQL or shell commands from strings.
  • XSS: framework auto-escaping; no eval()/innerHTML with user data; allowlist-sanitize unavoidable raw HTML.
  • Access control: on every request, the user must own or be permitted on that specific resource (IDOR).
  • Passwords: argon2, bcrypt (cost ≥ 12) or scrypt from a vetted library. Session secret from the secret store, never code.
  • Validation: a schema at the boundary (shape, lengths, enums, formats); reject with 422 and details; use only the parsed value after.
  • Uploads: allowlist MIME types, cap size, check magic bytes when it matters, store under a generated name.
  • File storage: private buckets only. Users get minutes-long, read-only signed URLs for one object, after an ownership check, signed via managed identity (no long-lived account key). Per-tenant prefix (<owner_id>/...); the client never picks the full path.
  • SSRF (server fetches a user-influenced URL): allowlist scheme and host, reject if any resolved IP is private or reserved (incl. 169.254.169.254, IPv6), no redirects.
  • Destructive ops on derived paths: before delete/move/overwrite, require the symlink-resolved target to be under an allowlisted root, at least one level below it, with ownership evidence read beforehand. A shape check is not authorization. On refusal, log and stop; never fall back to a broader path.
  • Rate limiting: API generally, auth strictly (~10 attempts / 15 min), 429 with Retry-After. Multiple instances or serverless: shared store (e.g. Redis) or API gateway, never in-memory. LLM endpoints also get a per-user token/cost limit.

5. Secrets

  • Deployed: the cloud's secret store via managed identity, not app settings or CI variables. Prefer identity-based auth over keys.
  • Local: a gitignored env file; .env.example holds placeholders only.
  • Check the staged diff before committing; a secret scanner (e.g. Gitleaks) runs before each PR.
  • A secret that reached a remote is compromised: rotate first, then purge history.

6. Dependencies

  • Use the package manager that the lockfile, packageManager and CI agree on; stop on disagreement or competing lockfiles.
  • Block install scripts until reviewed; never blanket-approve.
  • OSV-Scanner checks every lockfile before each PR. Triage critical/high by reachability; never auto-apply forced fixes; document deferrals with a review date.
  • Audits only catch known advisories: review new packages and lockfile diffs (owner, age, provenance, typosquats).

Follow the reference procedure when adding or upgrading dependencies.

7. Personal data

  • Collect only what a feature needs, for a stated purpose.
  • Keep it out of logs, telemetry and LLM prompts.
  • Keep it findable: tables keyed by user/owner, not free-text blobs. Classify fields as you add them.
  • Decide as you add it: purpose, retention, how it's really deleted (stores and backups, not a flag), export, and which outside services or analytics receive it. Record it where the project keeps its data decisions (in the SaaS playbook, ARCHITECTURE.md → "Personal data").
  • Before launching to real users: privacy policy, consent UI, vendor DPAs, and a final check that the record matches the code.
  • A privacy incident starts the breach-notification clock; postmortem with debugging-and-error-recovery.

8. AI / LLM features (OWASP LLM Top 10)

  • Model output is untrusted: never into eval, SQL, shell, innerHTML or file paths. Parse, schema-validate, encode.
  • Untrusted text in context can hijack the prompt. The system prompt is not a boundary; enforce permissions in code.
  • Keep secrets, other tenants' data and the full system prompt out of the context.
  • Scope tools, validate every tool argument, confirm destructive actions.
  • Cap tokens, rate and recursion depth. Partition RAG per tenant; validate documents before indexing.

9. Before every PR

  • Gates pass: secret scan, code scan, dependencies (no reachable unmitigated critical/high), security review of the diff (no Critical/High), and an LLM red-team suite (e.g. promptfoo) when LLM code or prompts changed.
  • Review the diff for auth, input, data and privacy, headers and CORS, dependencies, AI/LLM and errors (project security checklist if any). Confirm headers in a real response.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.