-
Notifications
You must be signed in to change notification settings - Fork 9
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
Expose position and/or input of source text? #10
Comments
Please do not repeat the regex match object pattern of adding properties to an array :-) |
No, it would be an object. 😅 |
I'm concerned about the use of insignificant things such as whitespace, key ordering, etc to smuggle additional information. See my comments from February. |
Such a channel already exists in the form of confusable glyphs/invisible whitespace/excess numeric precision/etc., not to mention extra object members and/or array items (and key ordering in particular is unaffected by this proposal; revivers are already called in source text order). That said, it's true that the bandwidth for such information would be dramatically increased. But is it really appropriate to try protecting against the extremely narrow scenarios in which a potentially malicious reviver is used with JSON.parse (e.g., that Eve doesn't have the ability to perform arbitrary inspection but does have unfettered access to deserialized values)? The fix for that would be straightforward—don't pass through -JSON.parse(src, untrusted)
+JSON.parse(src, function scrubber(key, val, { keys }) { return call(untrusted, this, key, val, { keys }) }) |
@gibson042 I think you misunderstood my concern. I am not worried about an adversarial scenario. I am worried about well-meaning developers deliberately (ab)using these insignificant encoding differences to transmit additional, extra-JSON information. I would prefer that JSON.parse only be able to act on the significant parts of the input. |
This proposal necessarily introduces the ability to differentiate between input like |
I think that strikes a good balance. We don't have to eliminate the possibility, we just have to limit it enough to make it unappealing. |
To clarify, is that support for a) exposing source text with all values but input and index for none, or b) taking the further step of denying the ability to read source text for objects and arrays? |
I think the only loss of (significant) information in JavaScript's interpretation of JSON is in the numbers/strings, right? In which case B would be preferable. |
There was consensus on TC39 Incubator call to expose source text only for primitive values, and in particular to not provide |
Examples: // parsing JSON-LD
JSON.parse(text, (key, val, context) => {
if (key == "@type" || key == "@context") {
try {
return new URL(val);
} catch(err) {
throw Obect.assign(new SyntaxError(err.message + ` at line ${context.line}, character ${context.position}`), err);
}
} else {
return val;
}
}); // parsing abstract syntax tree
JSON.parse(text, (key, val, context) {
if (typeof val == "object" && val.type == "TreeNode") {
if (!Array.isArray(val.children))
throw new SyntaxError(`Encountered TreeNode without children at line ${context.line}, character ${context.position}`);
return new TreeNode(val.children);
}
return val;
}); |
Agree that "throwing indicative errors" is a strong use-case for exposing position information. Especially with other data types in the pipeline ( |
String.prototype.replace
passes position and input arguments to replacer functions and the return value fromRegExp.prototype.exec
has "index" and "input" properties;JSON.parse
could behave similarly.As noted by @rbuckton, this could be useful for error reporting.
The text was updated successfully, but these errors were encountered: