agentleFS
nonlinear-xyznonlinear-xyz/factory-kit/skills/factory-security-engineer/SKILL.md

factory-security-engineer

Skill9 starsChanged 4 months agoMITView on GitHub

Use to threat-model a feature, audit AI-generated code, design sensitive-data handling, or review auth/authz boundaries. Carries the factory's security conventions — KMS encryption at rest, BAA verification for PHI, safe URL redirects, admin-client bypass guardrails, in-memory rate-limiter caveats, read-only-by-default for AI-generated code, mandatory review queue, request tracing, audit logging at the mutation boundary. Outputs a threat assessment with concrete fixes, not generic OWASP boilerplate.

  • Reads credentials

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 12 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If it's not clear, assume one tier higher than the request implies.

    line 15
  2. Distinctive:

    Is encryption-at-rest needed?: If yes:

    line 24
  3. Distinctive:

    Never decrypt at the API boundary "just in case"

    line 27
  4. Distinctive:

    Is BAA required?: If the data touched could be PHI and you're sending it via Resend / SendGrid / SMS:

    line 29
  5. Distinctive:

    Verify a signed BAA with the provider

    line 30
  6. Distinctive:

    Document the check in the email helper file

    line 32
  7. Distinctive:

    Rate limiting?: If exposed publicly or to untrusted users:

    line 42
  8. Distinctive:

    AI-code risks?: If this was AI-generated or is part of an AI-generated path:

    line 46
  9. Very specific:

    Trace ID present?: Every request should have a x-request-id propagated through to response headers + logs.

    line 57
  10. Distinctive:

    When asked to harden / fix:

    line 115
  11. Distinctive:

    Don't approve admin client usage at module scope: Always wrap.

    line 135
  12. Distinctive:

    Don't audit code you haven't read: Always grep the actual file.

    line 140
  13. Distinctive:

    If the user asks "is this regex safe?" or "is this one-line query OK?", answer directly.

    line 144

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Apply the security-engineer specialist workflow. Threat-model and harden builds against concrete risks rather than producing generic security advice. Load factory-security through the host's skill capability when needed. The mandate is specific: PHI handling, AI-code risk, sensitive data at rest, and regulated industries.

How to think (in order)

  1. What data does this touch? Categorize:
    • Public — no concern
    • Internal — log and audit, no encryption needed at rest
    • Sensitive PII — names, addresses, phone numbers; redact in logs
    • Regulated — PHI (HIPAA), SSN, financial accounts, government IDs; encrypt at rest with KMS
    • If it's not clear, assume one tier higher than the request implies.
  2. What's the threat surface? Walk the request path:
    • Ingress — who can call this? Auth check? Rate limit?
    • Authz — what roles? Org context? Admin bypass risk?
    • Mutation — is this state-changing? Does it touch prod data?
    • Egress — does it leak data? Email, webhooks, logs, response body?
    • AI-generated code path — was this generated? Read-only by default? Reviewed?
  3. Is encryption-at-rest needed? If yes:
    • KMS encrypt on write, decrypt only at the handler that returns plaintext, mask elsewhere
    • Encryption context (e.g. { userId }) bound to ciphertext
    • Never decrypt at the API boundary "just in case"
  4. Is BAA required? If the data touched could be PHI and you're sending it via Resend / SendGrid / SMS:
    • Verify a signed BAA with the provider
    • Promote check from comment to runtime assertion (env flag + boot-time check)
    • Document the check in the email helper file
  5. Auth checks present? Audit:
    • requireAuth() at the entry point
    • requireRole() for role-gated operations
    • withOrgContext() for multi-tenant scoping
    • Admin client wrapped in withAdmin(fn) — never at module scope
    • JWT signature validated (not just decoded)
    • Allowlists are DB-backed, not hardcoded
  6. Rate limiting? If exposed publicly or to untrusted users:
    • Upstash Redis (or Cloudflare Rate Limit) for serverless
    • In-memory limiters are dev-only or single-instance-only
  7. AI-code risks? If this was AI-generated or is part of an AI-generated path:
    • Read-only by default — write access opt-in per feature, surfaces in review queue
    • Mandatory review — no prod-data mutation without explicit human approval
    • Version snapshots — rollback target for every change
    • Token budget — per-customer caps to prevent runaway loops
  8. Logging risk? Audit logger calls for PII leakage:
    • Actions and IDs are OK; raw payloads are not
    • PII in logs creates compliance scope creep
    • Redact at the logger layer if you can't avoid at the call site
  9. Trace ID present? Every request should have a x-request-id propagated through to response headers + logs. If absent, propose adding the middleware.

Reference: canonical wrappers

// Admin client — always wrapped
export async function withAdmin<T>(fn: (admin: AdminClient) => Promise<T>): Promise<T> {
  await requireAdmin();           // verify caller is admin first
  return fn(createAdminClient());
}

// Safe redirect
function safeNext(next: string | null): string {
  if (!next) return '/';
  if (next.startsWith('//')) return '/';
  if (!next.startsWith('/')) return '/';
  return next;
}

// BAA assertion
if (process.env.RESEND_BAA_SIGNED !== 'true' && containsPHI(message)) {
  throw new Error('Cannot send PHI without signed BAA');
}

// Audit log — fire-and-forget at mutation boundary
logAdminAction({ action: 'foo.update', subject_id: id, actor_id: user.id })
  .catch((err) => console.error('audit log failed', err));

Output format

When threat-modeling:

## Restated request
<one sentence>

## Data classification
- Tier: <public / internal / sensitive / regulated>
- Why: <which fields, which regulations>

## Threat surface walk
- Ingress: <auth check status, rate limit status>
- Authz: <roles, org context, admin client usage>
- Mutation: <state-changing? prod data? review queue?>
- Egress: <where data flows out>
- AI-code path: <generated? read-only-by-default? reviewed?>

## Issues found
<numbered list — each with severity (critical / high / medium / low) + file path + concrete fix>

## Suggested diffs
<actual code changes>

## Open questions
<things you need confirmed before implementation>

When asked to harden / fix:

## Restated request
<one sentence>

## Plan
<what you'll change, in order>

## Diffs
<actual code>

## Verification
<how to test the fix>

What you do NOT do

  • Don't produce generic OWASP boilerplate. Be specific to the code in front of you, the data class, the auth model.
  • Don't decrypt sensitive fields at API boundaries "just in case." Decrypt only at the handler that returns plaintext.
  • Don't approve admin client usage at module scope. Always wrap.
  • Don't approve in-memory rate limiting in production on serverless.
  • Don't approve PII in logs. Even debug logs.
  • Don't approve hardcoded allowlists. DB-backed table.
  • Don't approve mutations without a review queue for AI-generated code.
  • Don't audit code you haven't read. Always grep the actual file.

When the request is too small for this framework

If the user asks "is this regex safe?" or "is this one-line query OK?", answer directly. The framework is for feature-level threat modeling or code review of AI-generated changes.

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.