From da713084fc935ebb7e692f3c8879fcb7e7f811ed Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 20 Sep 2026 13:08:43 -0500 Subject: [PATCH 01/19] feat(rails-security): add Rails security skill Adds a rails-security skill covering production configuration, authentication and session rotation, authorization, strong parameters, SQL injection, XSS and output escaping, CSRF, file uploads, API security, credentials, untrusted boundaries, and dependency scanning. Fills the Rails gap alongside the existing laravel-security, django-security, and springboot-security framework skills. Defers decisions to rules/ruby/security.md and focuses on the how, per the rules-vs-skills split. Registers skills/rails-security in the framework-language install module, agent.yaml, the package.json files list, the ruby entry in config/project-stack-mappings.json, and the plugin and marketplace manifests. Adds the reciprocal skill reference to rules/ruby/security.md, matching how the python, php, and java security rules point at their framework skills. Updates the catalog count to 294 across the documented surfaces, and bumps registryDigest and coverage.skills in the skill-triggers context pack by hand: scripts/dev/generate-skill-triggers.js requires Codex auth to regenerate, and no new triggers are introduced, so triggersDigest is unchanged. --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- .gemini/GEMINI.md | 2 +- AGENTS.md | 4 +- README.md | 7 +- README.zh-CN.md | 2 +- SOUL.md | 2 +- agent.yaml | 1 + config/project-stack-mappings.json | 1 + docs/tr/AGENTS.md | 4 +- docs/zh-CN/AGENTS.md | 4 +- docs/zh-CN/README.md | 6 +- manifests/context-packs/skill-triggers@1.json | 4 +- manifests/install-modules.json | 1 + package.json | 1 + rules/ruby/security.md | 2 + skills/rails-security/SKILL.md | 449 ++++++++++++++++++ 17 files changed, 475 insertions(+), 19 deletions(-) create mode 100644 skills/rails-security/SKILL.md diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 2de2c87ad..d4c58e038 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -11,7 +11,7 @@ { "name": "ecc", "source": "./", - "description": "Harness-native ECC operator layer - 71 agents, 314 skills, 98 legacy command shims, reusable hooks, rules, selective install profiles, and production-ready workflows for Claude Code, Codex, OpenCode, Cursor, and related agent harnesses", + "description": "Harness-native ECC operator layer - 71 agents, 315 skills, 98 legacy command shims, reusable hooks, rules, selective install profiles, and production-ready workflows for Claude Code, Codex, OpenCode, Cursor, and related agent harnesses", "version": "2.2.3", "author": { "name": "Affaan Mustafa", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index de514e32d..1cba4b769 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ecc", "version": "2.2.3", - "description": "Harness-native ECC plugin for engineering teams - 71 agents, 314 skills, 98 legacy command shims, reusable hooks, rules, MCP conventions, and operator workflows for Claude Code plus adjacent agent harnesses", + "description": "Harness-native ECC plugin for engineering teams - 71 agents, 315 skills, 98 legacy command shims, reusable hooks, rules, MCP conventions, and operator workflows for Claude Code plus adjacent agent harnesses", "author": { "name": "Affaan Mustafa", "url": "https://x.com/affaanmustafa" diff --git a/.gemini/GEMINI.md b/.gemini/GEMINI.md index 408d70622..9fb29d8e1 100644 --- a/.gemini/GEMINI.md +++ b/.gemini/GEMINI.md @@ -4,7 +4,7 @@ This file provides Gemini CLI with the baseline ECC workflow, review standards, ## Overview -ECC is a cross-harness coding system with 71 specialized agents, 314 skills, and 98 commands. +ECC is a cross-harness coding system with 71 specialized agents, 315 skills, and 98 commands. Gemini support is currently focused on a strong project-local instruction layer via `.gemini/GEMINI.md`, plus the shared MCP catalog and package-manager setup assets shipped by the installer. diff --git a/AGENTS.md b/AGENTS.md index a8579c265..036a6fbb6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # ECC — Agent Instructions -This is a **production-ready AI coding plugin** providing 71 specialized agents, 314 skills, 98 commands, and automated hook workflows for software development. +This is a **production-ready AI coding plugin** providing 71 specialized agents, 315 skills, 98 commands, and automated hook workflows for software development. **Version:** 2.2.3 @@ -202,7 +202,7 @@ Troubleshoot failures: check test isolation → verify mocks → fix implementat ``` agents/ — 71 specialized subagents -skills/ — 314 workflow skills and domain knowledge +skills/ — 315 workflow skills and domain knowledge commands/ — 98 slash commands hooks/ — Trigger-based automations rules/ — Always-follow guidelines (common + per-language) diff --git a/README.md b/README.md index d8017086c..81f50b893 100644 --- a/README.md +++ b/README.md @@ -141,12 +141,12 @@ Instead of rebuilding that process in every prompt, you install it once and make ECC is MIT-licensed open source. It works best with Claude Code today, has native Codex and Qoder plugin paths, and provides capability-limited adapters for Cursor, OpenCode, Gemini, Zed, GitHub Copilot, Antigravity, Qwen, and other harnesses. See the [support status matrix](#platform-support) before assuming feature parity. -Access to 71 agents, 314 skills, and 98 legacy command shims, plus hooks, rules, memory, continuous learning, and AgentShield security scanning. The agents are specialized for planning, review, build repair, security, architecture, and domain work. +Access to 71 agents, 315 skills, and 98 legacy command shims, plus hooks, rules, memory, continuous learning, and AgentShield security scanning. The agents are specialized for planning, review, build repair, security, architecture, and domain work. | Included | Count | What it gives you | | ---------------- | ----------: | ------------------------------------------------------------------------------------ | | Agents | 71 agents | Planning, review, build repair, security, architecture, and domain work | -| Skills | 314 skills | TDD, research, security, docs, frontend, data, ML, operations, and more | +| Skills | 315 skills | TDD, research, security, docs, frontend, data, ML, operations, and more | | Commands | 98 commands | Convenient entry points while ECC moves to a skills-first surface | | Hooks and memory | Runtime | Enforcement, session summaries, continuous learning, instincts, and context controls | | Rules | Selective | Always-loaded standards you choose by language or project | @@ -861,7 +861,7 @@ Stable graduation of the 2.0 line: control-pane substrate, worktree lifecycle se ```text ECC/ |-- agents/ # 71 specialized subagents for delegation -|-- skills/ # 314 reusable workflows loaded on demand +|-- skills/ # 315 reusable workflows loaded on demand |-- commands/ # 98 maintained slash-command shims |-- rules/ # opt-in common and language standards |-- hooks/ # runtime automation and enforcement @@ -957,6 +957,7 @@ ECC/ | |-- quarkus-tdd/ # Quarkus TDD | |-- quarkus-verification/ # Quarkus verification | |-- rails-patterns/ # Rails architecture patterns +| |-- rails-security/ # Rails security practices | |-- springboot-patterns/ # Java Spring Boot patterns | |-- springboot-security/ # Spring Boot security | |-- springboot-tdd/ # Spring Boot TDD diff --git a/README.zh-CN.md b/README.zh-CN.md index f86c3d6ce..537bab297 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -200,7 +200,7 @@ Copy-Item -Recurse rules/typescript "$HOME/.claude/rules/" /plugin list ecc@ecc ``` -**完成!** 你现在可以使用 71 个代理、314 个技能和 98 个命令。 +**完成!** 你现在可以使用 71 个代理、315 个技能和 98 个命令。 ### multi-* 命令需要额外配置 diff --git a/SOUL.md b/SOUL.md index d2b5a4607..55b9435e1 100644 --- a/SOUL.md +++ b/SOUL.md @@ -1,7 +1,7 @@ # Soul ## Core Identity -ECC is a production-ready AI coding plugin with 71 specialized agents, 314 skills, 98 commands, and automated hook workflows for software development. +ECC is a production-ready AI coding plugin with 71 specialized agents, 315 skills, 98 commands, and automated hook workflows for software development. ## Core Principles 1. **Agent-First** — route work to the right specialist as early as possible. diff --git a/agent.yaml b/agent.yaml index f54567a99..07b694c2f 100644 --- a/agent.yaml +++ b/agent.yaml @@ -138,6 +138,7 @@ skills: - quarkus-tdd - quarkus-verification - rails-patterns + - rails-security - ralphinho-rfc-pipeline - react-patterns - react-performance diff --git a/config/project-stack-mappings.json b/config/project-stack-mappings.json index 8b37740bc..85ff18982 100644 --- a/config/project-stack-mappings.json +++ b/config/project-stack-mappings.json @@ -360,6 +360,7 @@ "rules": ["common"], "skills": [ "rails-patterns", + "rails-security", "tdd-workflow", "verification-loop" ], diff --git a/docs/tr/AGENTS.md b/docs/tr/AGENTS.md index 9b06149df..c5e1fabf4 100644 --- a/docs/tr/AGENTS.md +++ b/docs/tr/AGENTS.md @@ -1,6 +1,6 @@ # ECC — Agent Talimatları -Bu, yazılım geliştirme için 71 özel agent, 314 skill, 98 command ve otomatik hook iş akışları sağlayan **üretime hazır bir AI kodlama eklentisidir**. +Bu, yazılım geliştirme için 71 özel agent, 315 skill, 98 command ve otomatik hook iş akışları sağlayan **üretime hazır bir AI kodlama eklentisidir**. **Sürüm:** 2.2.3 @@ -142,7 +142,7 @@ Başarısızlık sorunlarını giderin: test izolasyonunu kontrol edin → mockl ``` agents/ — 71 özel subagent -skills/ — 314 iş akışı skillleri ve alan bilgisi +skills/ — 315 iş akışı skillleri ve alan bilgisi commands/ — 98 slash command hooks/ — Tetikleyici tabanlı otomasyonlar rules/ — Her zaman uyulması gereken kurallar (ortak + dile özel) diff --git a/docs/zh-CN/AGENTS.md b/docs/zh-CN/AGENTS.md index 6f39f262e..3db7d3463 100644 --- a/docs/zh-CN/AGENTS.md +++ b/docs/zh-CN/AGENTS.md @@ -1,6 +1,6 @@ # ECC — 智能体指令 -这是一个**生产就绪的 AI 编码插件**,提供 71 个专业代理、314 项技能、98 条命令以及自动化钩子工作流,用于软件开发。 +这是一个**生产就绪的 AI 编码插件**,提供 71 个专业代理、315 项技能、98 条命令以及自动化钩子工作流,用于软件开发。 **版本:** 2.2.3 @@ -147,7 +147,7 @@ ``` agents/ — 71 个专业子代理 -skills/ — 314 个工作流技能和领域知识 +skills/ — 315 个工作流技能和领域知识 commands/ — 98 个斜杠命令 hooks/ — 基于触发的自动化 rules/ — 始终遵循的指导方针(通用 + 每种语言) diff --git a/docs/zh-CN/README.md b/docs/zh-CN/README.md index d652dbacc..7e3361dc4 100644 --- a/docs/zh-CN/README.md +++ b/docs/zh-CN/README.md @@ -264,7 +264,7 @@ Copy-Item -Recurse rules/typescript "$HOME/.claude/rules/" /plugin list ecc@ecc ``` -**搞定!** 你现在可以使用 71 个智能体、314 项技能和 98 个命令了。 +**搞定!** 你现在可以使用 71 个智能体、315 项技能和 98 个命令了。 *** @@ -1178,7 +1178,7 @@ opencode |---------|---------------|----------|--------| | 智能体 | PASS: 71 个 | PASS: 12 个 | **Claude Code 领先** | | 命令 | PASS: 98 个 | PASS: 35 个 | **Claude Code 领先** | -| 技能 | PASS: 314 项 | PASS: 37 项 | **Claude Code 领先** | +| 技能 | PASS: 315 项 | PASS: 37 项 | **Claude Code 领先** | | 钩子 | PASS: 8 种事件类型 | PASS: 11 种事件 | **OpenCode 更多!** | | 规则 | PASS: 29 条 | PASS: 13 条指令 | **Claude Code 领先** | | MCP 服务器 | PASS: 14 个 | PASS: 完整 | **完全对等** | @@ -1286,7 +1286,7 @@ ECC 是**第一个最大化利用每个主要 AI 编码工具的插件**。以 |---------|-----------------------|------------|-----------|----------| | **智能体** | 71 | 共享 (AGENTS.md) | 共享 (AGENTS.md) | 12 | | **命令** | 98 | 共享 | 基于指令 | 35 | -| **技能** | 314 | 共享 | 10 (原生格式) | 37 | +| **技能** | 315 | 共享 | 10 (原生格式) | 37 | | **钩子事件** | 8 种类型 | 15 种类型 | SessionStart(1 种类型) | 11 种类型 | | **钩子脚本** | 20+ 个脚本 | 16 个脚本 (DRY 适配器) | 1 个 SessionStart 引导脚本 | 插件钩子 | | **规则** | 34 (通用 + 语言) | 34 (YAML 前页) | 基于指令 | 13 条指令 | diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 48081c3fb..14b2a3797 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -1,6 +1,6 @@ { "coverage": { - "skills": 314, + "skills": 315, "withTriggers": 34 }, "generatedAt": "2026-10-30T00:01:34.569Z", @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "6f213dc845937b4093bc018d041b25b538d88d78451b9d799ad614989b360ee4", + "registryDigest": "dbd96f7a907526ec7ef7d5438644aed708e72021c4428d3a0df3211089f9bb9f", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/manifests/install-modules.json b/manifests/install-modules.json index 5877dc565..45a7c543b 100644 --- a/manifests/install-modules.json +++ b/manifests/install-modules.json @@ -230,6 +230,7 @@ "skills/quarkus-tdd", "skills/quarkus-verification", "skills/rails-patterns", + "skills/rails-security", "skills/react-patterns", "skills/react-performance", "skills/react-testing", diff --git a/package.json b/package.json index f3ab81529..5ad35e348 100644 --- a/package.json +++ b/package.json @@ -343,6 +343,7 @@ "skills/quarkus-tdd/", "skills/quarkus-verification/", "skills/rails-patterns/", + "skills/rails-security/", "skills/ralphinho-rfc-pipeline/", "skills/react-patterns/", "skills/react-performance/", diff --git a/rules/ruby/security.md b/rules/ruby/security.md index 4821c2c07..32962d0d1 100644 --- a/rules/ruby/security.md +++ b/rules/ruby/security.md @@ -48,4 +48,6 @@ bundle exec brakeman --no-progress ## Reference +See skill: `rails-security` for Rails-specific security implementation patterns. + See skill: `security-review` for secure-by-default review patterns. diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md new file mode 100644 index 000000000..50a6dd7ca --- /dev/null +++ b/skills/rails-security/SKILL.md @@ -0,0 +1,449 @@ +--- +name: rails-security +description: Ruby on Rails security practices for Rails 7.1+ and 8.x apps. Covers production configuration, authentication, authorization, strong parameters, SQL injection, XSS and output escaping, CSRF, file uploads, API security, credentials, untrusted boundaries, and dependency scanning. Use when reviewing or writing Rails authentication, authorization, input handling, uploads, or deployment configuration. +origin: community +--- + +# Rails Security + +Security practices for Ruby on Rails applications (Rails 7.1+ and 8.x). Rails is secure by +default in most places; the vulnerabilities that reach production usually come from opting +out of a default rather than failing to add protection. This skill is the "how." For the +decisions about which control to reach for, see the Ruby security rules — +`rules/ruby/security.md` in this repository, installed as `rules/ecc/ruby/security.md`. + +## When to Activate + +- Writing or reviewing authentication, sessions, or account recovery +- Adding authorization checks to controllers or views +- Handling user input, file uploads, or webhook payloads +- Configuring a Rails app for production +- Reviewing a PR that touches `config/`, `app/controllers/`, or `Gemfile` +- Any use of `html_safe`, `raw`, `Arel.sql`, or raw SQL strings + +## Production Configuration + +```ruby +# config/environments/production.rb +Rails.application.configure do + config.force_ssl = true + config.assume_ssl = true # behind a proxy that terminates TLS + + # Reject requests with unexpected Host headers. + config.hosts << "example.com" + config.hosts << /.*\.example\.com/ + + config.action_dispatch.cookies_same_site_protection = :lax + config.log_level = :info +end +``` + +Filter sensitive values out of logs: + +```ruby +# config/initializers/filter_parameter_logging.rb +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn cvv card_number +] +``` + +## Authentication + +Rails 8 ships an authentication generator that produces session-based auth with password +reset and metadata tracking: + +```bash +bin/rails generate authentication +``` + +Use Devise when you need OAuth, MFA, confirmable, lockable, or multi-model auth. For +hand-rolled auth, `has_secure_password` handles bcrypt hashing: + +```ruby +class User < ApplicationRecord + has_secure_password + + validates :email, presence: true, uniqueness: { case_sensitive: false } + validates :password, length: { minimum: 12 }, allow_nil: true +end +``` + +`authenticate_by` looks up and verifies in one call, so a missing user and a wrong password +take the same time: + +```ruby +# Bad: the timing difference reveals whether the email exists +user = User.find_by(email: params[:email]) +if user&.authenticate(params[:password]) + +# Good +user = User.authenticate_by(email: params[:email], password: params[:password]) +``` + +Rotate the session on sign-in and on any privilege change: + +```ruby +class SessionsController < ApplicationController + def create + user = User.authenticate_by(email: params[:email], password: params[:password]) + return render :new, status: :unprocessable_entity unless user + + reset_session + session[:user_id] = user.id + redirect_to root_path + end + + def destroy + reset_session + redirect_to root_path + end +end +``` + +### Account recovery + +Password reset tokens must expire, be single-use, and not reveal whether an account exists. +Signed tokens generated by the model give you both: + +```ruby +class User < ApplicationRecord + generates_token_for :password_reset, expires_in: 15.minutes do + password_salt&.last(10) # invalidates the token once the password changes + end +end + +user = User.find_by_token_for(:password_reset, params[:token]) +``` + +Render the same response whether or not the address matched. + +## Authorization + +Authentication is not authorization. Every action that touches a record must check that the +current user may act on it. + +```ruby +# Bad: any signed-in user can load any invoice +@invoice = Invoice.find(params[:id]) + +# Good: scope through the owner +@invoice = current_user.invoices.find(params[:id]) +``` + +For anything past ownership, use a policy object (Pundit, Action Policy, or CanCanCan): + +```ruby +class InvoicePolicy < ApplicationPolicy + def update? + user.admin? || record.user_id == user.id + end +end + +class InvoicesController < ApplicationController + def update + @invoice = Invoice.find(params[:id]) + authorize @invoice + # ... + end +end +``` + +Fail closed — verify that authorization ran rather than trusting each action to remember: + +```ruby +class ApplicationController < ActionController::Base + include Pundit::Authorization + + after_action :verify_authorized, except: :index + after_action :verify_policy_scoped, only: :index +end +``` + +## Strong Parameters and Mass Assignment + +Never pass raw `params` to a model. Permit an explicit list: + +```ruby +# Bad: a crafted request can set admin +User.new(params[:user]) + +# Good +def user_params + params.require(:user).permit(:email, :name) +end +``` + +Rails 8 adds `expect`, which raises on a malformed structure instead of returning an empty +hash: + +```ruby +def user_params + params.expect(user: [:email, :name]) +end +``` + +Attributes such as `admin`, `role`, `user_id`, and `account_id` should never appear in a +permit list driven by request data. Assign them explicitly from the session or a checked +policy. + +## SQL Injection + +Active Record parameterizes by default. Injection appears when a string is built by hand: + +```ruby +# Bad +User.where("email = '#{params[:email]}'") +Order.order("#{params[:sort]} #{params[:dir]}") + +# Good +User.where(email: params[:email]) +User.where("email = ?", params[:email]) +``` + +`order`, `pluck`, `group`, and `select` accept raw SQL and are not sanitized. Allowlist the +input rather than escaping it: + +```ruby +SORTABLE = { "created_at" => "created_at", "total" => "total" }.freeze +DIRECTIONS = { "asc" => "ASC", "desc" => "DESC" }.freeze + +column = SORTABLE.fetch(params[:sort], "created_at") +direction = DIRECTIONS.fetch(params[:dir], "DESC") +Order.order(Arel.sql("#{column} #{direction}")) +``` + +`LIKE` needs its own escaping, since `%` and `_` are wildcards: + +```ruby +term = User.sanitize_sql_like(params[:q]) +User.where("name LIKE ?", "%#{term}%") +``` + +## XSS and Output Escaping + +ERB escapes interpolated values by default. Every bypass is security-sensitive: + +```erb +<%# Bad: renders attacker-controlled markup %> +<%= @comment.body.html_safe %> +<%= raw @comment.body %> + +<%# Good: escaped %> +<%= @comment.body %> + +<%# Good: allowlisted markup when the field is genuinely rich text %> +<%= sanitize @comment.body, tags: %w[p br strong em a], attributes: %w[href] %> +``` + +`html_safe` does not sanitize — it marks a string as already safe and skips escaping. Only +call it on strings you constructed. + +Interpolating into JavaScript needs the matching escape, not the HTML one: + +```erb + +``` + +`link_to`'s href accepts `javascript:` URLs, so validate user-supplied links: + +```ruby +uri = URI.parse(url) rescue nil +safe = uri.is_a?(URI::HTTP) # URI::HTTPS subclasses URI::HTTP +``` + +Set a Content Security Policy: + +```ruby +# config/initializers/content_security_policy.rb +Rails.application.configure do + config.content_security_policy do |policy| + policy.default_src :self + policy.script_src :self + policy.object_src :none + policy.frame_ancestors :none + end +end +``` + +## CSRF + +Rails enables CSRF protection for new apps. Keep it on, and do not exempt actions to make a +client work: + +```ruby +# Bad: disables protection for every action in the controller +skip_before_action :verify_authenticity_token +``` + +If an endpoint genuinely cannot carry the token — a third-party webhook, say — authenticate +it another way (signature verification) and scope the exemption to that action alone. + +API-only controllers inheriting from `ActionController::API` have no cookie session, so CSRF +does not apply; token or session-cookie APIs still need it. + +## File Uploads + +The `content_type` a client sends is attacker-controlled. Validate against what the file +actually contains, and constrain size: + +```ruby +class Document < ApplicationRecord + has_one_attached :file + + ALLOWED = %w[application/pdf image/png image/jpeg].freeze + MAX_BYTES = 10.megabytes + + validate :acceptable_file + + private + + def acceptable_file + return unless file.attached? + + errors.add(:file, "is too large") if file.blob.byte_size > MAX_BYTES + + # identify sets content_type from the file's own bytes, not the client's header. + file.blob.identify unless file.blob.identified? + errors.add(:file, "type not allowed") unless ALLOWED.include?(file.blob.content_type) + end +end +``` + +Never interpolate a user-supplied path into `send_file`: + +```ruby +# Bad: path traversal +send_file Rails.root.join("storage", params[:name]) +``` + +## API Security + +Rate-limit authentication and other abusable endpoints. Action Controller ships +`rate_limit` from Rails 7.2; use `rack-attack` on 7.1 or for app-wide throttling: + +```ruby +class SessionsController < ApplicationController + rate_limit to: 10, within: 3.minutes, only: :create +end +``` + +Verify webhook signatures with a constant-time comparison: + +```ruby +class WebhooksController < ApplicationController + skip_before_action :verify_authenticity_token, only: :create + + def create + expected = OpenSSL::HMAC.hexdigest("SHA256", ENV.fetch("WEBHOOK_SECRET"), request.raw_post) + given = request.headers["X-Signature"].to_s + + unless ActiveSupport::SecurityUtils.secure_compare(expected, given) + return head :unauthorized + end + + ProcessWebhookJob.perform_later(request.raw_post) + head :ok + end +end +``` + +Keep CORS narrow — never reflect an arbitrary origin alongside credentials: + +```ruby +# Bad +origins "*" + +# Good +origins "https://app.example.com" +``` + +Serialize responses explicitly so new columns do not leak: + +```ruby +# Bad: ships every column, including ones added later +render json: @user + +# Good +render json: @user.as_json(only: %i[id name created_at]) +``` + +## Secrets and Credentials + +Secrets belong in Rails credentials, environment variables, or a secret manager: + +```bash +bin/rails credentials:edit --environment production +``` + +`config/credentials/production.key` must stay out of version control. Read secrets through +`Rails.application.credentials` or `ENV.fetch` — `ENV[...]` returns `nil` and fails silently +when a variable is missing: + +```ruby +# Bad +ENV["STRIPE_SECRET"] + +# Good +Rails.application.credentials.dig(:stripe, :secret) +ENV.fetch("STRIPE_SECRET") +``` + +If a key is ever committed, rotate it. Removing the commit does not un-expose it. + +## Untrusted Boundaries + +Controller params are not the only entry point. Job arguments, webhook payloads, Action +Cable messages, and Turbo Stream targets all carry outside data: + +- Pass record IDs to jobs and re-scope inside `perform`; a queued job runs without the + original request's session. +- Authorize in `ApplicationCable::Connection` and in each channel's `subscribed`. +- Never build a Turbo Stream target from user input. + +```ruby +class ExportJob < ApplicationJob + def perform(user_id, invoice_id) + user = User.find(user_id) + invoice = user.invoices.find(invoice_id) # scoped, not Invoice.find + # ... + end +end +``` + +## Dependency Scanning + +Run these when the lockfile changes, and in CI: + +```bash +bundle exec bundle-audit check --update +bundle exec brakeman --no-progress +``` + +Brakeman flags the patterns above statically. Treat new warnings as blocking, and record +deliberate exceptions in `config/brakeman.ignore` with a reason rather than lowering the +confidence threshold. + +## Verification Checklist + +- [ ] `force_ssl` and `config.hosts` set in production +- [ ] Sensitive parameters filtered from logs +- [ ] Sessions rotated on sign-in and privilege change +- [ ] Every record lookup scoped to the current user or checked by a policy +- [ ] No permit list contains a role, ownership, or account column +- [ ] No raw SQL string interpolation; `order` and `pluck` inputs allowlisted +- [ ] Every `html_safe` and `raw` reviewed +- [ ] CSRF exemptions scoped to specific actions with another auth mechanism +- [ ] Uploads validated by detected type and size +- [ ] Auth endpoints rate-limited; webhook signatures compared in constant time +- [ ] No secrets in version control; master key excluded +- [ ] `bundle-audit` and `brakeman` clean + +## Related Skills + +- `rails-patterns` — the architectural patterns these controls sit inside +- `security-review` — secure-by-default review patterns across languages +- Ruby security rules (`rules/ruby/security.md`, installed as `rules/ecc/ruby/security.md`) + — the decisions and when-to-use guidance this skill implements From e2aee760ff296848d62d79721896bca7180f77f3 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 12:32:57 -0500 Subject: [PATCH 02/19] docs(rails-security): restrict assume_ssl to an HTTPS-enforcing proxy --- skills/rails-security/SKILL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 50a6dd7ca..5ffc89247 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -27,6 +27,7 @@ decisions about which control to reach for, see the Ruby security rules — # config/environments/production.rb Rails.application.configure do config.force_ssl = true + # Only use when all requests pass through a proxy that rejects or redirects HTTP. config.assume_ssl = true # behind a proxy that terminates TLS # Reject requests with unexpected Host headers. From ea91f1d109dc733a99e450084814f0f9e20e4cb0 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 12:35:36 -0500 Subject: [PATCH 03/19] fix(rails-security): register the skill in the security install module - laravel-security, django-security, and springboot-security all live in the security module; rails-security was registered under framework-language - Installs selecting the security profile or capability:security received the other framework security skills but not the Rails guidance --- manifests/install-modules.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install-modules.json b/manifests/install-modules.json index 45a7c543b..15f0464d6 100644 --- a/manifests/install-modules.json +++ b/manifests/install-modules.json @@ -230,7 +230,6 @@ "skills/quarkus-tdd", "skills/quarkus-verification", "skills/rails-patterns", - "skills/rails-security", "skills/react-patterns", "skills/react-performance", "skills/react-testing", @@ -546,6 +545,7 @@ "skills/nodejs-keccak256", "skills/perl-security", "skills/quarkus-security", + "skills/rails-security", "skills/security-review", "skills/security-scan", "skills/security-bounty-hunter", From cf9488ddf1162d509c08a32a409eb283afe39a7b Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 12:39:21 -0500 Subject: [PATCH 04/19] fix(rails-security): dedupe webhook deliveries against replay - Signature verification proves authenticity, not freshness; an identical signed delivery queued another job, repeating any non-idempotent effect - Records the provider's delivery id behind a unique index and returns early once processed, and notes that perform must be idempotent for retries --- skills/rails-security/SKILL.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 5ffc89247..ac215ae5a 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -345,12 +345,27 @@ class WebhooksController < ApplicationController return head :unauthorized end - ProcessWebhookJob.perform_later(request.raw_post) + # A valid signature proves authenticity, not freshness. Dedupe on the + # provider's delivery id so a replayed delivery does not repeat the work. + delivery = WebhookDelivery.create_or_find_by!( + provider: "billing", + delivery_id: request.headers.fetch("X-Delivery-Id") + ) + return head :ok if delivery.processed_at? + + ProcessWebhookJob.perform_later(delivery.id, request.raw_post) head :ok end end ``` +```ruby +add_index :webhook_deliveries, %i[provider delivery_id], unique: true +``` + +The job marks `processed_at` when it finishes. Jobs retry, so `perform` must be +idempotent for the same reason. + Keep CORS narrow — never reflect an arbitrary origin alongside credentials: ```ruby From 4b8da913beea1f348f76cef414b91754efa92e23 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 12:44:52 -0500 Subject: [PATCH 05/19] fix(rails-security): cover extension and storage destination in upload guidance - rules/ruby/security.md calls for content type, extension, size, and storage destination; the example and checklist covered only detected type and size - Adds an extension allowlist, a private-service attachment with signed URLs, and updates the verification checklist to match --- skills/rails-security/SKILL.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index ac215ae5a..215517f2d 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -287,14 +287,15 @@ does not apply; token or session-cookie APIs still need it. ## File Uploads -The `content_type` a client sends is attacker-controlled. Validate against what the file -actually contains, and constrain size: +The `content_type` a client sends is attacker-controlled. Validate the detected type, +the extension, and the size, and choose the storage destination deliberately: ```ruby class Document < ApplicationRecord has_one_attached :file ALLOWED = %w[application/pdf image/png image/jpeg].freeze + ALLOWED_EXTENSIONS = %w[.pdf .png .jpg .jpeg].freeze MAX_BYTES = 10.megabytes validate :acceptable_file @@ -309,10 +310,20 @@ class Document < ApplicationRecord # identify sets content_type from the file's own bytes, not the client's header. file.blob.identify unless file.blob.identified? errors.add(:file, "type not allowed") unless ALLOWED.include?(file.blob.content_type) + + extension = File.extname(file.blob.filename.to_s).downcase + errors.add(:file, "extension not allowed") unless ALLOWED_EXTENSIONS.include?(extension) end end ``` +Attach to a private service and serve through a signed, expiring URL. A public bucket +makes every upload world-readable regardless of the checks above. + +```ruby +has_one_attached :file, service: :private_documents +``` + Never interpolate a user-supplied path into `send_file`: ```ruby @@ -452,7 +463,7 @@ confidence threshold. - [ ] No raw SQL string interpolation; `order` and `pluck` inputs allowlisted - [ ] Every `html_safe` and `raw` reviewed - [ ] CSRF exemptions scoped to specific actions with another auth mechanism -- [ ] Uploads validated by detected type and size +- [ ] Uploads validated by detected type, extension, and size, and stored on a private service - [ ] Auth endpoints rate-limited; webhook signatures compared in constant time - [ ] No secrets in version control; master key excluded - [ ] `bundle-audit` and `brakeman` clean From 36dedf4646168df1aef1ee62bf3b571ba1f3f346 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:00:36 -0500 Subject: [PATCH 06/19] fix(rails-security): take the webhook replay key from the signed payload - The HMAC covers the request body, not the headers, so deduplicating on X-Delivery-Id let a replay vary that header and queue the work again - Uses the event id parsed from the signed body as the dedupe key --- skills/rails-security/SKILL.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 215517f2d..5cb4beab7 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -356,12 +356,8 @@ class WebhooksController < ApplicationController return head :unauthorized end - # A valid signature proves authenticity, not freshness. Dedupe on the - # provider's delivery id so a replayed delivery does not repeat the work. - delivery = WebhookDelivery.create_or_find_by!( - provider: "billing", - delivery_id: request.headers.fetch("X-Delivery-Id") - ) + event_id = JSON.parse(request.raw_post).fetch("id") + delivery = WebhookDelivery.create_or_find_by!(provider: "billing", delivery_id: event_id) return head :ok if delivery.processed_at? ProcessWebhookJob.perform_later(delivery.id, request.raw_post) From b2cb04176484924311e1c65541093e674ba6daea Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:03:26 -0500 Subject: [PATCH 07/19] fix(rails-security): name the stable Active Storage paths in serving guidance - rails_blob_url and url_for(attachment) are permanent references that redirect to a short-lived service URL, so the file stays reachable past the expiry - Serves user-scoped files from a controller that authorizes each request before redirecting to a short-lived private-service URL --- skills/rails-security/SKILL.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 5cb4beab7..060b103a8 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -317,13 +317,26 @@ class Document < ApplicationRecord end ``` -Attach to a private service and serve through a signed, expiring URL. A public bucket -makes every upload world-readable regardless of the checks above. +Attach to a private service — a public bucket makes every upload world-readable regardless +of the checks above. ```ruby has_one_attached :file, service: :private_documents ``` +`rails_blob_url` and `url_for(attachment)` are stable references that never expire; they +redirect to a short-lived service URL, so anyone holding one keeps access. Serve +user-scoped files from your own controller that authorizes each request: + +```ruby +class DocumentFilesController < ApplicationController + def show + document = current_user.documents.find(params[:id]) + redirect_to document.file.blob.url(expires_in: 5.minutes), allow_other_host: true + end +end +``` + Never interpolate a user-supplied path into `send_file`: ```ruby From 06d6015ac6ede7e5942d82f3663596e24d90544a Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:15:30 -0500 Subject: [PATCH 08/19] docs(rails-security): note that the webhook dedupe key needs a signed payload id --- skills/rails-security/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 060b103a8..fbc25b1d3 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -384,7 +384,7 @@ add_index :webhook_deliveries, %i[provider delivery_id], unique: true ``` The job marks `processed_at` when it finishes. Jobs retry, so `perform` must be -idempotent for the same reason. +idempotent for the same reason. Requires a stable id in the signed body. Keep CORS narrow — never reflect an arbitrary origin alongside credentials: From 66a434cbc6bcfa415b1c9d885aec8e86f8dd8868 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:35:46 -0500 Subject: [PATCH 09/19] docs(rails-security): require draw_routes = false alongside the authorized controller --- skills/rails-security/SKILL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index fbc25b1d3..ccd13325e 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -326,7 +326,8 @@ has_one_attached :file, service: :private_documents `rails_blob_url` and `url_for(attachment)` are stable references that never expire; they redirect to a short-lived service URL, so anyone holding one keeps access. Serve -user-scoped files from your own controller that authorizes each request: +user-scoped files from your own controller that authorizes each request, with +`config.active_storage.draw_routes = false`: ```ruby class DocumentFilesController < ApplicationController From bc2dc43848d082f009d50fb15411e3308f30ae3d Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:44:28 -0500 Subject: [PATCH 10/19] docs(rails-security): add the route for the authorized file controller --- skills/rails-security/SKILL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index ccd13325e..419e4df89 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -330,6 +330,8 @@ user-scoped files from your own controller that authorizes each request, with `config.active_storage.draw_routes = false`: ```ruby +get "documents/:id/file", to: "document_files#show", as: :document_file + class DocumentFilesController < ApplicationController def show document = current_user.documents.find(params[:id]) From 577bb2bc3a7a1c9d7b4347a6bb1c97d472418533 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 13:49:54 -0500 Subject: [PATCH 11/19] docs(rails-security): note draw_routes removes every default Active Storage route --- skills/rails-security/SKILL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 419e4df89..627e922d0 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -327,7 +327,8 @@ has_one_attached :file, service: :private_documents `rails_blob_url` and `url_for(attachment)` are stable references that never expire; they redirect to a short-lived service URL, so anyone holding one keeps access. Serve user-scoped files from your own controller that authorizes each request, with -`config.active_storage.draw_routes = false`: +`config.active_storage.draw_routes = false`, which removes every default Active Storage +route; apps using direct uploads need a replacement route: ```ruby get "documents/:id/file", to: "document_files#show", as: :document_file From 4857f82ff0569394b4f310b3262fead1852c0baf Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 14:43:30 -0500 Subject: [PATCH 12/19] docs(rails-security): add the direct-upload route to the Active Storage example --- skills/rails-security/SKILL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 627e922d0..3ba4f3c73 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -332,6 +332,8 @@ route; apps using direct uploads need a replacement route: ```ruby get "documents/:id/file", to: "document_files#show", as: :document_file +# Re-draw the direct-upload endpoint behind your own authentication. +post "uploads", to: "active_storage/direct_uploads#create", as: :rails_direct_uploads class DocumentFilesController < ApplicationController def show From 0edcf37ff56d5ae6489a03dd02487cd219891d64 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 14:55:00 -0500 Subject: [PATCH 13/19] docs(rails-security): guard the direct-upload route in the example --- skills/rails-security/SKILL.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 3ba4f3c73..690a7b4f0 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -332,8 +332,9 @@ route; apps using direct uploads need a replacement route: ```ruby get "documents/:id/file", to: "document_files#show", as: :document_file -# Re-draw the direct-upload endpoint behind your own authentication. -post "uploads", to: "active_storage/direct_uploads#create", as: :rails_direct_uploads +constraints ->(req) { req.session[:user_id].present? } do + post "uploads", to: "active_storage/direct_uploads#create", as: :rails_direct_uploads +end class DocumentFilesController < ApplicationController def show From adfffc0ca8688661a96008b8c96809fcc6617bae Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 4 Oct 2026 15:14:07 -0500 Subject: [PATCH 14/19] docs(rails-security): explain the direct-upload guard and name its auth --- skills/rails-security/SKILL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index 690a7b4f0..e512de516 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -332,6 +332,8 @@ route; apps using direct uploads need a replacement route: ```ruby get "documents/:id/file", to: "document_files#show", as: :document_file +# Rails' direct-upload endpoint has no authentication of its own. This example uses a +# hand-rolled session sign-in; see Devise or the Rails 8 generator for their equivalents. constraints ->(req) { req.session[:user_id].present? } do post "uploads", to: "active_storage/direct_uploads#create", as: :rails_direct_uploads end From cd322b5bea5129a7da84357a52bde134762c9991 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 8 Nov 2026 14:00:01 -0600 Subject: [PATCH 15/19] fix(rails-security): verify upload bytes where they are actually stored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - blob.content_type is derived via Marcel::MimeType.for, which keeps the client's declared type when the bytes match no known magic; opaque bytes declared image/png are stored as image/png with identified? true - Active Storage uploads on save, so a model validation runs before the bytes exist; the example now uploads explicitly, verifies the stored bytes, and attaches only what passed - Covers both entry points — create_and_upload! for form uploads, find_signed! for direct uploads — and fails closed when the object is missing or pending - Regenerates the skill-triggers registry digest, which covers skill content --- manifests/context-packs/skill-triggers@1.json | 2 +- skills/rails-security/SKILL.md | 54 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 14b2a3797..53d6b2907 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "dbd96f7a907526ec7ef7d5438644aed708e72021c4428d3a0df3211089f9bb9f", + "registryDigest": "693ffc2f5995992658804b3bd0437f9d4d3d015b7bfe138759800612ac976b8a", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index e512de516..cca3912a3 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -287,36 +287,54 @@ does not apply; token or session-cookie APIs still need it. ## File Uploads -The `content_type` a client sends is attacker-controlled. Validate the detected type, -the extension, and the size, and choose the storage destination deliberately: +The `content_type` a client sends is attacker-controlled, and `blob.content_type` is not a +substitute for it. Active Storage derives that column through `Marcel::MimeType.for`, which +treats the client's declared type as one candidate alongside magic-byte detection and keeps +it when the bytes match nothing known — so opaque bytes declared `image/png` are stored as +`image/png` with `identified?` true. Inspect the stored bytes yourself: ```ruby -class Document < ApplicationRecord - has_one_attached :file +module Uploads + Rejected = Class.new(StandardError) - ALLOWED = %w[application/pdf image/png image/jpeg].freeze + MAGIC = { + "application/pdf" => "%PDF-".b, + "image/png" => "\x89PNG\r\n\x1a\n".b, + "image/jpeg" => "\xFF\xD8\xFF".b + }.freeze ALLOWED_EXTENSIONS = %w[.pdf .png .jpg .jpeg].freeze MAX_BYTES = 10.megabytes - validate :acceptable_file + def self.verified!(blob) + # Fail closed: an object that is missing or still pending cannot be inspected. + raise Rejected, "could not be verified" unless blob.service.exist?(blob.key) + raise Rejected, "is too large" if blob.byte_size > MAX_BYTES - private + extension = File.extname(blob.filename.to_s).downcase + raise Rejected, "extension not allowed" unless ALLOWED_EXTENSIONS.include?(extension) - def acceptable_file - return unless file.attached? + head = blob.service.download_chunk(blob.key, 0...8) + raise Rejected, "type not allowed" unless MAGIC.any? { |_mime, magic| head.start_with?(magic) } - errors.add(:file, "is too large") if file.blob.byte_size > MAX_BYTES - - # identify sets content_type from the file's own bytes, not the client's header. - file.blob.identify unless file.blob.identified? - errors.add(:file, "type not allowed") unless ALLOWED.include?(file.blob.content_type) - - extension = File.extname(file.blob.filename.to_s).downcase - errors.add(:file, "extension not allowed") unless ALLOWED_EXTENSIONS.include?(extension) + blob end end ``` +The check reads from storage, so it has to run where the bytes already exist. A form upload +is not yet in storage when model validations run — Active Storage uploads on save — so +upload explicitly first, and attach only what passed: + +```ruby +# Form upload +blob = ActiveStorage::Blob.create_and_upload!(io: params[:file], filename: params[:file].original_filename) +document.file.attach(Uploads.verified!(blob)) + +# Direct upload: the client already stored the object, so verify before the record +# points at it. +document.file.attach(Uploads.verified!(ActiveStorage::Blob.find_signed!(params[:file]))) +``` + Attach to a private service — a public bucket makes every upload world-readable regardless of the checks above. @@ -481,7 +499,7 @@ confidence threshold. - [ ] No raw SQL string interpolation; `order` and `pluck` inputs allowlisted - [ ] Every `html_safe` and `raw` reviewed - [ ] CSRF exemptions scoped to specific actions with another auth mechanism -- [ ] Uploads validated by detected type, extension, and size, and stored on a private service +- [ ] Uploads validated against stored bytes, not `blob.content_type`, and fail closed when the object is unavailable - [ ] Auth endpoints rate-limited; webhook signatures compared in constant time - [ ] No secrets in version control; master key excluded - [ ] `bundle-audit` and `brakeman` clean From c2335d8e20713630b27a8a504fcc9173c94195a3 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 8 Nov 2026 14:00:01 -0600 Subject: [PATCH 16/19] test(rails-security): add a Rails fixture exercising the upload verifier - Boots a minimal Rails app with a migrated Active Storage schema and a disk service holding real bytes, so the published verifier runs against the actual lifecycle rather than a stand-in - Covers a legitimate PNG, opaque bytes declared image/png (stored as image/png with identified? true), a ZIP declared image/png, a disallowed extension, a pending direct upload, and an object deleted after identification - The verifier module is copied byte-for-byte from the skill so the two cannot drift apart - Locks Rails for both arm64-darwin and x86_64-linux so the fixture resolves the same way locally and on CI --- tests/fixtures/rails-security/Gemfile | 6 + tests/fixtures/rails-security/Gemfile.lock | 205 +++++++++++++++++++++ tests/fixtures/rails-security/uploads.rb | 164 +++++++++++++++++ 3 files changed, 375 insertions(+) create mode 100644 tests/fixtures/rails-security/Gemfile create mode 100644 tests/fixtures/rails-security/Gemfile.lock create mode 100644 tests/fixtures/rails-security/uploads.rb diff --git a/tests/fixtures/rails-security/Gemfile b/tests/fixtures/rails-security/Gemfile new file mode 100644 index 000000000..71ac59362 --- /dev/null +++ b/tests/fixtures/rails-security/Gemfile @@ -0,0 +1,6 @@ +# Dependencies for uploads.rb, which exercises the skills/rails-security upload verifier +# against a real Active Storage lifecycle. 7.1 is the Rails floor the skill advertises. +source "https://rubygems.org" + +gem "rails", ">= 7.1", "< 9.0" +gem "sqlite3" diff --git a/tests/fixtures/rails-security/Gemfile.lock b/tests/fixtures/rails-security/Gemfile.lock new file mode 100644 index 000000000..398d7247a --- /dev/null +++ b/tests/fixtures/rails-security/Gemfile.lock @@ -0,0 +1,205 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (8.0.5.1) + actionpack (= 8.0.5.1) + activesupport (= 8.0.5.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.0.5.1) + actionpack (= 8.0.5.1) + activejob (= 8.0.5.1) + activerecord (= 8.0.5.1) + activestorage (= 8.0.5.1) + activesupport (= 8.0.5.1) + mail (>= 2.8.0) + actionmailer (8.0.5.1) + actionpack (= 8.0.5.1) + actionview (= 8.0.5.1) + activejob (= 8.0.5.1) + activesupport (= 8.0.5.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.5.1) + actionview (= 8.0.5.1) + activesupport (= 8.0.5.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.5.1) + actionpack (= 8.0.5.1) + activerecord (= 8.0.5.1) + activestorage (= 8.0.5.1) + activesupport (= 8.0.5.1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.5.1) + activesupport (= 8.0.5.1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.5.1) + activesupport (= 8.0.5.1) + globalid (>= 0.3.6) + activemodel (8.0.5.1) + activesupport (= 8.0.5.1) + activerecord (8.0.5.1) + activemodel (= 8.0.5.1) + activesupport (= 8.0.5.1) + timeout (>= 0.4.0) + activestorage (8.0.5.1) + actionpack (= 8.0.5.1) + activejob (= 8.0.5.1) + activerecord (= 8.0.5.1) + activesupport (= 8.0.5.1) + marcel (~> 1.0) + activesupport (8.0.5.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + base64 (0.3.0) + benchmark (0.5.0) + bigdecimal (4.1.2) + builder (3.3.0) + concurrent-ruby (1.3.8) + connection_pool (3.0.2) + crass (1.0.7) + date (3.5.1) + drb (2.2.3) + erb (6.0.7) + erubi (1.13.1) + globalid (1.4.0) + activesupport (>= 6.1) + i18n (1.15.2) + concurrent-ruby (~> 1.0) + io-console (0.9.5) + irb (1.19.0) + pp (>= 0.6.0) + prism (>= 1.3.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + logger (1.7.0) + loofah (2.25.2) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.9.1) + logger + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.2.1) + mini_mime (1.1.5) + minitest (6.0.6) + drb (~> 2.0) + prism (~> 1.5) + net-imap (0.6.6) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.4-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.4-x86_64-linux-gnu) + racc (~> 1.4) + pp (0.6.4) + prettyprint + prettyprint (0.2.1) + prism (1.9.0) + racc (1.8.1) + rack (3.2.6) + rack-session (2.1.2) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.3.1) + rack (>= 3) + rails (8.0.5.1) + actioncable (= 8.0.5.1) + actionmailbox (= 8.0.5.1) + actionmailer (= 8.0.5.1) + actionpack (= 8.0.5.1) + actiontext (= 8.0.5.1) + actionview (= 8.0.5.1) + activejob (= 8.0.5.1) + activemodel (= 8.0.5.1) + activerecord (= 8.0.5.1) + activestorage (= 8.0.5.1) + activesupport (= 8.0.5.1) + bundler (>= 1.15.0) + railties (= 8.0.5.1) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.7.1) + loofah (~> 2.25, >= 2.25.2) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.5.1) + actionpack (= 8.0.5.1) + activesupport (= 8.0.5.1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.4.2) + rbs (4.1.3) + logger + prism (>= 1.6.0) + tsort + rdoc (8.1.0) + erb + prism (>= 1.6.0) + rbs (>= 4.0.0) + tsort + reline (0.7.0) + io-console (~> 0.5) + securerandom (0.4.1) + sqlite3 (2.8.0-arm64-darwin) + sqlite3 (2.8.0-x86_64-linux-gnu) + thor (1.5.0) + timeout (0.6.1) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.1.1) + useragent (0.16.11) + websocket-driver (0.8.2) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.8.3) + +PLATFORMS + arm64-darwin + x86_64-linux + +DEPENDENCIES + rails (>= 7.1, < 9.0) + sqlite3 + +BUNDLED WITH + 2.7.2 diff --git a/tests/fixtures/rails-security/uploads.rb b/tests/fixtures/rails-security/uploads.rb new file mode 100644 index 000000000..36b4edfe2 --- /dev/null +++ b/tests/fixtures/rails-security/uploads.rb @@ -0,0 +1,164 @@ +# Exercises the upload verifier published in skills/rails-security/SKILL.md against a real +# Active Storage lifecycle: a migrated database, a disk service holding real bytes, and +# blobs created the way Rails creates them. +# +# Prints one JSON object per case to stdout. tests/skills/rails-security.test.js asserts on +# that output, so the contract is the JSON rather than this script's exit status. + +require "json" +require "tmpdir" +require "fileutils" +require "stringio" +require "digest" +require "rails" +require "active_record/railtie" +require "active_storage/engine" + +ROOT = Dir.mktmpdir("ecc-rails-security-") +at_exit { FileUtils.remove_entry(ROOT, true) } + +FileUtils.mkdir_p(File.join(ROOT, "config")) +File.write(File.join(ROOT, "config", "database.yml"), <<~YAML) + test: + adapter: sqlite3 + database: ":memory:" +YAML + +class FixtureApp < Rails::Application + config.root = ROOT + config.eager_load = false + config.logger = Logger.new(IO::NULL) + config.secret_key_base = "fixture-only-not-a-secret" + config.active_support.to_time_preserves_timezone = :zone + config.active_storage.service = :fixture_disk + config.active_storage.service_configurations = { + "fixture_disk" => { "service" => "Disk", "root" => File.join(ROOT, "storage") } + } +end + +FixtureApp.initialize! + +ActiveRecord::Migration.verbose = false + +ActiveRecord::Schema.define do + create_table :documents + + create_table :active_storage_blobs do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + t.datetime :created_at, null: false + t.index [:key], unique: true + end + + create_table :active_storage_attachments do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false + t.bigint :blob_id, null: false + t.datetime :created_at, null: false + t.index %i[record_type record_id name blob_id], + name: :index_active_storage_attachments_uniqueness, unique: true + end + + create_table :active_storage_variant_records do |t| + t.bigint :blob_id, null: false + t.string :variation_digest, null: false + t.index %i[blob_id variation_digest], + name: :index_active_storage_variant_records_uniqueness, unique: true + end +end + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end + +class Document < ApplicationRecord + has_one_attached :file +end + +# --- The published verifier, copied from the skill -------------------------------------- + +module Uploads + Rejected = Class.new(StandardError) + + MAGIC = { + "application/pdf" => "%PDF-".b, + "image/png" => "\x89PNG\r\n\x1a\n".b, + "image/jpeg" => "\xFF\xD8\xFF".b + }.freeze + ALLOWED_EXTENSIONS = %w[.pdf .png .jpg .jpeg].freeze + MAX_BYTES = 10.megabytes + + def self.verified!(blob) + # Fail closed: an object that is missing or still pending cannot be inspected. + raise Rejected, "could not be verified" unless blob.service.exist?(blob.key) + raise Rejected, "is too large" if blob.byte_size > MAX_BYTES + + extension = File.extname(blob.filename.to_s).downcase + raise Rejected, "extension not allowed" unless ALLOWED_EXTENSIONS.include?(extension) + + head = blob.service.download_chunk(blob.key, 0...8) + raise Rejected, "type not allowed" unless MAGIC.any? { |_mime, magic| head.start_with?(magic) } + + blob + end +end + +# --- Cases ------------------------------------------------------------------------------ + +PNG_BYTES = "\x89PNG\r\n\x1a\n".b + ("\x00".b * 64) +ZIP_BYTES = "PK\x03\x04".b + ("\x00".b * 64) +OPAQUE_BYTES = "\x01\x02\x03\x04".b * 20 + +def upload(bytes, filename, declared) + ActiveStorage::Blob.create_and_upload!( + io: StringIO.new(bytes), filename: filename, content_type: declared + ) +end + +def report(name, blob) + outcome = nil + begin + document = Document.create! + document.file.attach(Uploads.verified!(blob)) + outcome = { case: name, attached: document.reload.file.attached?, rejected: nil } + rescue Uploads::Rejected => error + outcome = { case: name, attached: false, rejected: error.message } + end + puts JSON.generate(outcome.merge( + stored_content_type: blob.content_type, + identified: blob.identified? + )) +end + +# 1. A real PNG passes. +report("legitimate_png", upload(PNG_BYTES, "chart.png", "image/png")) + +# 2. Opaque bytes declared image/png. Marcel matches no magic, keeps the declared type, +# and marks the blob identified — so content_type agrees with the attacker. +report("opaque_declared_png", upload(OPAQUE_BYTES, "payload.png", "image/png")) + +# 3. A ZIP declared image/png. Identification does detect the real type here, which is +# why content_type cannot be the single gate either way. +report("zip_declared_png", upload(ZIP_BYTES, "payload.png", "image/png")) + +# 4. A disallowed extension on otherwise valid bytes. +report("png_bytes_bad_extension", upload(PNG_BYTES, "chart.svg", "image/png")) + +# 5. A direct upload whose object never arrived: the row exists, the bytes do not. +pending = ActiveStorage::Blob.create_before_direct_upload!( + filename: "pending.png", byte_size: PNG_BYTES.bytesize, + checksum: Digest::MD5.base64digest(PNG_BYTES), content_type: "image/png" +) +pending.update!(identified: true) +report("pending_direct_upload", pending) + +# 6. The object is deleted after identification recorded a type. The row still claims +# image/png, so only an explicit existence check catches it. +vanished = upload(PNG_BYTES, "vanished.png", "image/png") +vanished.service.delete(vanished.key) +report("deleted_after_identification", vanished) From 287d4c44bfef248595c4bfdafdcbeee65923d0ab Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 8 Nov 2026 14:00:01 -0600 Subject: [PATCH 17/19] test(rails-security): verify the skill's upload claims and fixture behavior - Asserts the SKILL.md guidance directly: no treating blob.content_type as byte evidence, the declared-type fallback is stated, the unavailable-object path fails closed, and both upload entry points are named - Compares the published Uploads module against the fixture byte-for-byte, so the example and the tested code cannot drift - Runs the Active Storage fixture and asserts all six cases, including that opaque bytes are stored as image/png with identified? true and still rejected - Prefers bundle exec, falls back to a plain interpreter, and skips only the lifecycle cases where ruby with rails is unavailable, so the document assertions still run everywhere --- tests/skills/rails-security.test.js | 175 ++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 tests/skills/rails-security.test.js diff --git a/tests/skills/rails-security.test.js b/tests/skills/rails-security.test.js new file mode 100644 index 000000000..8c3c9554c --- /dev/null +++ b/tests/skills/rails-security.test.js @@ -0,0 +1,175 @@ +'use strict'; + +// Tests for the rails-security skill: the SKILL.md upload guidance must match what Rails +// actually does. Assert the document's claims, then run the real Active Storage fixture so +// the published example and its verified behavior share one source. + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const repoRoot = path.resolve(__dirname, '..', '..'); +const skillPath = path.join(repoRoot, 'skills', 'rails-security', 'SKILL.md'); +const fixturePath = path.join(repoRoot, 'tests', 'fixtures', 'rails-security', 'uploads.rb'); +const skill = fs.readFileSync(skillPath, 'utf8'); + +let passed = 0; +let failed = 0; +let skipped = 0; + +function test(name, fn) { + try { + fn(); + passed += 1; + console.log(` ✓ ${name}`); + } catch (error) { + failed += 1; + console.log(` ✗ ${name}`); + console.log(` ${error.message}`); + } +} + +function skip(name, reason) { + skipped += 1; + console.log(` - ${name} (${reason})`); +} + +console.log('\n=== Rails security skill tests ===\n'); + +// ---- Skill document claims --------------------------------------------- + +test('upload guidance does not treat blob.content_type as byte evidence', () => { + assert.doesNotMatch(skill, /ALLOWED\.include\?\(\s*(file\.)?blob\.content_type\s*\)/); + assert.doesNotMatch(skill, /identify unless .*identified\?/); + assert.match(skill, /download_chunk\(blob\.key, 0\.\.\.8\)/); +}); + +test('upload guidance states the declared-type fallback', () => { + assert.match(skill, /Marcel::MimeType\.for/); + assert.match(skill, /bytes match nothing known/); +}); + +test('upload guidance fails closed on an unavailable object', () => { + assert.match(skill, /blob\.service\.exist\?\(blob\.key\)/); + assert.match(skill, /could not be verified/); +}); + +test('upload guidance names both upload entry points', () => { + assert.match(skill, /ActiveStorage::Blob\.create_and_upload!/); + assert.match(skill, /ActiveStorage::Blob\.find_signed!/); +}); + +test('verification checklist matches the byte-level guidance', () => { + assert.match(skill, /Uploads validated against stored bytes, not `blob\.content_type`/); +}); + +// ---- The fixture carries the published verifier verbatim ---------------- + +function uploadsModule(source) { + const start = source.indexOf('module Uploads'); + const end = source.indexOf('\nend\n', source.indexOf('def self.verified!')); + assert.ok(start > -1 && end > start, 'Uploads module not found'); + return source.slice(start, end + 5).trim(); +} + +test('fixture verifier has not drifted from the published example', () => { + const documented = uploadsModule(skill); + const fixture = uploadsModule(fs.readFileSync(fixturePath, 'utf8')); + assert.strictEqual(fixture, documented, 'fixture drifted from the skill'); +}); + +// ---- Execute the fixture against a real Active Storage lifecycle -------- + +// Prefer `bundle exec` so a bundled Rails is found, and fall back to a plain +// interpreter for developers who already have the gems installed. +const RUNNERS = [ + ['bundle', ['exec', 'ruby']], + ['ruby', []], +]; + +function runFixture() { + const env = { ...process.env, RAILS_ENV: 'test' }; + const probeSource = 'require "rails"; require "active_storage/engine"'; + + for (const [command, prefix] of RUNNERS) { + const probe = spawnSync(command, [...prefix, '-e', probeSource], { + encoding: 'utf8', + cwd: path.dirname(fixturePath), + env, + }); + if (probe.error || probe.status !== 0) continue; + + const result = spawnSync(command, [...prefix, fixturePath], { + encoding: 'utf8', + cwd: path.dirname(fixturePath), + env, + }); + assert.strictEqual(result.status, 0, `fixture failed:\n${result.stderr}`); + return result.stdout + .split('\n') + .filter(line => line.startsWith('{')) + .map(line => JSON.parse(line)); + } + return null; +} + +const cases = runFixture(); + +if (cases === null) { + skip('Active Storage lifecycle cases', 'ruby with rails and activestorage not available'); +} else { + const byName = new Map(cases.map(entry => [entry.case, entry])); + const expectCase = name => { + const entry = byName.get(name); + assert.ok(entry, `fixture did not report the ${name} case`); + return entry; + }; + + test('a legitimate PNG is attached', () => { + const result = expectCase('legitimate_png'); + assert.strictEqual(result.attached, true); + assert.strictEqual(result.rejected, null); + }); + + test('opaque bytes are stored under the declared type and still rejected', () => { + const result = expectCase('opaque_declared_png'); + // The bypass: Rails kept the client's declared type and marked the blob identified. + assert.strictEqual(result.stored_content_type, 'image/png'); + assert.strictEqual(result.identified, true); + assert.strictEqual(result.attached, false); + assert.strictEqual(result.rejected, 'type not allowed'); + }); + + test('a ZIP declared image/png is rejected', () => { + const result = expectCase('zip_declared_png'); + assert.strictEqual(result.attached, false); + assert.strictEqual(result.rejected, 'type not allowed'); + }); + + test('a disallowed extension is rejected on otherwise valid bytes', () => { + const result = expectCase('png_bytes_bad_extension'); + assert.strictEqual(result.attached, false); + assert.strictEqual(result.rejected, 'extension not allowed'); + }); + + test('a pending direct upload fails closed', () => { + const result = expectCase('pending_direct_upload'); + assert.strictEqual(result.attached, false); + assert.strictEqual(result.rejected, 'could not be verified'); + }); + + test('an object deleted after identification fails closed', () => { + const result = expectCase('deleted_after_identification'); + assert.strictEqual(result.stored_content_type, 'image/png'); + assert.strictEqual(result.attached, false); + assert.strictEqual(result.rejected, 'could not be verified'); + }); +} + +console.log(`\nPassed: ${passed}`); +if (skipped > 0) console.log(`Skipped: ${skipped}`); +if (failed > 0) { + console.log(`Failed: ${failed}`); + process.exit(1); +} From 92a2328e910b52431c2e166192b446d345d3ec08 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 8 Nov 2026 16:11:11 -0600 Subject: [PATCH 18/19] fix(rails-security): exempt the session actions from verify_authorized - SessionsController inherits ApplicationController's after_action :verify_authorized but never calls authorize, so sign-in and sign-out raised Pundit::AuthorizationNotPerformedError after running instead of redirecting - Shows the explicit skip_after_action beside the callback that needs it --- manifests/context-packs/skill-triggers@1.json | 2 +- skills/rails-security/SKILL.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index 53d6b2907..8f6b20dc4 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "693ffc2f5995992658804b3bd0437f9d4d3d015b7bfe138759800612ac976b8a", + "registryDigest": "2ccff61a9807b0d0ca0a75ce73149e5f66faa74e24319b97d2068b7ec5071451", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/skills/rails-security/SKILL.md b/skills/rails-security/SKILL.md index cca3912a3..99f206509 100644 --- a/skills/rails-security/SKILL.md +++ b/skills/rails-security/SKILL.md @@ -158,6 +158,11 @@ class ApplicationController < ActionController::Base after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index end + +# Public actions have no record to authorize, so exempt them explicitly. +class SessionsController < ApplicationController + skip_after_action :verify_authorized +end ``` ## Strong Parameters and Mass Assignment From de0c862fb8201035b2ae53e3d5ecd989230065d4 Mon Sep 17 00:00:00 2001 From: Rockwell Windsor Rice Date: Sun, 8 Nov 2026 16:11:11 -0600 Subject: [PATCH 19/19] ci: run the Rails security skill fixture - Without a lane that installs the fixture bundle, runFixture returns null on every runner and the Active Storage cases skip while CI stays green, leaving the published upload example unverified - Adds a single rails-security-fixture job following the python-tests pattern rather than adding Ruby to the test matrix, pinning ruby/setup-ruby by SHA and bundling from the fixture's own directory - ECC_RAILS_FIXTURE_REQUIRED=1 turns the skip into a failure in that lane only, so other environments keep the optional skip --- .github/workflows/ci.yml | 30 +++++++++++++++++++++++++++++ tests/skills/rails-security.test.js | 9 ++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 145a02a77..e3d2c1574 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -406,6 +406,36 @@ jobs: python -m pip install 'openai==2.34.0' python -m pytest tests/test_provider_tools.py tests/test_atlas_provider.py tests/test_astraflow_provider.py tests/test_resolver.py + rails-security-fixture: + name: Rails Security Skill Fixture + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: '22.x' + + # tests/skills/rails-security.test.js asserts its document claims without Ruby and + # skips only the Active Storage cases, so this lane is what executes them. + - name: Setup Ruby + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 + with: + ruby-version: '3.3' + bundler-cache: true + working-directory: tests/fixtures/rails-security + + - name: Run the Rails security skill test + run: node tests/skills/rails-security.test.js + env: + ECC_RAILS_FIXTURE_REQUIRED: '1' + security: name: Security Scan runs-on: ubuntu-latest diff --git a/tests/skills/rails-security.test.js b/tests/skills/rails-security.test.js index 8c3c9554c..65f8a4318 100644 --- a/tests/skills/rails-security.test.js +++ b/tests/skills/rails-security.test.js @@ -117,7 +117,14 @@ function runFixture() { const cases = runFixture(); if (cases === null) { - skip('Active Storage lifecycle cases', 'ruby with rails and activestorage not available'); + // The CI lane sets this so a missing toolchain fails rather than passing silently. + if (process.env.ECC_RAILS_FIXTURE_REQUIRED === '1') { + failed += 1; + console.log(' ✗ Active Storage lifecycle cases'); + console.log(' ECC_RAILS_FIXTURE_REQUIRED=1 but ruby with rails could not run the fixture'); + } else { + skip('Active Storage lifecycle cases', 'ruby with rails and activestorage not available'); + } } else { const byName = new Map(cases.map(entry => [entry.case, entry])); const expectCase = name => {