Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add content length as an optional signed header. #7

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ice-breaker-tg
Copy link
Contributor

@ice-breaker-tg ice-breaker-tg commented Oct 4, 2022

Adds content-length to the signed headers portion of the built request.

Adds test:uploads npm command to test actual uploads to an S3 bucket given in .env
Sets up the tests using misc methods to attempt sending invalid/incorrect data when it comes to size.

Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ice-breaker-tg all looks good abd my suggestions in pr are nits that can be applied or disregarded.

That said I’m still not approving these changes because according to aws/aws-sdk-net#424 (comment) this header is not enforced by S3, that is if client sends larger file but sets content-length header to smaller number S3 will end up writing a larger object.

I don’t know if that comment is accurate, but we need to make sure it is before considering this done.

This article seems to suggest that presigned post requests can be used instead to enforce size limits, which we could consider if PUTs are indeed not enforcing size limit

src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
test/sigv4.test.js Outdated Show resolved Hide resolved
@ice-breaker-tg
Copy link
Contributor Author

ice-breaker-tg commented Nov 4, 2022

@ice-breaker-tg all looks good abd my suggestions in pr are nits that can be applied or disregarded.

That said I’m still not approving these changes because according to aws/aws-sdk-net#424 (comment) this header is not enforced by S3, that is if client sends larger file but sets content-length header to smaller number S3 will end up writing a larger object.

I don’t know if that comment is accurate, but we need to make sure it is before considering this done.

This article seems to suggest that presigned post requests can be used instead to enforce size limits, which we could consider if PUTs are indeed not enforcing size limit

This should not be an issue, due to the SHA256 being calculated on upload.
Attempting to write a smaller or larger file via setting content length manually in CURL results in the upload failing.
I will do some further testing with it to ensure that there is no combination of problems.

I think that article is using the built in signedURLs from the SDK and is a bit different since we are generating them ourselves.

I have done several tests with this, and I cannot sort out a way to do a "bad sized" upload, but we can discuss a bit further to ensure this is all working as expected.

Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of the change looks correct to me.

Please tidy up this PR. Add a PR description and documentation to help the next dev get started if tests now need env set up. Remove commented out code...add in the debug module to let folks turn toggle debug logging if it's useful.

test/badFetch.js Show resolved Hide resolved
test/badFetch.js Outdated Show resolved Hide resolved
test/actual-uploads.test.js Outdated Show resolved Hide resolved
test/actual-uploads.test.js Show resolved Hide resolved
test/signer.test.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
test/actual-uploads.test.js Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
olizilla added a commit to storacha/w3infra that referenced this pull request Dec 8, 2022
- Add `createUploadUrl` to `car-store.js` as creating presigned s3 urls
is a job for the bucket abstraction and having a thing called `signer`
that wasn't a keypair for a DID for ucanto was confusing.
- Switch to the `@aws-sdk/s3-request-presigner` for creation of signed
s3 urls to simplify credential management. The existing s3 client is
reused.
- Adds `content-length` to the list of headers that form part of the url
signature.

fixes #38 

### Notes

When presigning a URL for s3, some headers are "hoisted" to the
URLSearchParams; they appear in the query string so you can hand the url
off as a string, and the params needed for auth are baked right in
there. S3 support unpacking those params from either the query _or_ from
http request headers. The query params are part of the signature, so
they can't be tampered with.

You can also "hoist" and sign any other params you want... it is
tempting to move `x-amz-checksum-sha256` to the query so a user wouldn't
need to provide it separately. However it appears that aws does not
support pulling that value out of the query, only from a request header.

It is unknown how s3 reacts to sending a content-length that doesn't
match the payload size, but there are tests for it in
storacha/sigv4#7

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
@JeffLowe JeffLowe linked an issue Dec 12, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add size to signed headers.
3 participants