Repository navigation
fix: keep __proto__ node ids out of Object.prototype in the node map - #590
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
createNodeMap stored subjects and graphs in plain objects, so a node with @id '__proto__' (or a graph with that name) resolved to Object.prototype: its @id and properties were written there and the subject was silently lost. The graphs, their subject maps and the merged node map are now created without a prototype, so such a name is stored as its own entry. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Author
|
Hi! This PR has all checks passing and is ready for review. Would appreciate a look whenever you have a moment 🙏 |
Author
|
Hey! Just wanted to follow up on this security fix for proto pollution in the node map. The branch is current with main and all looks green. Appreciate any time you can spare for a review. 🙏 |
Author
|
Hi @digitalbazaar team — this PR is ready for review. All checks are green where available. Let me know if anything needs tweaking! |
Author
|
Ready for review when you have a moment! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #584
Problem
jsonld.flatten()builds its node map with plain objects, so a subject whose@idis__proto__resolves toObject.prototypeat the lookup(
subjects[name] = subjects[name] || {}inlib/nodeMap.js): its@idandits properties are written onto
Object.prototypeand the subject itself issilently dropped from the output. The same happens for a named graph named
__proto__, andmergeNodeMapGraphs' merged map has the same shape, so thenode is lost again on merge.
Reproduction on
main(with the four npm deps stubbed, since this host has nonetwork installs) — the PoC from the issue:
Fix
The graphs container, each subject map and the merged node map are now created
with
Object.create(null)(innodeMap.js, in the two flatten call sites injsonld.js, and inframe.js's graph map, which feeds the samecreateNodeMap). On a prototype-less map,__proto__is stored as a plain ownentry, so the subject survives and nothing reaches
Object.prototype.Verification
[{'@id': '__proto__', 'http://example.com/polluted': [{'@value': 'yes'}]}]and leaves
Object.prototypeuntouched; same for a named graph named__proto__.tests/misc.js(flatten with@id: __proto__,named graph
__proto__, andjsonld.createNodeMapkeeping the entry).a frame run (plain IRIs, blank nodes, named graphs,
@list, a merge): outputis byte-identical before and after, except the
__proto__node map entry,which was silently
{}before and now holds the node.the library was exercised directly through
require('.../lib/jsonld.js')with minimal stubs for
canonicalize,lru-cache,rdf-canonizeand@digitalbazaar/http-client.