Skip to content

Commit

Permalink
Ensure JS implementations don't traverse the prototype chain.
Browse files Browse the repository at this point in the history
This extracts tests from #414, originally written in a slightly more
granular manner by @ChALkeR, but here combines and pares them down so we
only add ~10 rather than hundreds. Hopefully these should at least point
implementers at the issue. If any real-world occurrences of bugs are
uncovered that aren't covered by these, please raise a follow-up issue!

Interested implementers may also reference the PR if they wish to run a
fuller set of them.

Co-authored by: Nikita Skovoroda <[email protected]>
  • Loading branch information
Julian committed Aug 7, 2022
1 parent 0015d52 commit 597b1fb
Show file tree
Hide file tree
Showing 12 changed files with 600 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/draft-next/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,59 @@
"valid": true
}
]
},
{
"description": "properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"properties": {
"__proto__": {"type": "number"},
"toString": {
"properties": { "length": { "type": "string" } }
},
"constructor": {"type": "number"}
}
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": true
},
{
"description": "__proto__ not valid",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString not valid",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor not valid",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present and valid",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
46 changes: 46 additions & 0 deletions tests/draft-next/required.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,51 @@
"valid": false
}
]
},
{
"description": "required properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": { "required": ["__proto__", "toString", "constructor"] },
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": false
},
{
"description": "__proto__ present",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString present",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor present",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
54 changes: 54 additions & 0 deletions tests/draft2019-09/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,59 @@
"valid": true
}
]
},
{
"description": "properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"properties": {
"__proto__": {"type": "number"},
"toString": {
"properties": { "length": { "type": "string" } }
},
"constructor": {"type": "number"}
}
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": true
},
{
"description": "__proto__ not valid",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString not valid",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor not valid",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present and valid",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
46 changes: 46 additions & 0 deletions tests/draft2019-09/required.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,51 @@
"valid": false
}
]
},
{
"description": "required properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": { "required": ["__proto__", "toString", "constructor"] },
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": false
},
{
"description": "__proto__ present",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString present",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor present",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
54 changes: 54 additions & 0 deletions tests/draft2020-12/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,59 @@
"valid": true
}
]
},
{
"description": "properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"properties": {
"__proto__": {"type": "number"},
"toString": {
"properties": { "length": { "type": "string" } }
},
"constructor": {"type": "number"}
}
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": true
},
{
"description": "__proto__ not valid",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString not valid",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor not valid",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present and valid",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
46 changes: 46 additions & 0 deletions tests/draft2020-12/required.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,51 @@
"valid": false
}
]
},
{
"description": "required properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": { "required": ["__proto__", "toString", "constructor"] },
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": false
},
{
"description": "__proto__ present",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString present",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor present",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
54 changes: 54 additions & 0 deletions tests/draft4/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,59 @@
"valid": true
}
]
},
{
"description": "properties whose names are Javascript object property names",
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
"schema": {
"properties": {
"__proto__": {"type": "number"},
"toString": {
"properties": { "length": { "type": "string" } }
},
"constructor": {"type": "number"}
}
},
"tests": [
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores other non-objects",
"data": 12,
"valid": true
},
{
"description": "none of the properties mentioned",
"data": {},
"valid": true
},
{
"description": "__proto__ not valid",
"data": { "__proto__": "foo" },
"valid": false
},
{
"description": "toString not valid",
"data": { "toString": { "length": 37 } },
"valid": false
},
{
"description": "constructor not valid",
"data": { "constructor": { "length": 37 } },
"valid": false
},
{
"description": "all present and valid",
"data": {
"__proto__": 12,
"toString": { "length": "foo" },
"constructor": 37
},
"valid": true
}
]
}
]
Loading

0 comments on commit 597b1fb

Please sign in to comment.