security

Mitigate Rails security risks in web applications during code reviews and deployment.

Updated Dec 13, 2024
One-click install
npx skills add https://github.com/apdarr/lace --skill security-apdarr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: security
Source: https://github.com/apdarr/lace/tree/main/.github/skills/security
Command: npx skills add https://github.com/apdarr/lace --skill security-apdarr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides structured, actionable guidance for securing Rails applications by addressing common web vulnerabilities such as XSS, SQL injection, CSRF, insecure file uploads, and command injection.

Core Features & Use Cases

  • XSS Prevention: Avoid bypassing Rails defaults by escaping output and sanitizing user-generated content.
  • SQL Injection Prevention: Use parameterized queries, hash conditions, and safe LIKE patterns to prevent data leakage or tampered queries.
  • CSRF Protection: Ensure CSRF tokens are present in forms, headers, and fetch requests; implement CSP and safe request handling.
  • File Upload Security: Validate content types, prefer ActiveStorage, and validate by content bytes; restrict upload sizes and storage.
  • Command Injection Prevention: Prefer safe command execution methods and avoid shell interpolation; validate inputs.

Quick Start

Review the Rails security standards and implement the recommended practices in controllers, views, and models to harden your application.

Frequently Asked Questions about security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQL injection in Rails queries?

Prevent SQL injection in Rails by using parameterized queries, hash conditions, and safe LIKE patterns to stop data leakage and tampered queries. Avoid interpolating user input directly into database query strings.

What is the best way to secure file uploads in Rails?

Secure file uploads in Rails by validating content types and checking content bytes, preferring ActiveStorage, and restricting upload sizes. Validate uploads by content bytes rather than relying solely on file extensions.

How do I stop XSS vulnerabilities in Rails views?

Stop XSS vulnerabilities in Rails by escaping output and sanitizing user-generated content. Avoid bypassing Rails default escaping mechanisms when rendering user input in views to prevent cross-site scripting attacks.

Why does my Rails API fail CSRF protection checks?

Rails API CSRF protection fails when forms, headers, or fetch requests lack valid CSRF tokens. Ensure CSRF tokens are present in requests and implement Content Security Policy alongside safe request handling.

How to prevent command injection when executing system commands in Rails?

Prevent command injection in Rails by preferring safe command execution methods over shell interpolation and validating inputs. Avoid passing unsanitized user input directly to system command execution functions.