Attack Surface: Unauthorized Version Record Modification
- Description: Direct manipulation of the
versions
table (or the tablepaper_trail
is configured to use) to alter or delete historical data, bypassingpaper_trail
's intended controls. - How
paper_trail
Contributes:paper_trail
creates and manages theversions
table, making it the direct target for data integrity attacks related to version history. This is its core function. - Example: An attacker with database access uses a SQL
UPDATE
statement to change theobject
column of a version record, altering the recorded state of a financial transaction to show a lower amount. - Impact: Loss of audit trail integrity, potential for fraudulent activity, legal and compliance violations, reputational damage.
- Risk Severity: Critical
- Mitigation Strategies:
- Database-Level Permissions (Primary): The application's database user must have only
INSERT
(and optionallySELECT
) privileges on theversions
table. Absolutely noUPDATE
orDELETE
privileges. This is the most crucial defense, directly protecting the datapaper_trail
manages. - Application-Level Access Control: Ensure no code paths allow direct modification of the
versions
table outside ofpaper_trail
's controlled methods. Avoid any custom SQL queries or ActiveRecord manipulations that bypasspaper_trail
. This prevents circumvention ofpaper_trail
's mechanisms. - Regular Database Audits: Implement periodic audits of the
versions
table, potentially using checksums or database auditing features, to detect unauthorized changes to the datapaper_trail
stores.
- Database-Level Permissions (Primary): The application's database user must have only
Attack Surface: whodunnit
Spoofing
- Description: An attacker manipulates the
whodunnit
field, a core component ofpaper_trail
's audit trail, to falsely attribute actions to another user or system process. - How
paper_trail
Contributes:paper_trail
defines and uses thewhodunnit
field to track the originator of changes. This is a fundamental part ofpaper_trail
's functionality. - Example: An attacker modifies a request to include a different user's ID in the data used to set
PaperTrail.request.whodunnit
, causing their malicious changes to be attributed to the innocent user within thepaper_trail
records. - Impact: Misattribution of actions within the audit trail, difficulty in identifying the true perpetrator, potential for framing innocent users.
- Risk Severity: High
- Mitigation Strategies:
- Secure Authentication: Implement robust authentication to ensure the user's identity is reliably established. This provides the foundation for a trustworthy
whodunnit
. - Controller-Level
whodunnit
Setting: SetPaperTrail.request.whodunnit
in abefore_action
in your controllers, immediately after successful authentication, and never based on user-supplied input. This ensurespaper_trail
receives accurate attribution data. Example:class ApplicationController < ActionController::Base before_action :set_paper_trail_whodunnit private def user_for_paper_trail user_signed_in? ? current_user.id : 'Public User' # Or a system user ID end end
- Review Custom
whodunnit
Methods: If you have a customuser_for_paper_trail
method (apaper_trail
specific feature), thoroughly audit it for vulnerabilities.
- Secure Authentication: Implement robust authentication to ensure the user's identity is reliably established. This provides the foundation for a trustworthy
Attack Surface: Sensitive Data Exposure in Version History
- Description: Sensitive information (passwords, API keys, PII) is inadvertently stored in the
object
orobject_changes
columns of theversions
table, directly exposing data through paper_trail's core mechanism. - How
paper_trail
Contributes:paper_trail
serializes model data, including potentially sensitive attributes, into theobject
andobject_changes
columns of theversions
table. This is howpaper_trail
stores its historical data. - Example: A user model includes a
password
attribute (which should be a hashed password, but for this example, assume it's plain text).paper_trail
, by its design, stores the plain-text password in theobject
column when the user is created or updated. - Impact: Data breach, privacy violations, potential for further attacks (e.g., credential stuffing).
- Risk Severity: Critical
- Mitigation Strategies:
- Attribute Filtering (Primary): Use the
:ignore
option inhas_paper_trail
to explicitly exclude sensitive attributes from being tracked by paper_trail. This is a directpaper_trail
configuration setting. Example:class User < ApplicationRecord has_paper_trail ignore: [:password, :api_key, :credit_card_number] end
- Data Sanitization/Encryption: If sensitive data must be tracked, sanitize or encrypt it before it's stored by
paper_trail
. This requires custom serialization logic that interacts directly with howpaper_trail
handles data. - Restricted Access: Limit access to the
versions
table (managed bypaper_trail
) and any UI that displays version history to authorized personnel only.
- Attribute Filtering (Primary): Use the
Attack Surface: Bypassing Versioning Controls
- Description: An attacker finds a way to modify tracked models without triggering the creation of new versions, directly circumventing
paper_trail
's intended functionality. - How
paper_trail
Contributes: This attack directly targetspaper_trail
's core purpose: to track changes. The vulnerability lies in the ability to avoidpaper_trail
's mechanisms. - Example: An attacker discovers a code path that uses direct SQL
UPDATE
statements on a tracked model, bypassing ActiveRecord callbacks and thuspaper_trail
's hooks. - Impact: Data changes occur without being recorded, undermining the audit trail provided by
paper_trail
. - Risk Severity: High
- Mitigation Strategies:
- Comprehensive Model Configuration: Ensure all relevant models and attributes are correctly configured for versioning with
paper_trail
. Carefully review:only
,:ignore
,:if
, and:unless
conditions – allpaper_trail
specific settings. - Code Review: Thoroughly review code for any direct SQL modifications or ActiveRecord manipulations that bypass
paper_trail
's hooks. - Testing: Include comprehensive tests (including negative tests) to verify that all expected actions trigger version creation by
paper_trail
and that attempts to bypass versioning fail. without_versioning
Audit: Scrutinize the use ofwithout_versioning
(apaper_trail
specific method). It should be used extremely rarely and only with strong justification and thorough review. This method directly disablespaper_trail
.
- Comprehensive Model Configuration: Ensure all relevant models and attributes are correctly configured for versioning with