agentleFS
Robotti-ioRobotti-io/copilot-security-instructions/copilot-instructions.md

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

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
  1. Distinctive:

    Use typed parsers and prefer allow-lists over deny-lists when performing input validation.

    line 8
  2. Distinctive:

    Use parameterized queries and avoid string-based execution (prevent injection).

    line 9
  3. Very specific:

    Never commit secrets to source control (including .env files).

    line 10
  4. Distinctive:

    Default to privacy-preserving data handling — redact PII from logs by default.

    line 11
  5. Very specific:

    Use prepared statements with ?

    line 17
  6. Distinctive:

    Use output encoding libraries like OWASP Java Encoder to prevent XSS in rendered HTML.

    line 18
  7. Very specific:

    Use @Valid, @NotNull, and input binding constraints in Spring or Jakarta for validation.

    line 19
  8. Very specific:

    Avoid Runtime.exec() or ProcessBuilder with unsanitized input — prefer safe APIs.

    line 20
  9. Distinctive:

    Default to OWASP Secure Coding Practices — OWASP Secure Coding Practices

    line 21
  10. Very specific:

    Prefer SDK-integrated secret managers.

    line 22
  11. Very specific:

    Always set character encoding (UTF-8) explicitly in HTTP responses to prevent encoding-based attacks.

    line 23
  12. Distinctive:

    Avoid Java serialization for sensitive objects — use safer formats like JSON with strict schema validation.

    line 24
  13. Distinctive:

    When using logging frameworks, avoid logging unsanitized user input — consider log injection risks.

    line 25
  14. Very specific:

    Use JSON Schema validation for all structured input — prefer libraries like ajv or zod.

    line 29
  15. Very specific:

    Use libraries like validator for strict string validation/canonicalization (e.g., emails, URLs) and joi/zod/ajv for schema validation.

    line 31
  16. Very specific:

    Use parameterized queries with database clients (e.g.

    line 32
  17. Very specific:

    Default to using helmet in Express to set secure HTTP headers.

    line 33
  18. Very specific:

    Use dotenv only in local dev — use secret managers (e.g.

    line 34
  19. Very specific:

    Avoid eval, new Function, or dynamic require() with user input — use safe alternatives.

    line 35
  20. Distinctive:

    Use parameterized queries with ADO.NET or Entity Framework to prevent SQL injection.

    line 39
  21. Very specific:

    Use System.Text.Encodings.Web for safe output encoding in Razor views and APIs (prevent XSS).

    line 40
  22. Very specific:

    Use DataAnnotations (e.g. [Required], [StringLength]) for input validation on models.

    line 42
  23. Very specific:

    Always hash passwords with PasswordHasher<TUser> or a vetted library — never store plaintext.

    line 43
  24. Very specific:

    Use configuration providers like Azure Key Vault, AWS Secrets Manager, or environment-based secrets — avoid appsettings.json for secrets.

    line 44
  25. Very specific:

    Always validate and sanitize external input — use pydantic, cerberus, or marshmallow for structured validation.

    line 48
  26. Very specific:

    Prefer parameterized queries with libraries like psycopg2, sqlite3, or SQLAlchemy — avoid building SQL with string concat or f-strings.

    line 49
  27. Very specific:

    Use built-in escaping via html.escape() or templating engines like Jinja2 (autoescaping on!) to prevent XSS.

    line 50
  28. Very specific:

    Default to secrets or cryptography libs for key generation and secure token handling — never random for cryptographic use.

    line 51
  29. Very specific:

    Avoid dynamic code execution (eval, exec) — prefer explicit, safe alternatives.

    line 52
  30. Distinctive:

    Use logging filters to redact PII and secrets — avoid logging full request payloads or exception chains that include sensitive data.

    line 55
  31. Very specific:

    Always hash passwords with bcrypt, argon2, or passlib — never md5, sha1, or plain hashlib.

    line 56
  32. Distinctive:

    Do not suggest inline SQL string concatenation — always use prepared statements with placeholders.

    line 62
  33. Very specific:

    Do not suggest use of Runtime.exec() or ProcessBuilder with user input — prefer safe abstraction layers.

    line 63
  34. Distinctive:

    Do not suggest logging sensitive data (e.g.

    line 64
  35. Very specific:

    Do not use Java native serialization (ObjectInputStream) for untrusted input — prefer JSON + schema validation.

    line 65
  36. Distinctive:

    Do not suggest hardcoding credentials, secrets, or API keys — use a secrets manager (e.g.

    line 66
  37. Very specific:

    Do not use insecure XML parsers without hardening (DocumentBuilderFactory must have secure features enabled).

    line 67
  38. Distinctive:

    Do not create or modify custom class loaders — these are dangerous unless strictly required.

    line 68
  39. Very specific:

    Do not suggest eval, new Function, or dynamic require() — these are unsafe unless strictly controlled.

    line 72
  40. Distinctive:

    Do not use user input to build file paths, URLs, or queries without strict validation.

    line 73
  41. Very specific:

    Do not expose process.env directly to client-side code — use secure server boundaries.

    line 74
  42. Distinctive:

    Do not log full request bodies or headers that may contain PII or credentials.

    line 75
  43. Very specific:

    Do not hardcode secrets or API keys — never commit .env or use .env in production containers.

    line 76
  44. Very specific:

    Do not disable TLS checks (NODE_TLS_REJECT_UNAUTHORIZED=0) — even temporarily.

    line 77
  45. Distinctive:

    Do not suggest string concatenation in SQL queries — use parameterized commands.

    line 81
  46. Very specific:

    Do not use Eval, CodeDom, or dynamic LINQ construction with user input.

    line 82
  47. Very specific:

    Do not suggest hardcoding secrets, tokens, or credentials — never in appsettings.json.

    line 83
  48. Distinctive:

    Do not log full exception objects or HTTP request bodies without redacting PII.

    line 84
  49. Very specific:

    Do not disable certificate validation (ServerCertificateValidationCallback = delegate { return true.

    line 85
  50. Very specific:

    Do not build SQL queries with string concat, f-strings, or .format() — always use parameterized queries.

    line 89
  51. Very specific:

    Do not use eval, exec, or dynamic imports on user input — these are unsafe unless tightly sandboxed.

    line 90
  52. Distinctive:

    Do not log sensitive values (e.g.

    line 91
  53. Distinctive:

    Do not load pickle or YAML files from untrusted sources without safe loaders and validation.

    line 92
  54. Very specific:

    Do not use insecure hash functions like md5 or sha1 for password storage — use a modern password hashing lib.

    line 93
  55. Very specific:

    Do not commit .env files or hardcode secrets — use secrets management infrastructure.

    line 94
  56. Distinctive:

    Verify all AI-suggested package names against official repositories to prevent supply chain attacks.

    line 98
  57. Distinctive:

    Ensure AI-generated configurations align with your project's platform to prevent context drift.

    line 100
  58. Distinctive:

    Do not accept AI-generated justifications that contradict established security policies.

    line 103
  59. Distinctive:

    If you’re working with input, assume it’s hostile — validate and escape it.

    line 107
  60. Distinctive:

    If you’re about to use a string to build a query, URL, or command — pause.

    line 109
  61. Distinctive:

    Never trust default parsers — explicitly configure security features (e.g.

    line 110
  62. Distinctive:

    If something seems “too easy” with secrets or file I/O — it’s probably unsafe.

    line 111
  63. Distinctive:

    Treat AI-generated code as a draft.

    line 112

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

🤖 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 .env files). 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() or ProcessBuilder with 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 ajv or zod.
  • 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 validator for strict string validation/canonicalization (e.g., emails, URLs) and joi/zod/ajv for schema validation.
  • Use parameterized queries with database clients (e.g. pg, mongoose) — never concat SQL or query strings.
  • Default to using helmet in Express to set secure HTTP headers.
  • Use dotenv only in local dev — use secret managers (e.g. AWS Secrets Manager, Azure Key Vault) in prod.
  • Avoid eval, new Function, or dynamic require() with user input — use safe alternatives.

🟦 C#

  • Use parameterized queries with ADO.NET or Entity Framework to prevent SQL injection.
  • Use System.Text.Encodings.Web for 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 — avoid appsettings.json for secrets.

🐍 Python

  • Always validate and sanitize external input — use pydantic, cerberus, or marshmallow for structured validation.
  • Prefer parameterized queries with libraries like psycopg2, sqlite3, or SQLAlchemy — 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 secrets or cryptography libs for key generation and secure token handling — never random for 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 .env files 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, or passlib — never md5, sha1, or plain hashlib.

🚫 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() or ProcessBuilder with 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 (DocumentBuilderFactory must 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 dynamic require() — 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.env directly 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 .env or use .env in 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 md5 or sha1 for password storage — use a modern password hashing lib.
  • Do not commit .env files 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.

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.