| 1478 | } |
| 1479 | |
| 1480 | function filter(obj: any) { |
| 1481 | let next = [obj] |
| 1482 | |
| 1483 | while (next.length) { |
| 1484 | const nodes = next |
| 1485 | next = [] |
| 1486 | |
| 1487 | for (const node of nodes) { |
| 1488 | if (Object.prototype.hasOwnProperty.call(node, "__proto__")) { |
| 1489 | throw new SyntaxError("Object contains forbidden prototype property") |
| 1490 | } |
| 1491 | |
| 1492 | if ( |
| 1493 | Object.prototype.hasOwnProperty.call(node, "constructor") && |
| 1494 | Object.prototype.hasOwnProperty.call(node.constructor, "prototype") |
| 1495 | ) { |
| 1496 | throw new SyntaxError("Object contains forbidden prototype property") |
| 1497 | } |
| 1498 | |
| 1499 | for (const key in node) { |
| 1500 | const value = node[key] |
| 1501 | if (value && typeof value === "object") { |
| 1502 | next.push(value) |
| 1503 | } |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | return obj |
| 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * **Unsafe**: This function will throw an error if an insecure property is |