@jsonapi-serde/server 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,6 +21,8 @@ export type SearchParamsInput = ConstructorParameters<typeof URLSearchParams>[0]
|
|
|
21
21
|
*
|
|
22
22
|
* Supports bracket and array notation like `user[address][city]=NY`.
|
|
23
23
|
*
|
|
24
|
+
* Any key parts named `__proto__`, `constructor` or `prototype` are skipped to prevent prototype pollution.
|
|
25
|
+
*
|
|
24
26
|
* @example
|
|
25
27
|
* ```ts
|
|
26
28
|
* parseSearchParams("foo[0]=bar&foo[1]=baz");
|
|
@@ -49,6 +49,8 @@ const filterEmptyItems = (current) => {
|
|
|
49
49
|
*
|
|
50
50
|
* Supports bracket and array notation like `user[address][city]=NY`.
|
|
51
51
|
*
|
|
52
|
+
* Any key parts named `__proto__`, `constructor` or `prototype` are skipped to prevent prototype pollution.
|
|
53
|
+
*
|
|
52
54
|
* @example
|
|
53
55
|
* ```ts
|
|
54
56
|
* parseSearchParams("foo[0]=bar&foo[1]=baz");
|
|
@@ -58,7 +60,7 @@ const filterEmptyItems = (current) => {
|
|
|
58
60
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Kept within one function for performance reasons
|
|
59
61
|
export const parseSearchParams = (input) => {
|
|
60
62
|
const searchParams = new URLSearchParams(input);
|
|
61
|
-
const result =
|
|
63
|
+
const result = Object.create(null);
|
|
62
64
|
for (const [key, value] of searchParams) {
|
|
63
65
|
const path = parseKey(key);
|
|
64
66
|
if (!path) {
|
|
@@ -82,6 +84,10 @@ export const parseSearchParams = (input) => {
|
|
|
82
84
|
: Array.isArray(current) && part === ""
|
|
83
85
|
? current.length
|
|
84
86
|
: part;
|
|
87
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
88
|
+
// Skip unsafe keys to prevent prototype pollution
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
85
91
|
if (isLast) {
|
|
86
92
|
current[key] = value;
|
|
87
93
|
continue;
|