Implement bypass rules for S3 uploads#743
Open
Luc-cpl wants to merge 1 commit intohumanmade:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a robust file bypass system for the S3 Uploads plugin, allowing specific file paths to avoid S3 operations and instead use alternative behaviors (such as pretending files exist, ignoring them, or redirecting to local storage). The changes provide flexible configuration via PHP constants or filters, integrate bypass logic throughout the stream wrapper, and add comprehensive tests for all bypass scenarios.
Motivation
Some WordPress plugins incorrectly use the
uploadsdirectory to store operational files such as.php,.htaccess,index.php, orindex.html. In many cases, these plugins also perform filesystem checks on every request to verify the presence of these files and recreate them if they are missing.When the
uploadsdirectory is backed by S3 via the stream wrapper, these behaviors can trigger unnecessary remote operations or cause compatibility issues, since these files are not intended to be stored in object storage.This feature introduces a bypass mechanism that allows these specific files or paths to avoid S3 interactions entirely, preventing excessive remote calls while maintaining compatibility with plugins that expect traditional filesystem semantics.
File bypass system implementation
File_Bypassclass ininc/class-file-bypass.php, which defines and manages file bypass rules, supporting three actions:void,exists, andlocal. Rules can be configured via PHP constants or thes3_uploads_bypass_rulesfilter.inc/class-stream-wrapper.php), so file operations (open, write, unlink, stat) respect bypass rules and perform the appropriate action (ignore, pretend, or redirect to local filesystem). [1] [2] [3] [4] [5] [6]Testing and validation
tests/test-file-bypass.phpto verify all bypass behaviors (void,exists,local) and ensure regular files are unaffected. Tests cover matching logic, file existence, read/write/unlink operations, and directory creation for local bypasses.