mcpField
P
privacy-by-design-rails

privacy-by-design-rails

github.com/codeminer42Security3238 installsUpdated 5d ago
Repository

About privacy-by-design-rails

privacy-by-design-rails is a skill for Rails 8 developers working with personal data. It provides a scanner and references for applying privacy practices across areas such as data minimization, encryption, log protection, consent, and data subject requests.

Key features

  1. 01Scan files handling personal data
  2. 02Provide Rails privacy references
  3. 03Cover encryption and key rotation
  4. 04Guide log and error-report scrubbing
  5. 05Describe consent and retention workflows

Use cases

  1. 01Review Rails code that handles personal data
  2. 02Plan log scrubbing for a Rails application
  3. 03Implement consent management and data subject requests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/codeminer42/skills --skill privacy-by-design-rails

After installing, type/privacy-by-design-railsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
anonymization.md
consent-management.md
data-minimization.md
data-retention.md
dsar.md
encryption.md
log-and-output-protection.md
pii-definition.md
pseudonymization.md
secrets-management.md
session-security.md
rules/
consent-use-purposes-constant.md
email-no-pii-in-body.md
encrypt-filter-parameters.md
encrypt-pii-fields.md
export-dsar-vs-processing.md
export-no-pii-at-rest.md
log-no-job-arguments.md
log-no-pii-in-cache.md
log-pass-ids-not-data.md
scripts/rules/
base_rule.rb
consent_use_purposes_constant.rb
email_no_pii_in_body.rb
encrypt_filter_parameters.rb
encrypt_pii_fields.rb
error_reporter_scrubbing.rb
export_dsar_vs_processing.rb
export_no_pii_at_rest.rb
log_no_job_arguments.rb
log_no_pii_in_cache.rb

Details

From the project README

Privacy by Design with Rails 8

When generating or reviewing code that handles personal data, run the scanner first: ruby .claude/skills/privacy-by-design-rails/scripts/scanner.rb --files <relevant files>

For deeper context on any topic, read the relevant reference file from references/.

What counts as PII? Any data that can identify a person directly or indirectly (GDPR Art. 4, LGPD Art. 5, NIST SP 800-122). This includes data that isn't identifying alone but becomes PII when linked to a person — farm names, animal names with known owners, license plates, vehicle VINs, student IDs, property addresses, social media handles, company names of sole proprietors, device IDs linked to accounts, IP addresses. See references/pii-definition.md for the full definition and linkability test. When in doubt, treat it as PII.

Quick Reference

PrincipleRails FeatureFile
Log + inspect filteringconfig.filter_parameters (covers both)references/log-and-output-protection.md
Per-model PII declarationself.filter_attributes (self-documenting)references/log-and-output-protection.md
Job arg protection (ActiveJob)self.log_arguments = false (set in ApplicationJob)references/log-and-output-protection.md
Job arg protection (Sidekiq)Server middleware + pass IDs onlyreferences/log-and-output-protection.md
PII redaction in logslogstop gemreferences/log-and-output-protection.md
IP anonymizationip_anonymizer middlewarereferences/log-and-output-protection.md
Error reporter scrubbingScrub PII from Sentry/Rollbar/etc.references/log-and-output-protection.md
APM/monitoring scrubbingScrub PII from AppSignal/NewRelic/etc.references/log-and-output-protection.md
Data minimizationStrong parameters + serializersreferences/data-minimization.md
Searchable encryptionencrypts :field, deterministic: truereferences/encryption.md
Non-searchable encryptionencrypts :fieldreferences/encryption.md
Password hashinghas_secure_passwordreferences/encryption.md
Key rotationencrypts :field, previous: [...]references/encryption.md
Secrets managementbin/rails credentials:editreferences/secrets-management.md
Security auditingbundler-audit, Brakeman, pdscanreferences/secrets-management.md
HTTPS enforcementconfig.force_ssl = true + HSTSreferences/session-security.md
Session securitySigned cookies / Bearer tokensreferences/session-security.md
Consent managementImmutable append-only audit trailreferences/consent-management.md
Consent enforcementController concern gating actionsreferences/consent-management.md
Consent-gated exportsConsentGatedExportSerializer for processingreferences/consent-management.md
AnonymizationReplace PII with [ANONYMIZED]references/anonymization.md
PseudonymizationHMAC hash preserving analytics linksreferences/pseudonymization.md
DSAR workflowAccess / Rectification / Erasurereferences/dsar.md
Data retentionSolid Queue scheduled jobsreferences/data-retention.md

Putting It All Together — The User Model

class User < ApplicationRecord
  has_secure_password
  has_many :sessions, dependent: :destroy
  has_many :addresses, dependent: :destroy
  has_many :orders, dependent: :restrict_with_error
  has_many :consents, dependent: :destroy
  has_many :data_subject_requests, dependent: :destroy

  include Anonymizable
  include Pseudonymizable
  include DataExportable
  include HasConsent

  encrypts :email_address, deterministic: true, downcase: true
  encrypts :first_name
  encrypts :last_name
  encrypts :phone
  encrypts :date_of_birth

  self.filter_attributes = %i[
    first_name last_name phone date_of_birth
    email_address password_digest
  ]

  enum :role, { customer: 0, admin: 1 }

  anonymizable :first_name, :last_name, :phone, :date_of_birth
  exportable :uuid, :email_address, :first_name, :last_name, :phone, :date_of_birth

  normalizes :email_address, with: ->(e) { e.strip.downcase }
end

Common Mistakes (not caught by scanner)

MistakeFix
Deleting records with dependents for right to erasurePrefer anonymization when the record has dependents — preserves referential integrity. Some authorities prefer true deletion, so check local requirements
Storing consents as a boolean flagUse immutable append-only records for audit trail
Exposing sequential IDs in APIsUse UUIDs as public identifiers
Manual data retentionAutomate with Solid Queue scheduled jobs

External References

Consult these when you need the latest guidance or to verify patterns against official sources. Use WebFetch when needed — don't fetch all of them upfront.

Rails
GDPR
LGPD (Brazil)

Comments

Markdown supported