Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Security fix for Arbitrary Code Execution in json-ptr #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function compilePointerDereference(path: PathSegments): Dereference {
return (it): unknown => it;
}
body = path.reduce((body, _, i) => {
return body + " && \n\ttypeof((it = it['" + replace(path[i] + '', '\\', '\\\\') + "'])) !== 'undefined'";
return body + " && \n\ttypeof((it = it['" + path[i].replace('\\', '\\\\').replace(/\'/g, '\\\'') + "'])) !== 'undefined'";

Choose a reason for hiding this comment

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

path[i] is a PathSegment which is string | number, so this code violates the TypeScript checks.
It also drastically changes the call stack as this replaces the replace function call that is a local function, not string.replace

Alternative solution:
return body + " && \n\ttypeof((it = it['" + replace(replace(path[i] + '', '\\', '\\\\'), '\'', '\\\'') + "'])) !== 'undefined'";

}, "if (typeof(it) !== 'undefined'") as string;
body = body + ') {\n\treturn it;\n }';
// eslint-disable-next-line no-new-func
Expand Down