Skip to content

Commit d921f33

Browse files
committed
feat: Enhance security guidelines in documentation for code generation and review processes
1 parent f45e2c3 commit d921f33

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.github/copilot-instructions.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# Better Together Community Engine – Rails App & Engine Guidelines
1+
# Be## Core Principles
2+
3+
- **Security first**: Run `bundle exec brakeman -q` before generating code; fix high-confidence vulnerabilities
4+
- **Accessibility first** (WCAG AA/AAA): semantic HTML, ARIA roles, keyboard nav, proper contrast.
5+
- **Hotwire everywhere**: Turbo for navigation/updates; Stimulus controllers for interactivity.
6+
- **Keep controllers thin**; move business logic to POROs/service objects or concerns.
7+
- **Prefer explicit join models** over polymorphic associations when validation matters.
8+
- **Avoid the term "STI"** in code/comments; use "single-table inheritance" or alternate designs.
9+
- **Use `ENV.fetch`** rather than `ENV[]`.
10+
- **Always add policy/authorization checks** on links/buttons to controller actions.
11+
- **i18n & Mobility**: every user-facing string must be translatable; include missing keys.
12+
- Provide translations for all available locales (e.g., en, es, fr) when adding new strings.er Community Engine – Rails App & Engine Guidelines
213

314
This repository contains the **Better Together Community Engine** (an isolated Rails engine under the `BetterTogether` namespace) and/or a host Rails app that mounts it. Use these instructions for all code generation.
415

@@ -47,6 +58,21 @@ This repository contains the **Better Together Community Engine** (an isolated R
4758

4859
## Coding Guidelines
4960

61+
### Security Requirements
62+
- **Run Brakeman before generating code**: `bundle exec brakeman -q`
63+
- **Fix high-confidence vulnerabilities immediately** - never ignore security warnings with "High" confidence
64+
- **Review and address medium-confidence warnings** that are security-relevant
65+
- **Safe coding practices when generating code:**
66+
- **No unsafe reflection**: Never use `constantize`, `safe_constantize`, or `eval` on user input
67+
- **Use allow-lists for dynamic class resolution**: Follow the `joatu_source_class` pattern with concern-based allow-lists
68+
- **Validate user inputs**: Always sanitize and validate parameters, especially for file uploads and dynamic queries
69+
- **Strong parameters**: Use Rails strong parameters in all controllers
70+
- **Authorization everywhere**: Implement Pundit policy checks on all actions
71+
- **SQL injection prevention**: Use parameterized queries, avoid string interpolation in SQL
72+
- **XSS prevention**: Use Rails auto-escaping, sanitize HTML inputs with allowlists
73+
- **For reflection-based features**: Create concerns with `included_in_models` class methods for safe dynamic class resolution
74+
- **Post-generation security check**: Run `bundle exec brakeman -c UnsafeReflection,SQL,CrossSiteScripting` after major code changes
75+
5076
## Test Environment Setup
5177
- Configure the host Platform in a before block for controller/request/feature tests.
5278
- Create/set a Platform as host (with community) before requests.

AGENTS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,22 @@ Instructions for GitHub Copilot and other automated contributors working in this
2424
- **Security:** `bundle exec brakeman -q -w2` and `bundle exec bundler-audit --update`
2525
- **Style:** `bin/codex_style_guard`
2626

27+
## Security Requirements
28+
- **Always run Brakeman** before generating/committing code: `bundle exec brakeman -q`
29+
- **Address high-confidence vulnerabilities immediately** - anything with "High" confidence must be fixed
30+
- **Review medium-confidence warnings** - evaluate and fix security-relevant issues
31+
- **Use safe coding practices:**
32+
- Never use `constantize`, `safe_constantize`, or `eval` on user input
33+
- Use allow-lists for dynamic class resolution (see `joatu_source_class` pattern)
34+
- Sanitize and validate all user inputs
35+
- Use strong parameters in controllers
36+
- Implement proper authorization checks (Pundit policies)
37+
- **For reflection-based code**: Create concern-based allow-lists using `included_in_models` pattern
38+
- **Run security scan after major changes**: `bundle exec brakeman -c UnsafeReflection,SQL,CrossSiteScripting`
39+
2740
## Conventions
2841
- Make incremental changes with passing tests.
42+
- **Security first**: Run `bundle exec brakeman -q` before committing code changes.
2943
- Avoid introducing new external services in tests; stub where possible.
3044
- If RuboCop reports offenses after autocorrect, update and rerun until clean.
3145
- Keep commit messages and PR descriptions concise and informative.

0 commit comments

Comments
 (0)