Skip to content

Commit

Permalink
Merge pull request #6 from outlandishideas/s3-skip-blank-files
Browse files Browse the repository at this point in the history
Skip "security" blank files when using S3 Uploads
  • Loading branch information
NoelLH authored May 31, 2023
2 parents ccba294 + 496fd1d commit 32da28c
Show file tree
Hide file tree
Showing 6 changed files with 6,341 additions and 6,323 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea

composer.lock
6 changes: 6 additions & 0 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ public static function format_number( $number, $number_format, $currency = '', $
}

public static function recursive_add_index_file( $dir ) {
if (defined('S3_UPLOADS_BUCKET')) {
// Neither classic filesystem security measure is relevant on S3. When this constant is
// set, we assume that S3 Uploads is intended to be used for Gravity Forms uploads.
return;
}

if ( ! is_dir( $dir ) || is_link( $dir ) ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wp-premium/gravityforms",
"type": "wordpress-plugin",
"description": "Gravity Forms, composer-ified",
"version": "2.4.20.1",
"version": "2.4.20.2",
"minimum-stability": "stable",
"require": {
"composer/installers": "~2.0|~1.0"
Expand Down
24 changes: 13 additions & 11 deletions forms_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5493,17 +5493,19 @@ public static function get_file_upload_path( $form_id, $file_name ) {
return false;
}

// Adding index.html files to all subfolders.
if ( $default_target_root != $target_root && ! file_exists( $target_root . 'index.html' ) ) {
GFCommon::recursive_add_index_file( $target_root );
} elseif ( ! file_exists( self::get_upload_root() . '/index.html' ) ) {
GFCommon::recursive_add_index_file( self::get_upload_root() );
} elseif ( ! file_exists( self::get_upload_path( $form_id ) . '/index.html' ) ) {
GFCommon::recursive_add_index_file( self::get_upload_path( $form_id ) );
} elseif ( ! file_exists( self::get_upload_path( $form_id ) . "/$y/index.html" ) ) {
GFCommon::recursive_add_index_file( self::get_upload_path( $form_id ) . "/$y" );
} else {
GFCommon::recursive_add_index_file( self::get_upload_path( $form_id ) . "/$y/$m" );
// Adding index.html files to all subfolders, except when S3 houses uploads.
if (!defined('S3_UPLOADS_BUCKET')) {
if ($default_target_root != $target_root && !file_exists($target_root . 'index.html')) {
GFCommon::recursive_add_index_file($target_root);
} elseif (!file_exists(self::get_upload_root() . '/index.html')) {
GFCommon::recursive_add_index_file(self::get_upload_root());
} elseif (!file_exists(self::get_upload_path($form_id) . '/index.html')) {
GFCommon::recursive_add_index_file(self::get_upload_path($form_id));
} elseif (!file_exists(self::get_upload_path($form_id) . "/$y/index.html")) {
GFCommon::recursive_add_index_file(self::get_upload_path($form_id) . "/$y");
} else {
GFCommon::recursive_add_index_file(self::get_upload_path($form_id) . "/$y/$m");
}
}
}

Expand Down
Loading

0 comments on commit 32da28c

Please sign in to comment.