Skip to content

Checking for file existence in S3 broken since league/flysystem-aws-s3-v3 3.12.1 #1630

@ptkoz

Description

@ptkoz

Bug Report

Q A
Flysystem Version 3.12.2
Adapter Name Aws S3 (v3) Adapter
Adapter version 3.12.1 & 3.12.2

Summary

Following code will:

  • return false for version up to 3.10.3
  • throw an exception for 3.12.1 & 3.12.2
$flysytsem = new \League\Flysystem\Filesystem(
    new \League\Flysystem\AwsS3V3\AwsS3V3Adapter(
        new \Aws\S3\S3Client([
            'region' => 'PUT AWS REGION HERE',
            'version' => 'latest',
            'credentials' => [
                'key' => 'PUT AWS KEY ID HERE',
                'secret' => 'PUT AWS SECRET HERE',
            ]
        ]),
        'PUT S3 BUCKET NAME HERE'
    ),
);

var_dump($flysytsem->fileExists('/some/non-existing/file'));

Please note that for existing files, newest versions also correctly return true, without an exception. I've tested this with various aws-sdk versions and it seems to be unrelated (tested various versions from 3.236.6 to 3.257.5, same behaviour).

Also the calling identity has full access to the S3 bucket:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::bucket-name/*"
        }
    ]
}

How to reproduce

  1. Clone bare-minimum example repository here: https://github.com/ptkoz/flysystem-aws-s3-v3-file-exists-bug
  2. Run composer install
  3. Run php test.php
  4. Observe the issue

Then:
5. Downgrade version number in composer.json to ~3.10.0
6. Run composer update
7. Run php test.php
8. Observe it works

The exception

Posting full exception trace seems unnecessary. There are various Flysystem / AWS / Guzzle exceptions in the stack. The issue though seems to originate in 403 response from AWS api for HEAD request, as follows:

Uncaught GuzzleHttp\Exception\ClientException: Client error: `HEAD https://xxxxx.s3.eu-west-1.amazonaws.com/some/non-existing/file` resulted in a `403 Forbidden` response in /flysystem-aws-s3-v3-file-exists-bug/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions