agentleFS
ViviBeriViviBeri/webcraft-pro/skills/secure-input-output/SKILL.md

secure-input-output

Skill11 starsChanged 10 days agoMITView on GitHub

Use when handling untrusted input, database queries, HTML rendering, file uploads, URL fetching, serialization, output encoding, or validation in web applications and APIs.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 10 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat all data crossing a trust boundary as untrusted.

    line 10
  2. Distinctive:

    Use allowlists for structured values and reject unexpected fields for sensitive operations.

    line 17
  3. Distinctive:

    Use parameterized queries or safe ORM APIs.

    line 23
  4. Distinctive:

    Prefer safe DOM APIs such as textContent over unsafe HTML insertion.

    line 25
  5. Distinctive:

    Use framework-supported template escaping and avoid bypass/safe-HTML escape hatches for untrusted content.

    line 26
  6. Distinctive:

    Use explicit serialization models to prevent accidental exposure of internal fields.

    line 29
  7. Distinctive:

    Avoid server-side fetching of arbitrary user-provided URLs.

    line 43
  8. Distinctive:

    Prefer strict host allowlists and controlled egress.

    line 44
  9. Distinctive:

    Test malformed encodings, oversized values, injection payloads, unexpected object properties, path traversal, unsafe redirects, …

    line 51
  10. Distinctive:

    All trust-boundary inputs have server-side schemas, queries and rendering use context-safe APIs, file and URL handling are constrained, and …

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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

Secure Input and Output Handling

Objective

Treat all data crossing a trust boundary as untrusted. Validate it for the operation, use safe APIs and encode output for its destination context.

Input workflow

  1. Identify every source: browser fields, headers, cookies, path/query parameters, uploaded files, webhooks, queues, imported data and third-party API responses.
  2. Define strict schemas for type, length, format, allowed values and cross-field business rules.
  3. Validate on the server at the point of use. Client validation improves usability but is not a security boundary.
  4. Use allowlists for structured values and reject unexpected fields for sensitive operations.
  5. Normalize carefully and avoid validation on one representation followed by use of another.
  6. Apply request size, collection size, pagination and processing limits.

Output and query safety

  • Use parameterized queries or safe ORM APIs; never concatenate untrusted values into SQL or command strings.
  • Encode output for its exact context: HTML text, HTML attributes, JavaScript, CSS, URL or JSON.
  • Prefer safe DOM APIs such as textContent over unsafe HTML insertion.
  • Use framework-supported template escaping and avoid bypass/safe-HTML escape hatches for untrusted content.
  • Validate redirect destinations against an explicit allowlist or same-origin policy.
  • Protect state-changing cookie-authenticated requests against CSRF.
  • Use explicit serialization models to prevent accidental exposure of internal fields.

File handling

  • Allowlist business-required extensions and verify file signatures; do not trust filename or Content-Type alone.
  • Enforce size and decompression limits.
  • Generate server-side storage names and store uploads outside executable web roots.
  • Prevent path traversal and unsafe archive extraction.
  • Scan or quarantine files when the threat model requires it.
  • Serve files with safe content-disposition and content-type behavior.
  • Authorize both upload and download operations.

URL fetching and SSRF

  • Avoid server-side fetching of arbitrary user-provided URLs.
  • Prefer strict host allowlists and controlled egress.
  • Reject loopback, private, link-local and metadata-service destinations where not explicitly required.
  • Revalidate resolved addresses and redirect targets; DNS resolution and redirects can change the destination.
  • Apply timeouts, response-size limits and protocol restrictions.

Verification

Test malformed encodings, oversized values, injection payloads, unexpected object properties, path traversal, unsafe redirects, content-type confusion, archive bombs and SSRF boundary cases using a safe test environment.

Completion criteria

All trust-boundary inputs have server-side schemas, queries and rendering use context-safe APIs, file and URL handling are constrained, and negative tests cover malformed and adversarial inputs.

Common AI failure mode

Failure: An agent inserts untrusted user-controlled text into an HTML rendering context without context-appropriate output encoding or a safe text API.

Why it matters: Attacker-controlled markup or script can execute in another user's browser, exposing session data or performing actions with the victim's authority. Input validation alone does not make a value safe for every output context.

Symptoms:

  • User-controlled strings reach innerHTML, unsafe template escape hatches, or equivalent HTML sinks.
  • A value validated for one context is reused in HTML, an attribute, JavaScript, CSS, or a URL without context-specific handling.
  • Tests cover ordinary input but omit markup and event-handler payloads in rendered output.

Prevention: Keep untrusted values as text using safe DOM APIs such as textContent and framework auto-escaping. When rich HTML is a genuine requirement, use a maintained sanitizer with an explicit allowlist and verify the sanitized output at the final sink. Apply context-specific encoding, prohibit unsafe bypasses for untrusted data, and test representative injection payloads in a safe environment.

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.