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

fix(middleware-ssec): ssecMiddleware with strict base64 validation #5875

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

RanVaknin
Copy link
Contributor

@RanVaknin RanVaknin commented Mar 8, 2024

Issue

#5863

Description

Making a a more robust check for if the provided key is indeed a base64 by comparing the byte length to 32, since AES-256 specifies a cipher must be 256bits (32 bytes) we can assert that the cipher provided must have a byte length of 32.

AES-256() The block cipher specifed in this Standard with 256-bit keys

https://csrc.nist.gov/pubs/fips/197/final

Testing

Added unit test coverage to cover the more of the middleware changes from #5676
And additionally unit tests to cover the isValidBase64EncodedSSECustomerKey helper function.

Driver code:

Borrowed from edge case mentioned in #5863:

async function putObjectWithMD5EncodedSSECKey(){
  try {
    const SSECustomerKey = crypto
    .createHash("md5")
    .update("foo")
    .digest("hex");
    const SSECustomerKeyMD5 = crypto
  .createHash("md5")
  .update(SSECustomerKey)
  .digest("hex");

    const response = await client.send(new PutObjectCommand({
      Bucket: 'testbucket',
       Body: 'This is a test',      
       Key: "foo",    
       SSECustomerKey: SSECustomerKey,
      SSECustomerAlgorithm: 'AES256',
      SSECustomerKeyMD5: SSECustomerKeyMD5
    }))
    console.log(response.$metadata.httpStatusCode);
  } catch (error) {
    console.error(error);
  }
}

// 200

Additional context

Add any other context about the PR here.

Checklist

  • If you wrote E2E tests, are they resilient to concurrent I/O?
  • If adding new public functions, did you add the @public tag and enable doc generation on the package?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@RanVaknin RanVaknin requested a review from a team as a code owner March 8, 2024 17:09
@kuhe kuhe merged commit 28dcfa3 into aws:main Mar 18, 2024
4 checks passed
Copy link

github-actions bot commented Apr 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants