aws / aws/aws-encryption-sdk-javascript
Use more privileged memory allocation for the plaintext Buffer in Decrypt
- Dominant language
- TypeScript
- Stars
- 260
- Forks
- 68
- Avg merge
- 22h 19m
- Merged PRs (30d)
- 2
Description
### Problem:
[https://github.com/aws/aws-encryption-sdk-javascript/blob/master/modules/decrypt-node/src/decrypt.ts](url)
```javascript
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.
[//]: # (NOTE: If you believe this might be a security issue, please email aws-security@amazon.com instead of creating a GitHub issue. For more details, see the AWS Vulnerability Reporting Guide: https://aws.amazon.com/security/vulnerability-reporting/ )
Contributor guide
Research direction
Start with modules/decrypt-node/src/decrypt.ts and inspect how plaintext chunks are collected and combined by Buffer.concat. Determine what privileged allocation means for this Node.js decryption path and how sensitive data should be handled before garbage collection. Done should address the reported plaintext-buffer lifetime concern without changing the decryption result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100