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 prototype pollution issue #529

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

carolabadeer
Copy link
Contributor

Issue #, if available:

Description of changes:
This change fixes the possible prototype pollution in the addMetadata method in segment.js and subsegment.js and adds corresponding unit tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@carolabadeer carolabadeer requested a review from a team as a code owner August 17, 2022 03:51
@codecov-commenter
Copy link

Codecov Report

Merging #529 (93fcd47) into master (bf0f26e) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #529      +/-   ##
==========================================
+ Coverage   82.34%   82.36%   +0.02%     
==========================================
  Files          36       36              
  Lines        1756     1758       +2     
==========================================
+ Hits         1446     1448       +2     
  Misses        310      310              
Impacted Files Coverage Δ
lib/segments/segment.js 79.75% <0.00%> (+0.12%) ⬆️
lib/segments/attributes/subsegment.js 77.92% <0.00%> (+0.14%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -172,7 +172,9 @@ Subsegment.prototype.addMetadata = function(key, value, namespace) {
this.metadata[ns] = {};
}

this.metadata[ns][key] = value !== null && value !== undefined ? value : '';
if (ns !== '__proto__') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to check for the string literal '__proto__' or the object __proto__?

E.g. what would happen if I tried to call segment.addMetadata('key', 'value', __proto__)? Is this something we want to prevent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great callout and a case I tested as well!

On line 159 above there's a check that enforces a string type on the namespace object:
if (namespace && typeof namespace !== 'string')
in which case an error would be logged and the method returns. This ensures that if __proto__ gets passed in, which is not a string, this line would never be reached and thus would not be an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it! Thanks for explaining

Copy link
Contributor

@willarmiros willarmiros left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -172,7 +172,9 @@ Subsegment.prototype.addMetadata = function(key, value, namespace) {
this.metadata[ns] = {};
}

this.metadata[ns][key] = value !== null && value !== undefined ? value : '';
if (ns !== '__proto__') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it! Thanks for explaining

@carolabadeer carolabadeer merged commit 8976998 into aws:master Aug 18, 2022
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.

None yet

3 participants