|
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 |
2 | 13 |
|
3 | 14 | 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. |
4 | 15 |
|
@@ -47,6 +58,21 @@ This repository contains the **Better Together Community Engine** (an isolated R |
47 | 58 |
|
48 | 59 | ## Coding Guidelines |
49 | 60 |
|
| 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 | + |
50 | 76 | ## Test Environment Setup |
51 | 77 | - Configure the host Platform in a before block for controller/request/feature tests. |
52 | 78 | - Create/set a Platform as host (with community) before requests. |
|
0 commit comments