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

Use more privileged memory allocation for the plaintext Buffer in Decrypt #1173

Open
SimonLau413 opened this issue Jun 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@SimonLau413
Copy link

Problem:

https://github.com/aws/aws-encryption-sdk-javascript/blob/master/modules/decrypt-node/src/decrypt.ts

const plaintext: Buffer[] = []
  let messageHeader: MessageHeader | false = false
  stream
    .once('MessageHeader', (header: MessageHeader) => {
      messageHeader = header
    })
    .on('data', (chunk: Buffer) => plaintext.push(chunk))

  // This will check both Uint8Array|Buffer
  if (ciphertext instanceof Uint8Array) {
    stream.end(ciphertext)
  } else if (typeof ciphertext === 'string') {
    stream.end(Buffer.from(ciphertext, encoding))
  } else if (ciphertext.readable) {
    ciphertext.pipe(stream)
  } else {
    throw new Error('Unsupported ciphertext format')
  }

  await finishedAsync(stream)
  if (!messageHeader) throw new Error('Unknown format')

  return {
    plaintext: Buffer.concat(plaintext),
    messageHeader,
  }

The Buffer.concat(plaintext) will result in a new Buffer. However, the const plaintext: Buffer[] = [] seem not zero-out where sensitive data might remain in memory until gc.

@texastony
Copy link
Contributor

@SimonLau413

Thank you for cutting this issue. We have looked at this matter closely.

An attacker would need access to the Node Process's memory to exploit this.
Such privileged access grants an adversary a number of other exploits.

We believe that any Threat Model that considers the Node Process’ memory access vulnerable needs a more holistic solution than just zeroing out the buffer.
However, what you have written is accurate,
therefore we are going to leave this open as the following Feature Request:

The AWS Encryption SDK for JavaScript SHOULD use a more privileged memory allocation for the plaintext Buffer in Decrypt.ts.

Much Obliged,
AWS Crypto Tools

@texastony texastony changed the title Zero-out intermediate array of plaintext buffer in decrypt function. Use more privileged memory allocation for the plaintext Buffer in Decrypt Jun 30, 2023
@texastony texastony added the enhancement New feature or request label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants