copilot-security-instructions
Copilot instructions42 starsChanged 10 months agoApache-2.0View on GitHub
These instructions guide GitHub Copilot to suggest secure, intentional code patterns for Java, Node.js, C#, and Python development — especially in enterprise or team settings. Prioritize clarity, validation, and the principle of least surprise.
- Reads credentials
In this repository10 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- markdown-customizationsSkill
- access-control-reviewSkill
- dependency-cve-triageSkill
- genai-acceptance-reviewSkill
- input-validation-hardeningSkill
- secrets-and-logging-hygieneSkill
- secure-code-reviewSkill
- secure-fix-validationSkill
- threat-modelSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
63 rules. About 0 are common, 27 are distinctive, and 36 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈27
Distinctive · estimate
This author's own choices. Worth a look.
36
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 8
Use typed parsers and prefer allow-lists over deny-lists when performing input validation.
- Distinctive: line 9
Use parameterized queries and avoid string-based execution (prevent injection).
- Very specific: line 10
Never commit secrets to source control (including .env files).
- Distinctive: line 11
Default to privacy-preserving data handling — redact PII from logs by default.
- Very specific: line 17
Use prepared statements with ?
- Distinctive: line 18
Use output encoding libraries like OWASP Java Encoder to prevent XSS in rendered HTML.
- Very specific: line 19
Use @Valid, @NotNull, and input binding constraints in Spring or Jakarta for validation.
- Very specific: line 20
Avoid Runtime.exec() or ProcessBuilder with unsanitized input — prefer safe APIs.
- Distinctive: line 21
Default to OWASP Secure Coding Practices — OWASP Secure Coding Practices
- Very specific: line 22
Prefer SDK-integrated secret managers.
- Very specific: line 23
Always set character encoding (UTF-8) explicitly in HTTP responses to prevent encoding-based attacks.
- Distinctive: line 24
Avoid Java serialization for sensitive objects — use safer formats like JSON with strict schema validation.
- Distinctive: line 25
When using logging frameworks, avoid logging unsanitized user input — consider log injection risks.
- Very specific: line 29
Use JSON Schema validation for all structured input — prefer libraries like ajv or zod.
- Very specific: line 31
Use libraries like validator for strict string validation/canonicalization (e.g., emails, URLs) and joi/zod/ajv for schema validation.
- Very specific: line 32
Use parameterized queries with database clients (e.g.
- Very specific: line 33
Default to using helmet in Express to set secure HTTP headers.
- Very specific: line 34
Use dotenv only in local dev — use secret managers (e.g.
- Very specific: line 35
Avoid eval, new Function, or dynamic require() with user input — use safe alternatives.
- Distinctive: line 39
Use parameterized queries with ADO.NET or Entity Framework to prevent SQL injection.
- Very specific: line 40
Use System.Text.Encodings.Web for safe output encoding in Razor views and APIs (prevent XSS).
- Very specific: line 42
Use DataAnnotations (e.g. [Required], [StringLength]) for input validation on models.
- Very specific: line 43
Always hash passwords with PasswordHasher<TUser> or a vetted library — never store plaintext.
- Very specific: line 44
Use configuration providers like Azure Key Vault, AWS Secrets Manager, or environment-based secrets — avoid appsettings.json for secrets.
- Very specific: line 48
Always validate and sanitize external input — use pydantic, cerberus, or marshmallow for structured validation.
- Very specific: line 49
Prefer parameterized queries with libraries like psycopg2, sqlite3, or SQLAlchemy — avoid building SQL with string concat or f-strings.
- Very specific: line 50
Use built-in escaping via html.escape() or templating engines like Jinja2 (autoescaping on!) to prevent XSS.
- Very specific: line 51
Default to secrets or cryptography libs for key generation and secure token handling — never random for cryptographic use.
- Very specific: line 52
Avoid dynamic code execution (eval, exec) — prefer explicit, safe alternatives.
- Distinctive: line 55
Use logging filters to redact PII and secrets — avoid logging full request payloads or exception chains that include sensitive data.
- Very specific: line 56
Always hash passwords with bcrypt, argon2, or passlib — never md5, sha1, or plain hashlib.
- Distinctive: line 62
Do not suggest inline SQL string concatenation — always use prepared statements with placeholders.
- Very specific: line 63
Do not suggest use of Runtime.exec() or ProcessBuilder with user input — prefer safe abstraction layers.
- Distinctive: line 64
Do not suggest logging sensitive data (e.g.
- Very specific: line 65
Do not use Java native serialization (ObjectInputStream) for untrusted input — prefer JSON + schema validation.
- Distinctive: line 66
Do not suggest hardcoding credentials, secrets, or API keys — use a secrets manager (e.g.
- Very specific: line 67
Do not use insecure XML parsers without hardening (DocumentBuilderFactory must have secure features enabled).
- Distinctive: line 68
Do not create or modify custom class loaders — these are dangerous unless strictly required.
- Very specific: line 72
Do not suggest eval, new Function, or dynamic require() — these are unsafe unless strictly controlled.
- Distinctive: line 73
Do not use user input to build file paths, URLs, or queries without strict validation.
- Very specific: line 74
Do not expose process.env directly to client-side code — use secure server boundaries.
- Distinctive: line 75
Do not log full request bodies or headers that may contain PII or credentials.
- Very specific: line 76
Do not hardcode secrets or API keys — never commit .env or use .env in production containers.
- Very specific: line 77
Do not disable TLS checks (NODE_TLS_REJECT_UNAUTHORIZED=0) — even temporarily.
- Distinctive: line 81
Do not suggest string concatenation in SQL queries — use parameterized commands.
- Very specific: line 82
Do not use Eval, CodeDom, or dynamic LINQ construction with user input.
- Very specific: line 83
Do not suggest hardcoding secrets, tokens, or credentials — never in appsettings.json.
- Distinctive: line 84
Do not log full exception objects or HTTP request bodies without redacting PII.
- Very specific: line 85
Do not disable certificate validation (ServerCertificateValidationCallback = delegate { return true.
- Very specific: line 89
Do not build SQL queries with string concat, f-strings, or .format() — always use parameterized queries.
- Very specific: line 90
Do not use eval, exec, or dynamic imports on user input — these are unsafe unless tightly sandboxed.
- Distinctive: line 91
Do not log sensitive values (e.g.
- Distinctive: line 92
Do not load pickle or YAML files from untrusted sources without safe loaders and validation.
- Very specific: line 93
Do not use insecure hash functions like md5 or sha1 for password storage — use a modern password hashing lib.
- Very specific: line 94
Do not commit .env files or hardcode secrets — use secrets management infrastructure.
- Distinctive: line 98
Verify all AI-suggested package names against official repositories to prevent supply chain attacks.
- Distinctive: line 100
Ensure AI-generated configurations align with your project's platform to prevent context drift.
- Distinctive: line 103
Do not accept AI-generated justifications that contradict established security policies.
- Distinctive: line 107
If you’re working with input, assume it’s hostile — validate and escape it.
- Distinctive: line 109
If you’re about to use a string to build a query, URL, or command — pause.
- Distinctive: line 110
Never trust default parsers — explicitly configure security features (e.g.
- Distinctive: line 111
If something seems “too easy” with secrets or file I/O — it’s probably unsafe.
- Distinctive: line 112
Treat AI-generated code as a draft.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions 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
🤖 Copilot Secure Defaults for Java, Node.js, C#, and Python Projects
These instructions guide GitHub Copilot to suggest secure, intentional code patterns for Java, Node.js, C#, and Python development — especially in enterprise or team settings. Prioritize clarity, validation, and the principle of least surprise.
🔐 1. Secure by Default
- Validate input strictly, and prevent XSS primarily via contextual output encoding (HTML/attribute/JS/URL). Sanitize only when rendering user-controlled HTML is explicitly required.
- Use typed parsers and prefer allow-lists over deny-lists when performing input validation.
- Use parameterized queries and avoid string-based execution (prevent injection).
- Never commit secrets to source control (including
.envfiles). Use a secure vault/secret manager (e.g. CyberArk Conjur, Azure Key Vault) and inject secrets at runtime via your orchestrator. - Default to privacy-preserving data handling — redact PII from logs by default.
🧩 2. Language-Specific Secure Patterns
☕ Java
- Use prepared statements with
?placeholders in JDBC — never concat SQL strings. - Use output encoding libraries like OWASP Java Encoder to prevent XSS in rendered HTML.
- Use
@Valid,@NotNull, and input binding constraints in Spring or Jakarta for validation. - Avoid
Runtime.exec()orProcessBuilderwith unsanitized input — prefer safe APIs. - Default to OWASP Secure Coding Practices — OWASP Secure Coding Practices
- Prefer SDK-integrated secret managers; environment variables are acceptable when injected securely by the orchestrator/runtime. Do not commit secrets in
.properties/config files. - Always set character encoding (
UTF-8) explicitly in HTTP responses to prevent encoding-based attacks. - Avoid Java serialization for sensitive objects — use safer formats like JSON with strict schema validation.
- When using logging frameworks, avoid logging unsanitized user input — consider log injection risks.
🟩 Node.js
- Use JSON Schema validation for all structured input — prefer libraries like
ajvorzod. - Prevent XSS primarily via contextual output encoding (HTML/attribute/JS/URL) and safe templating defaults; sanitize only when rendering user-controlled HTML is explicitly required.
- Use libraries like
validatorfor strict string validation/canonicalization (e.g., emails, URLs) andjoi/zod/ajvfor schema validation. - Use parameterized queries with database clients (e.g.
pg,mongoose) — never concat SQL or query strings. - Default to using
helmetin Express to set secure HTTP headers. - Use
dotenvonly in local dev — use secret managers (e.g. AWS Secrets Manager, Azure Key Vault) in prod. - Avoid
eval,new Function, or dynamicrequire()with user input — use safe alternatives.
🟦 C#
- Use parameterized queries with ADO.NET or Entity Framework to prevent SQL injection.
- Use
System.Text.Encodings.Webfor safe output encoding in Razor views and APIs (prevent XSS). - Apply
[ValidateAntiForgeryToken]in ASP.NET MVC to prevent CSRF attacks. - Use
DataAnnotations(e.g.[Required],[StringLength]) for input validation on models. - Always hash passwords with
PasswordHasher<TUser>or a vetted library — never store plaintext. - Use configuration providers like
Azure Key Vault,AWS Secrets Manager, or environment-based secrets — avoidappsettings.jsonfor secrets.
🐍 Python
- Always validate and sanitize external input — use
pydantic,cerberus, ormarshmallowfor structured validation. - Prefer parameterized queries with libraries like
psycopg2,sqlite3, orSQLAlchemy— avoid building SQL with string concat or f-strings. - Use built-in escaping via
html.escape()or templating engines like Jinja2 (autoescaping on!) to prevent XSS. - Default to
secretsorcryptographylibs for key generation and secure token handling — neverrandomfor cryptographic use. - Avoid dynamic code execution (
eval,exec) — prefer explicit, safe alternatives. - Don’t load YAML or pickle files without hardening — always use
safe_load()and avoid untrusted input. - Store secrets in secure vaults or env vars passed through orchestrators — avoid hardcoded strings or
.envfiles in prod. - Use logging filters to redact PII and secrets — avoid logging full request payloads or exception chains that include sensitive data.
- Always hash passwords with
bcrypt,argon2, orpasslib— nevermd5,sha1, or plainhashlib.
🚫 3. Do Not Suggest
Java
- Do not suggest inline SQL string concatenation — always use prepared statements with placeholders.
- Do not suggest use of
Runtime.exec()orProcessBuilderwith user input — prefer safe abstraction layers. - Do not suggest logging sensitive data (e.g. passwords, tokens, session IDs) — log redacted metadata instead.
- Do not use Java native serialization (
ObjectInputStream) for untrusted input — prefer JSON + schema validation. - Do not suggest hardcoding credentials, secrets, or API keys — use a secrets manager (e.g. Conjur, Key Vault).
- Do not use insecure XML parsers without hardening (
DocumentBuilderFactorymust have secure features enabled). - Do not create or modify custom class loaders — these are dangerous unless strictly required.
Node.js
- Do not suggest
eval,new Function, or dynamicrequire()— these are unsafe unless strictly controlled. - Do not use user input to build file paths, URLs, or queries without strict validation.
- Do not expose
process.envdirectly to client-side code — use secure server boundaries. - Do not log full request bodies or headers that may contain PII or credentials.
- Do not hardcode secrets or API keys — never commit
.envor use.envin production containers. - Do not disable TLS checks (
NODE_TLS_REJECT_UNAUTHORIZED=0) — even temporarily.
C#
- Do not suggest string concatenation in SQL queries — use parameterized commands.
- Do not use
Eval,CodeDom, or dynamic LINQ construction with user input. - Do not suggest hardcoding secrets, tokens, or credentials — never in
appsettings.json. - Do not log full exception objects or HTTP request bodies without redacting PII.
- Do not disable certificate validation (
ServerCertificateValidationCallback = delegate { return true; }) in production.
Python
- Do not build SQL queries with string concat, f-strings, or
.format()— always use parameterized queries. - Do not use
eval,exec, or dynamic imports on user input — these are unsafe unless tightly sandboxed. - Do not log sensitive values (e.g. API keys, passwords) or full stack traces with PII.
- Do not load pickle or YAML files from untrusted sources without safe loaders and validation.
- Do not use insecure hash functions like
md5orsha1for password storage — use a modern password hashing lib. - Do not commit
.envfiles or hardcode secrets — use secrets management infrastructure.
🧠 4. AI-Generated Code Safety
- Verify all AI-suggested package names against official repositories to prevent supply chain attacks.
- Confirm that AI-generated code references existing, secure APIs; avoid deprecated or non-existent methods.
- Ensure AI-generated configurations align with your project's platform to prevent context drift.
- Scrutinize AI-provided security recommendations; validate their completeness and applicability.
- Cross-check any AI-cited references (e.g., CVEs, RFCs) for authenticity to avoid misinformation.
- Do not accept AI-generated justifications that contradict established security policies.
💡 Developer Tips
- If you’re working with input, assume it’s hostile — validate and escape it.
- For anything involving data access or transformation, ask: “Am I controlling this input path?”
- If you’re about to use a string to build a query, URL, or command — pause. There’s probably a safer API.
- Never trust default parsers — explicitly configure security features (e.g. disable DTDs in XML).
- If something seems “too easy” with secrets or file I/O — it’s probably unsafe.
- Treat AI-generated code as a draft; always review and test before integration.
- Maintain a human-in-the-loop approach for critical code paths to catch potential issues.
- Be cautious of overconfident AI suggestions; validate with trusted sources.
- Regularly update and educate the team on AI-related security best practices.
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.

