strategy-security-first
Skill4 starsChanged 4 months agoMITView on GitHub
Treat all external data as hostile until proven otherwise; validate and escape at every boundary, never log secrets, and choose safe defaults so a mistake fails closed rather than open. Use when the task involves accepting or processing data from outside the program — user requests, uploaded files, external APIs, or queue messages; the task touches secrets or sensitive values — API keys, passwords, tokens, or personal data — that must not leak into logs or output; the user asks to harden code, review it for security, or choose safe defaults so that mistakes fail closed rather than open. Keywords: strategy, security, hostile, boundary, escape, validate, secrets, safe-default, hardening, untrusted.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
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
- Distinctive: line 67
Do not impose full hardening on a one-off local script that never accepts external data and never runs in a shared or exposed environment.
- Distinctive: line 69
Do not add boundary validation and escaping to values that are computed internally and never derived from outside the trust boundary.
- Distinctive: line 87
Never treat data that crossed a system boundary — a request, a file, a queue message, a third-party response — as safe.
- Distinctive: line 92
Prefer defaults that fail closed — deny by default, escape on output, and reject malformed data — so a missing check errs toward safety …
- Distinctive: line 97
Avoid writing passwords, tokens, keys, or personal data into logs, error messages, or exception traces, and redact them before any output.
- Distinctive: line 144
Not applicable — no I/O, auth, or untrusted input.
≈ “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.
Files
<!-- generated: do not edit — source: knowledge/atoms/ai-rules/strategy-security-first/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Strategy — Security First
When to use
- The task involves accepting or processing data from outside the program — user requests, uploaded files, external APIs, or queue messages.
- The task touches secrets or sensitive values — API keys, passwords, tokens, or personal data — that must not leak into logs or output.
- The user asks to harden code, review it for security, or choose safe defaults so that mistakes fail closed rather than open.
When NOT to use
- Do not impose full hardening on a one-off local script that never accepts external data and never runs in a shared or exposed environment.
- Do not add boundary validation and escaping to values that are computed internally and never derived from outside the trust boundary.
Core guidance
- Escape data for the context it is rendered into — Escape or parameterize data for the exact context it flows into — HTML, SQL, a shell, a URL — using the context-appropriate mechanism rather than a generic one.
- Grant the least privilege that works — Give code and callers the narrowest permissions, scopes, and lifetimes that let them do their job, and deny everything else by default.
- Parameterize instead of concatenating untrusted values — Pass untrusted values as bound parameters to prepared statements and never concatenate them into a query, command, or path string.
- Redact secrets before they reach any sink — Redact or omit secrets and sensitive fields before logging, serializing, or including them in an error message, rather than relying on downstream filtering.
- Validate external data at the boundary — Validate the shape, type, and range of external data at the point it enters the system, and reject anything that does not match before it reaches business logic.
Never
- Never treat data that crossed a system boundary — a request, a file, a queue message, a third-party response — as safe; validate it before use.
Prefer
- Prefer defaults that fail closed — deny by default, escape on output, and reject malformed data — so a missing check errs toward safety rather than exposure.
Avoid
- Avoid writing passwords, tokens, keys, or personal data into logs, error messages, or exception traces, and redact them before any output.
Escalate to user when
- Escalate to the user when the task appears to require relaxing a security control — disabling validation, widening access, or storing a secret in plaintext — and confirm before doing it.
Quick recipe
- Identify every point where external data enters and every secret or sensitive field the code touches, so you know where to validate and what to redact. (verify: You can name each entry boundary and each sensitive value the change handles.)
- Validate each input against an allowlist at its boundary, bind untrusted values as parameters, escape for the output context, and redact secrets before any sink. (verify: Every external value is validated before use, no untrusted value is concatenated into code, and no secret reaches a log or error message unredacted.)
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Failing open when a security check errors | Failing open turns an incident in the check itself into an open door, so an outage<br>becomes a bypass. | Treat any error in a security check as a denial, log the failure, and require the<br>check to succeed explicitly before proceeding. |
| Logging whole payloads that may hold secrets | Bulk logging captures passwords, tokens, and personal data into a durable sink<br>that many people can read, creating a standing leak. | Log only the specific fields you need for diagnosis, with sensitive values<br>redacted, and never log whole credential-bearing payloads. |
| Concatenating untrusted values into a statement | Concatenation mixes data with code, letting a crafted value change the statement's<br>meaning — the root cause of injection. | Use bound parameters for statements, argument arrays for processes, and validated<br>identifiers for paths, keeping data out of the code string. |
See references/anti-patterns.md.
Common mistakes
- Relying on a blocklist of bad values — Filtering out a fixed list of known-bad strings or characters lets any unlisted variant through. Fix: Validate against an allowlist of what is permitted, and escape or parameterize for the target context instead of stripping bad input.
- Secrets leaking through exception traces — Passing a secret as a function argument can leak it into an exception stack trace or debug dump when that function throws. Fix: Wrap secrets in an opaque value object whose string form is redacted, and never interpolate a raw secret into an error message.
- Validating after the value has already been used — Validating external data only after it has already been used in a query, path, or command leaves the dangerous operation exposed. Fix: Validate at the boundary before the value is used anywhere, and reject invalid data before any downstream operation runs.
Version notes
- Security-first discipline is version-agnostic (PHP >=7.4) — Treating external data as hostile and choosing safe defaults is a strategy that applies to any PHP version; it constrains how the agent reasons about trust, not which language features it uses, so it holds from PHP 7.4 upward.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/ai-rules/strategy-security-first.yaml.
Additional resources
- references/anti-patterns.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: ai-rules/strategy-minimal-diff, security/sql-injection-prevention
<!-- graph-fragment: graph/fragments/ai-rules/strategy-security-first.yaml -->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
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.

