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

Allocate new buffer when parsing sensitive blob #2622

Merged
merged 3 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Parser-f872d831.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Parser",
"description": "Alloc new buffers from 0 offset when parsing the sensitive blob data and zero out the node shared buffer pool."
}
17 changes: 16 additions & 1 deletion lib/model/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,22 @@ function IntegerShape() {

function BinaryShape() {
Shape.apply(this, arguments);
this.toType = util.base64.decode;
this.toType = function(value) {
var buf = util.base64.decode(value);
if (this.isSensitive && util.isNode() && typeof util.Buffer.alloc === 'function') {
trivikr marked this conversation as resolved.
Show resolved Hide resolved
/* Node.js can create a Buffer that is not isolated.
* i.e. buf.byteLength !== buf.buffer.byteLength
* This means that the sensitive data is accessible to anyone with access to buf.buffer.
* If this is the node shared Buffer, then other code within this process _could_ find this secret.
* Copy sensitive data to an isolated Buffer and zero the sensitive data.
* While this is safe to do here, copying this code somewhere else may produce unexpected results.
*/
var secureBuf = util.Buffer.alloc(buf.length, buf);
buf.fill(0);
buf = secureBuf;
}
return buf;
};
this.toWireFormat = util.base64.encode;
}

Expand Down
25 changes: 25 additions & 0 deletions test/model/shape.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.