Skip to content

Commit 597b1fb

Browse files
committed
Ensure JS implementations don't traverse the prototype chain.
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]>
1 parent 0015d52 commit 597b1fb

File tree

12 files changed

+600
-0
lines changed

12 files changed

+600
-0
lines changed

tests/draft-next/properties.json

+54
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,59 @@
178178
"valid": true
179179
}
180180
]
181+
},
182+
{
183+
"description": "properties whose names are Javascript object property names",
184+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
185+
"schema": {
186+
"properties": {
187+
"__proto__": {"type": "number"},
188+
"toString": {
189+
"properties": { "length": { "type": "string" } }
190+
},
191+
"constructor": {"type": "number"}
192+
}
193+
},
194+
"tests": [
195+
{
196+
"description": "ignores arrays",
197+
"data": [],
198+
"valid": true
199+
},
200+
{
201+
"description": "ignores other non-objects",
202+
"data": 12,
203+
"valid": true
204+
},
205+
{
206+
"description": "none of the properties mentioned",
207+
"data": {},
208+
"valid": true
209+
},
210+
{
211+
"description": "__proto__ not valid",
212+
"data": { "__proto__": "foo" },
213+
"valid": false
214+
},
215+
{
216+
"description": "toString not valid",
217+
"data": { "toString": { "length": 37 } },
218+
"valid": false
219+
},
220+
{
221+
"description": "constructor not valid",
222+
"data": { "constructor": { "length": 37 } },
223+
"valid": false
224+
},
225+
{
226+
"description": "all present and valid",
227+
"data": {
228+
"__proto__": 12,
229+
"toString": { "length": "foo" },
230+
"constructor": 37
231+
},
232+
"valid": true
233+
}
234+
]
181235
}
182236
]

tests/draft-next/required.json

+46
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,51 @@
101101
"valid": false
102102
}
103103
]
104+
},
105+
{
106+
"description": "required properties whose names are Javascript object property names",
107+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
108+
"schema": { "required": ["__proto__", "toString", "constructor"] },
109+
"tests": [
110+
{
111+
"description": "ignores arrays",
112+
"data": [],
113+
"valid": true
114+
},
115+
{
116+
"description": "ignores other non-objects",
117+
"data": 12,
118+
"valid": true
119+
},
120+
{
121+
"description": "none of the properties mentioned",
122+
"data": {},
123+
"valid": false
124+
},
125+
{
126+
"description": "__proto__ present",
127+
"data": { "__proto__": "foo" },
128+
"valid": false
129+
},
130+
{
131+
"description": "toString present",
132+
"data": { "toString": { "length": 37 } },
133+
"valid": false
134+
},
135+
{
136+
"description": "constructor present",
137+
"data": { "constructor": { "length": 37 } },
138+
"valid": false
139+
},
140+
{
141+
"description": "all present",
142+
"data": {
143+
"__proto__": 12,
144+
"toString": { "length": "foo" },
145+
"constructor": 37
146+
},
147+
"valid": true
148+
}
149+
]
104150
}
105151
]

tests/draft2019-09/properties.json

+54
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,59 @@
178178
"valid": true
179179
}
180180
]
181+
},
182+
{
183+
"description": "properties whose names are Javascript object property names",
184+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
185+
"schema": {
186+
"properties": {
187+
"__proto__": {"type": "number"},
188+
"toString": {
189+
"properties": { "length": { "type": "string" } }
190+
},
191+
"constructor": {"type": "number"}
192+
}
193+
},
194+
"tests": [
195+
{
196+
"description": "ignores arrays",
197+
"data": [],
198+
"valid": true
199+
},
200+
{
201+
"description": "ignores other non-objects",
202+
"data": 12,
203+
"valid": true
204+
},
205+
{
206+
"description": "none of the properties mentioned",
207+
"data": {},
208+
"valid": true
209+
},
210+
{
211+
"description": "__proto__ not valid",
212+
"data": { "__proto__": "foo" },
213+
"valid": false
214+
},
215+
{
216+
"description": "toString not valid",
217+
"data": { "toString": { "length": 37 } },
218+
"valid": false
219+
},
220+
{
221+
"description": "constructor not valid",
222+
"data": { "constructor": { "length": 37 } },
223+
"valid": false
224+
},
225+
{
226+
"description": "all present and valid",
227+
"data": {
228+
"__proto__": 12,
229+
"toString": { "length": "foo" },
230+
"constructor": 37
231+
},
232+
"valid": true
233+
}
234+
]
181235
}
182236
]

tests/draft2019-09/required.json

