Skip to content

Commit 4b7cea7

Browse files
committed
Initial Commit
0 parents  commit 4b7cea7

29 files changed

+1964
-0
lines changed

.github/copilot-instructions.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# 🤖 Copilot Secure Defaults for Java, Node.js, and C# Projects
2+
3+
These instructions guide GitHub Copilot to suggest secure, intentional code patterns for Java, Node.js, and C# development — especially in enterprise or team settings. Prioritize clarity, validation, and the principle of least surprise.
4+
5+
---
6+
7+
## 🔐 1. Secure by Default
8+
9+
- Sanitize and escape all user input (prevent XSS) — never render raw data to the page.
10+
- Validate all input strictly — use typed parsers and prefer allow-lists over deny-lists.
11+
- Use parameterized queries and avoid string-based execution (prevent injection).
12+
- Never store secrets in code or env files — use a secure vault (e.g. CyberArk Conjur, Azure Key Vault).
13+
- Default to privacy-preserving data handling — redact PII from logs by default.
14+
15+
---
16+
17+
## 🧩 2. Language-Specific Secure Patterns
18+
19+
### ☕ Java
20+
21+
- Use prepared statements with `?` placeholders in JDBC — never concat SQL strings.
22+
- Use output encoding libraries like OWASP Java Encoder to prevent XSS in rendered HTML.
23+
- Use `@Valid`, `@NotNull`, and input binding constraints in Spring or Jakarta for validation.
24+
- Avoid `Runtime.exec()` or `ProcessBuilder` with unsanitized input — prefer safe APIs.
25+
- Default to OWASP Secure Coding Practices — https://owasp.org/www-project-secure-coding-practices
26+
- Load secrets using SDK-integrated secret managers, not `System.getenv()` or `.properties` files.
27+
- Always set character encoding (`UTF-8`) explicitly in HTTP responses to prevent encoding-based attacks.
28+
- Avoid Java serialization for sensitive objects — use safer formats like JSON with strict schema validation.
29+
- When using logging frameworks, avoid logging unsanitized user input — consider log injection risks.
30+
31+
### 🟩 Node.js
32+
33+
- Use JSON Schema validation for all structured input — prefer libraries like `ajv` or `zod`.
34+
- Always sanitize and validate user input to prevent injection and XSS — `validator` and `joi` are common choices.
35+
- Use parameterized queries with database clients (e.g. `pg`, `mongoose`) — never concat SQL or query strings.
36+
- Default to using `helmet` in Express to set secure HTTP headers.
37+
- Use `dotenv` only in local dev — use secret managers (e.g. AWS Secrets Manager, Azure Key Vault) in prod.
38+
- Avoid `eval`, `new Function`, or dynamic `require()` with user input — use safe alternatives.
39+
40+
### 🟦 C#
41+
42+
- Use parameterized queries with ADO.NET or Entity Framework to prevent SQL injection.
43+
- Use `System.Text.Encodings.Web` for safe output encoding in Razor views and APIs (prevent XSS).
44+
- Apply `[ValidateAntiForgeryToken]` in ASP.NET MVC to prevent CSRF attacks.
45+
- Use `DataAnnotations` (e.g. `[Required]`, `[StringLength]`) for input validation on models.
46+
- Always hash passwords with `PasswordHasher<TUser>` or a vetted library — never store plaintext.
47+
- Use configuration providers like `Azure Key Vault`, `AWS Secrets Manager`, or environment-based secrets — avoid `appsettings.json` for secrets.
48+
49+
---
50+
51+
## 🚫 3. Do Not Suggest
52+
53+
### Java
54+
55+
- Do not suggest inline SQL string concatenation — always use prepared statements with placeholders.
56+
- Do not suggest use of `Runtime.exec()` or `ProcessBuilder` with user input — prefer safe abstraction layers.
57+
- Do not suggest logging sensitive data (e.g. passwords, tokens, session IDs) — log redacted metadata instead.
58+
- Do not use Java native serialization (`ObjectInputStream`) for untrusted input — prefer JSON + schema validation.
59+
- Do not suggest hardcoding credentials, secrets, or API keys — use a secrets manager (e.g. Conjur, Key Vault).
60+
- Do not use insecure XML parsers without hardening (`DocumentBuilderFactory` must have secure features enabled).
61+
- Do not create or modify custom class loaders — these are dangerous unless strictly required.
62+
63+
### Node.js
64+
65+
- Do not suggest `eval`, `new Function`, or dynamic `require()` — these are unsafe unless strictly controlled.
66+
- Do not use user input to build file paths, URLs, or queries without strict validation.
67+
- Do not expose `process.env` directly to client-side code — use secure server boundaries.
68+
- Do not log full request bodies or headers that may contain PII or credentials.
69+
- Do not hardcode secrets or API keys — never commit `.env` or use `.env` in production containers.
70+
- Do not disable TLS checks (`NODE_TLS_REJECT_UNAUTHORIZED=0`) — even temporarily.
71+
72+
### C#
73+
74+
- Do not suggest string concatenation in SQL queries — use parameterized commands.
75+
- Do not use `Eval`, `CodeDom`, or dynamic LINQ construction with user input.
76+
- Do not suggest hardcoding secrets, tokens, or credentials — never in `appsettings.json`.
77+
- Do not log full exception objects or HTTP request bodies without redacting PII.
78+
- Do not disable certificate validation (`ServerCertificateValidationCallback = delegate { return true; }`) in production.
79+
80+
---
81+
82+
## 🧠 4. AI-Generated Code Safety
83+
84+
- Verify all AI-suggested package names against official repositories to prevent supply chain attacks.
85+
- Confirm that AI-generated code references existing, secure APIs; avoid deprecated or non-existent methods.
86+
- Ensure AI-generated configurations align with your project's platform to prevent context drift.
87+
- Scrutinize AI-provided security recommendations; validate their completeness and applicability.
88+
- Cross-check any AI-cited references (e.g., CVEs, RFCs) for authenticity to avoid misinformation.
89+
- Do not accept AI-generated justifications that contradict established security policies.
90+
91+
---
92+
93+
## 💡 Developer Tips
94+
95+
- If you’re working with input, assume it’s hostile — validate and escape it.
96+
- For anything involving data access or transformation, ask: “Am I controlling this input path?”
97+
- If you’re about to use a string to build a query, URL, or command — pause. There’s probably a safer API.
98+
- Never trust default parsers — explicitly configure security features (e.g. disable DTDs in XML).
99+
- If something seems “too easy” with secrets or file I/O — it’s probably unsafe.
100+
- Treat AI-generated code as a draft; always review and test before integration.
101+
- Maintain a human-in-the-loop approach for critical code paths to catch potential issues.
102+
- Be cautious of overconfident AI suggestions; validate with trusted sources.
103+
- Regularly update and educate the team on AI-related security best practices.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 🕵️ Prompt: Logging & Sensitive Data Exposure Audit
2+
3+
You are reviewing application code for **unsafe logging practices**, **PII exposure**, and **improper log hygiene**.
4+
5+
Identify any of the following issues:
6+
7+
- Logging of sensitive information (e.g. passwords, tokens, API keys, session IDs)
8+
- Unfiltered logs that include full request/response bodies, headers, or user-submitted data
9+
- Logging of stack traces or exceptions without redaction or sanitization
10+
- Console or print statements left in production logic
11+
- Logs that include internal system paths, configurations, or database queries
12+
- Use of insecure transports for logs (e.g. writing logs to public cloud buckets without access control)
13+
14+
Also check for:
15+
16+
- Missing structured log formats (JSON, ECS, etc.)
17+
- Lack of logging levels or misuse of `debug`, `info`, `warn`, `error`
18+
19+
Provide refactor suggestions for redacting or excluding sensitive data. Recommend structured logging libraries or filters, and remind developers to align with least-privilege and data minimization principles.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 🔒 Prompt: Access Control & Authorization Review
2+
3+
You are auditing this codebase for **authorization and access control weaknesses**.
4+
5+
Focus on identifying:
6+
7+
- Missing or weak role-based access control (RBAC) or attribute-based access control (ABAC) enforcement
8+
- Direct access to protected routes, actions, or data without permission checks
9+
- Business logic that bypasses access validation (e.g. trusting client-side flags or roles)
10+
- Use of hardcoded role or permission strings without central enforcement
11+
- Functions exposed via APIs that should require authentication but don’t
12+
- Lack of contextual access checks (e.g. ensuring users can only access their own records)
13+
14+
If applicable, recommend use of secure middleware, centralized auth policies, and consistent permission enforcement patterns.
15+
16+
Highlight both missing controls and inconsistently applied ones. Annotate with comments and suggest safer refactors.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 🔐 Prompt: Hardcoded Secrets & Credential Audit
2+
3+
Act as a secure code reviewer analyzing this file for **hardcoded secrets**, API keys, tokens, credentials, or other sensitive information.
4+
5+
Flag any of the following patterns:
6+
7+
- API keys, access tokens, client secrets, or passwords embedded as string literals
8+
- Usage of `process.env` in frontend code or without proper runtime protection
9+
- Sensitive values written to `.env`, `.properties`, or `appsettings.json` files without secret management
10+
- OAuth tokens, JWTs, or HMAC secrets stored or logged in plaintext
11+
- Secrets stored in comments, JSON blobs, test configs, or logs
12+
13+
Highlight these with comments or suggested changes. Recommend usage of a secure vault (e.g. Azure Key Vault, AWS Secrets Manager, CyberArk Conjur) and explain the risk of each finding.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 🤖 Prompt: Unvalidated GenAI Code Acceptance Audit
2+
3+
You are reviewing code for signs that **AI-generated content** (e.g. from GitHub Copilot, ChatGPT, CodeWhisperer) has been accepted without validation, testing, or verification.
4+
5+
Look for and flag the following:
6+
7+
- Dependencies or packages that do not exist in official registries (possible hallucinated packages)
8+
- Calls to non-existent, deprecated, or undocumented API methods
9+
- Configuration code that does not match the project’s infrastructure (e.g. Azure config in AWS projects)
10+
- Use of placeholder, ambiguous, or overly generic variable/method names (e.g. `doTask()`, `handleThing()`)
11+
- Comments or TODOs referencing AI use without follow-up verification
12+
13+
Also check for:
14+
15+
- Lack of test coverage or validation for recently added logic
16+
- Sudden style or structure shifts that may indicate unreviewed AI insertion
17+
- No accompanying documentation or context for added code
18+
19+
Provide suggestions for verifying third-party resources, validating logic, and encouraging human-in-the-loop code review. Include annotations where risk or uncertainty is high.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 🧪 Prompt: Authentication Flow Review
2+
3+
You are performing a security review of the application’s **authentication logic and flow handling**.
4+
5+
Look for the following common risks:
6+
7+
- Incomplete or improperly enforced authentication on protected routes or resources
8+
- Weak or non-expiring session tokens (e.g. JWTs with long-lived expirations or missing `exp`)
9+
- Missing or broken CSRF protections (check for missing `SameSite`, CSRF tokens in forms)
10+
- Use of insecure login flows (e.g. no rate limiting, no multi-factor enforcement)
11+
- Tokens or session identifiers exposed via logs, URLs, or frontend JavaScript
12+
- Direct use of user-supplied credentials in downstream API requests without validation
13+
14+
Check for secure practices like:
15+
16+
- Short-lived tokens + refresh workflows
17+
- Server-side session storage with expiration
18+
- Secure cookie flags (`HttpOnly`, `Secure`, `SameSite=Strict`)
19+
- Use of well-tested identity providers or auth frameworks
20+
21+
Recommend mitigations for any insecure implementations you identify.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ⚠️ Prompt: Insecure or Deprecated API Usage Scan
2+
3+
Act as a secure code auditor. Your goal is to identify any usage of **insecure, deprecated, or high-risk APIs** that may introduce vulnerabilities or future instability.
4+
5+
Look for and flag the following patterns:
6+
7+
- Use of deprecated cryptographic functions (e.g. MD5, SHA1, `crypto.createCipher`, `System.Security.Cryptography.SHA1CryptoServiceProvider`)
8+
- Legacy input/output APIs that lack sanitization or encoding features
9+
- Insecure deserialization functions (e.g. `eval`, `JSON.parse` on external input, `ObjectInputStream`, `BinaryFormatter`)
10+
- Unsafe file access or shell execution APIs (`fs.readFileSync` on user input, `Runtime.exec`, `ProcessBuilder`, `child_process.exec`)
11+
- Unverified third-party libraries or packages not pinned to versions
12+
- APIs that allow insecure HTTP communication (e.g. `http.get`, `fetch` without TLS, `WebClient` without `UseHttps`)
13+
14+
Explain:
15+
16+
- Why the API is dangerous
17+
- What safer alternative is recommended
18+
- When/if it’s okay to use with proper mitigation
19+
20+
Provide annotations or refactor suggestions where applicable.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 🛡️ Prompt: Input Validation & Sanitization Audit
2+
3+
You are reviewing code for unsafe or missing input validation. Your task is to identify all potential risks related to untrusted user input.
4+
5+
Flag any of the following:
6+
7+
- No use of structured input validation libraries (e.g. `Joi`, `Zod`, `Ajv`, `DataAnnotations`, `@Valid`)
8+
- Direct use of request/query/path/body parameters without validation or sanitization
9+
- Unescaped input rendered into HTML templates (possible XSS)
10+
- No schema enforcement for JSON input or serialized data
11+
- Use of regex for validation without input bounds (may lead to ReDoS)
12+
- Implicit coercion of input types (e.g. treating string as number or boolean without validation)
13+
14+
Recommend:
15+
16+
- Strict, schema-based input validation
17+
- HTML/context-aware encoding of dynamic output
18+
- Safe handling of nested objects, arrays, and dynamic keys
19+
- Input length and character whitelisting where appropriate
20+
21+
Provide suggested fixes and explanations to help developers understand *why* these patterns are dangerous.

.github/workflows/markdownlint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Markdown Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
9+
jobs:
10+
markdown-lint:
11+
runs-on: [Linux]
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18.x'
20+
21+
- name: Clear npm cache
22+
run: npm cache clean --force
23+
24+
- name: Install markdownlint-cli
25+
run: npm install
26+
27+
- name: Run markdownlint
28+
run: npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

0 commit comments

Comments
 (0)