-
Notifications
You must be signed in to change notification settings - Fork 43
Fix handling of Maps and other non plain object types #970
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
base: main
Are you sure you want to change the base?
Changes from all commits
eb7f085
f9293dc
6d907cd
d1e099f
cf80e30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,3 @@ | ||||||||||||
| import { isPlainObject } from "./isPlainObject"; | ||||||||||||
| import { safeDecodeURIComponent } from "./safeDecodeURIComponent"; | ||||||||||||
| import { tryDecodeAsJWT } from "./tryDecodeAsJWT"; | ||||||||||||
| import { tryParseURL } from "./tryParseURL"; | ||||||||||||
|
|
@@ -21,13 +20,51 @@ export function extractStringsFromUserInput( | |||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (isPlainObject(obj)) { | ||||||||||||
| for (const key in obj) { | ||||||||||||
| if (obj instanceof Map) { | ||||||||||||
| for (const [key, value] of obj.entries()) { | ||||||||||||
| if (typeof key === "string") { | ||||||||||||
| results.add(key); | ||||||||||||
| } | ||||||||||||
| extractStringsFromUserInput(value, depth + 1).forEach((v) => | ||||||||||||
| results.add(v) | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (obj instanceof Set) { | ||||||||||||
| for (const value of obj.values()) { | ||||||||||||
| extractStringsFromUserInput(value, depth + 1).forEach((v) => | ||||||||||||
| results.add(v) | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (obj instanceof URLSearchParams) { | ||||||||||||
| for (const [key, value] of obj.entries()) { | ||||||||||||
| results.add(key); | ||||||||||||
| extractStringsFromUserInput(obj[key], depth + 1).forEach((value) => { | ||||||||||||
| results.add(value); | ||||||||||||
| }); | ||||||||||||
| results.add(value); | ||||||||||||
| } | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (globalThis.FormData && obj instanceof globalThis.FormData) { | ||||||||||||
| obj.forEach((value, key) => { | ||||||||||||
| results.add(key); | ||||||||||||
| if (typeof value === "string") { | ||||||||||||
| results.add(value); | ||||||||||||
| } | ||||||||||||
| }); | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (globalThis.Headers && obj instanceof globalThis.Headers) { | ||||||||||||
| obj.forEach((value, key) => { | ||||||||||||
| results.add(key); | ||||||||||||
| results.add(value); | ||||||||||||
| }); | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (Array.isArray(obj)) { | ||||||||||||
|
|
@@ -46,6 +83,7 @@ export function extractStringsFromUserInput( | |||||||||||
| // Ignore deeply nested/cyclic arrays that can overflow during native join recursion. | ||||||||||||
| // We still keep strings gathered from traversed elements above. | ||||||||||||
| } | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (typeof obj === "string" && obj.length > 0) { | ||||||||||||
|
|
@@ -75,6 +113,35 @@ export function extractStringsFromUserInput( | |||||||||||
| results.add(value); | ||||||||||||
| }); | ||||||||||||
| } | ||||||||||||
| return results; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) { | ||||||||||||
| try { | ||||||||||||
| for (const key of Reflect.ownKeys(obj)) { | ||||||||||||
| const descriptor = Object.getOwnPropertyDescriptor(obj, key); | ||||||||||||
| if (!descriptor || !("value" in descriptor)) { | ||||||||||||
| continue; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Ignore function names | ||||||||||||
| if (typeof descriptor.value === "function") { | ||||||||||||
| continue; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (typeof key === "string" && key.length > 0) { | ||||||||||||
| results.add(key); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| extractStringsFromUserInput(descriptor.value, depth + 1).forEach( | ||||||||||||
| (value) => { | ||||||||||||
| results.add(value); | ||||||||||||
| } | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| } catch { | ||||||||||||
| // Ignore errors | ||||||||||||
|
Comment on lines
+142
to
+143
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent catch in extractStringsFromUserInput swallows errors from the Reflect.ownKeys/Object.getOwnPropertyDescriptor loop; add logging or handle specific error cases instead of ignoring. Show fix
Suggested change
Details✨ AI Reasoning This finding points to the empty/silent catch introduced for the reflective iteration. Consider adding targeted error handling, logging, or restricting which objects are inspected to avoid silent failures. Reply |
||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return results; | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.