Summary
Active Storage's DiskService#delete_prefixed method previously passed blob keys directly into Dir.glob without escaping wildcard characters.
When blob keys contain attacker-controlled glob metacharacters, this can lead to deletion of unintended files within the storage directory.
Affected context
This vulnerability affects Rails applications using Active Storage with the Disk service backend where blob keys can contain user-influenced values or custom-generated keys that are not strictly sanitized.
The issue occurs during cleanup operations that rely on delete_prefixed, which uses Dir.glob to identify files to remove.
Environments where application logic or configuration allows special characters such as *, ?, [, or { in blob keys are particularly exposed, because these characters are interpreted as glob patterns rather than literal file names.
Exploit preconditions
- Attack surface: Active Storage operations that trigger
DiskService#delete_prefixedon the local filesystem. - Required access: Ability to influence or control blob keys (directly or indirectly), or to cause the application to generate blob keys containing glob metacharacters.
- Trigger point: Invocation of
delete_prefixed(e.g., cleanup, purge, or cascading deletes) that passes a crafted key prefix intoDir.glob. - Why exploitation is possible: The method forwards blob keys directly to
Dir.globwithout escaping glob metacharacters, causing the filesystem search to match a broader set of files than intended, and then delete them.
Why this happens
The underlying issue is the injection of untrusted input into a filesystem pattern-matching API without proper neutralization, aligning with CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
Instead of treating blob keys as literal directory or file name fragments, DiskService#delete_prefixed used them as raw glob patterns, allowing wildcard expansion.
This insecure pattern emerges whenever application-controlled data is passed into interpreters (such as shells, SQL engines, or file pattern matchers like Dir.glob) without escaping or constraining special characters, resulting in overbroad actions on the downstream component.
Potential impact
- Deletion of additional files within the Active Storage directory beyond the intended blobs.
- Accidental removal of other tenants' files in multi-tenant setups sharing a storage directory.
- Potential loss of critical application assets or user-uploaded data stored under the same root path.
- Service disruption due to missing files required for normal application behavior.
- Data integrity issues, including partial or inconsistent datasets for end users.
General mitigation guidance
Mitigation centers on ensuring that blob identifiers are treated strictly as data, not as patterns or commands.
Recommended defensive patterns include:
- Escaping or neutralizing glob metacharacters before passing any user-influenced value to
Dir.globor similar pattern APIs. - Restricting the character set for blob keys to a safe, minimal alphabet (e.g., alphanumeric plus a short whitelist of separators).
- Encapsulating file operations behind well-reviewed utility functions that always use safe, literal matching semantics instead of raw globs for untrusted inputs.
- Isolating storage directories and enforcing least-privilege filesystem permissions so that even if pattern expansion misbehaves, the blast radius is limited.
- Using logical identifiers for blobs (e.g., UUIDs) that are decoupled from any user-supplied strings.
How teams detect issues like this
Detection typically involves a combination of static and review-based checks:
- Static analysis rules that flag uses of
Dir.glob,Dir[], or other pattern-matching APIs where arguments may contain user-controllable data. - Code review checklists that explicitly question any use of filesystem globs and require justification when inputs are not strictly constant or from trusted sources.
- Logging and monitoring for unusual spikes in file deletions or errors related to missing blobs, which can indicate unintended deletions.
- Periodic security-focused scans of the codebase using automated tools to identify injection risks into shell, database, or filesystem interpreters.
- Tests that simulate blob keys with special characters and verify that deletion routines affect only the expected files.

