aws-sdk-net: S3 request signing broken for S3-compatible services
If one is to use an S3-compatible service (e.g. for integration testing by mocking S3), signed requests are no longer valid as of this commit fbea7531858a2801c0e7734aaf15b72c04b0732d, which appears to use a heuristic to detect whether a request is being made to S3.
When using an S3-compatible service the ClientConfig.ServiceUrl might no longer satisfy the heuristic which appears to check the endpoint host name, and as such the resourcePath is double encoded and no longer signs correctly.
This is the heuristic:
and its use:
Expected Behavior
When connecting to an S3-compatible service using ClientConfig.ServiceUrl, all S3 requests including those using characters that are transformed during URL encoding should be correctly signed according the version 4 signature scheme.
The CanonicalizeResourcePath() function should only single encode requests.
Current Behavior
The S3-compatible service rejects the request that include characters that are transformed during URL encoding.
Consider an attempt to store an object to a content bucket and object key: Alp?ha/Be%ta /Test&ing.
CanonicalizeResourcePath() was called with the following arguments:
endpoint = "http://192.168.99.100:33886/"
resourcePath = "/content/Alp?ha/Be%ta /Test&ing"
detectPreEncode = true
The function logged the following:
Double encoded /content/Alp?ha/Be%ta /Test&ing with endpoint http://192.168.99.100:33886/ for canonicalization: /content/Alp%253Fha/Be%2525ta%2520/Test%2526ing
Possible Solution
-
It appears that the that signing code is invoked from the S3 client code which intrinsically knows only single URL encoding is required. Expose the functionality through the
AWS4Signersuch that all S3 requests are only single encoded. -
If that isn’t possible, provide some means for configuration to disable the heuristic and double encoding.
Context
We have some integration tests that ensure our code correctly handles paths sensitive to URL encoding when storing objects in S3. Upon upgrade to AWSSDK.Core 3.3.21.15 and later, this test started to fail.
Your Environment
- AWSSDK.Core version used: 3.3.21.20
- Service assembly and version used: AWSSDK.S3 3.3.18
- Operating System and version: Microsoft Windows 10
- Targeted .NET platform: .NET Core 2.0
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 20 (2 by maintainers)
@sstevenkang This has severe security complications as people implement workarounds by disabling signing. I would urge you to reconsider prioritizing this issue as it seems like a simple fix.
Thanks for reporting this with great detail. We are not currently prioritizing work to accommodate for non-S3 services. We’ll add this into our backlog as a feature request.
We used
3.3.19to avoid the problem.I downgraded Core library to 3.3.19 as suggested by @Sumo-Bryant but honestly, it is not acceptable from Amazon to not fix this issue…
The latest version of Core (3.3.105.0) fixes this issue by no longer double encoding S3 requests with a different service URL
Our original workaround was to pin
AWSSDK.Coreto an old version without the issue. This only works if you don’t want to use new features such asAWSSDK.SecretsManagerfor which there is no version that is compatible with an “old” version ofAWSSDK.Core.We’ve disabled the affected tests for the time being.