+46
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,51 @@
101101
"valid": false
102102
}
103103
]
104+
},
105+
{
106+
"description": "required properties whose names are Javascript object property names",
107+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
108+
"schema": { "required": ["__proto__", "toString", "constructor"] },
109+
"tests": [
110+
{
111+
"description": "ignores arrays",
112+
"data": [],
113+
"valid": true
114+
},
115+
{
116+
"description": "ignores other non-objects",
117+
"data": 12,
118+
"valid": true
119+
},
120+
{
121+
"description": "none of the properties mentioned",
122+
"data": {},
123+
"valid": false
124+
},
125+
{
126+
"description": "__proto__ present",
127+
"data": { "__proto__": "foo" },
128+
"valid": false
129+
},
130+
{
131+
"description": "toString present",
132+
"data": { "toString": { "length": 37 } },
133+
"valid": false
134+
},
135+
{
136+
"description": "constructor present",
137+
"data": { "constructor": { "length": 37 } },
138+
"valid": false
139+
},
140+
{
141+
"description": "all present",
142+
"data": {
143+
"__proto__": 12,
144+
"toString": { "length": "foo" },
145+
"constructor": 37
146+
},
147+
"valid": true
148+
}
149+
]
104150
}
105151
]

tests/draft2020-12/properties.json

+54
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,59 @@
178178
"valid": true
179179
}
180180
]
181+
},
182+
{
183+
"description": "properties whose names are Javascript object property names",
184+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
185+
"schema": {
186+
"properties": {
187+
"__proto__": {"type": "number"},
188+
"toString": {
189+
"properties": { "length": { "type": "string" } }
190+
},
191+
"constructor": {"type": "number"}
192+
}
193+
},
194+
"tests": [
195+
{
196+
"description": "ignores arrays",
197+
"data": [],
198+
"valid": true
199+
},
200+
{
201+
"description": "ignores other non-objects",
202+
"data": 12,
203+
"valid": true
204+
},
205+
{
206+
"description": "none of the properties mentioned",
207+
"data": {},
208+
"valid": true
209+
},
210+
{
211+
"description": "__proto__ not valid",
212+
"data": { "__proto__": "foo" },
213+
"valid": false
214+
},
215+
{
216+
"description": "toString not valid",
217+
"data": { "toString": { "length": 37 } },
218+
"valid": false
219+
},
220+
{
221+
"description": "constructor not valid",
222+
"data": { "constructor": { "length": 37 } },
223+
"valid": false
224+
},
225+
{
226+
"description": "all present and valid",
227+
"data": {
228+
"__proto__": 12,
229+
"toString": { "length": "foo" },
230+
"constructor": 37
231+
},
232+
"valid": true
233+
}
234+
]
181235
}
182236
]

tests/draft2020-12/required.json

+46
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,51 @@
101101
"valid": false
102102
}
103103
]
104+
},
105+
{
106+
"description": "required properties whose names are Javascript object property names",
107+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
108+
"schema": { "required": ["__proto__", "toString", "constructor"] },
109+
"tests": [
110+
{
111+
"description": "ignores arrays",
112+
"data": [],
113+
"valid": true
114+
},
115+
{
116+
"description": "ignores other non-objects",
117+
"data": 12,
118+
"valid": true
119+
},
120+
{
121+
"description": "none of the properties mentioned",
122+
"data": {},
123+
"valid": false
124+
},
125+
{
126+
"description": "__proto__ present",
127+
"data": { "__proto__": "foo" },
128+
"valid": false
129+
},
130+
{
131+
"description": "toString present",
132+
"data": { "toString": { "length": 37 } },
133+
"valid": false
134+
},
135+
{
136+
"description": "constructor present",
137+
"data": { "constructor": { "length": 37 } },
138+
"valid": false
139+
},
140+
{
141+
"description": "all present",
142+
"data": {
143+
"__proto__": 12,
144+
"toString": { "length": "foo" },
145+
"constructor": 37
146+
},
147+
"valid": true
148+
}
149+
]
104150
}
105151
]

tests/draft4/properties.json

+54
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,59 @@
147147
"valid": true
148148
}
149149
]
150+
},
151+
{
152+
"description": "properties whose names are Javascript object property names",
153+
"comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
154+
"schema": {
155+
"properties": {
156+
"__proto__": {"type": "number"},
157+
"toString": {
158+
"properties": { "length": { "type": "string" } }
159+
},
160+
"constructor": {"type": "number"}
161+
}
162+
},
163+
"tests": [
164+
{
165+
"description": "ignores arrays",
166+
"data": [],
167+
"valid": true
168+
},
169+
{
170+
"description": "ignores other non-objects",
171+
"data": 12,
172+
"valid": true
173+
},
174+
{
175+
"description": "none of the properties mentioned",
176+
"data": {},
177+
"valid": true
178+
},
179+
{
180+
"description": "__proto__ not valid",
181+
"data": { "__proto__": "foo" },
182+
"valid": false
183+
},
184+
{
185+
"description": "toString not valid",
186+
"data": { "toString": { "length": 37 } },
187+
"valid": false
188+
},
189+
{
190+
"description": "constructor not valid",
191+
"data": { "constructor": { "length": 37 } },
192+
"valid": false
193+
},
194+
{
195+
"description": "all present and valid",
196+
"data": {
197+
"__proto__": 12,
198+
"toString": { "length": "foo" },
199+
"constructor": 37
200+
},
201+
"valid": true
202+
}
203+
]
150204
}
151205
]

0 commit comments

Comments
 (0)