-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcdc864
commit b54023a
Showing
4 changed files
with
95 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 24 additions & 31 deletions
55
packages/workflow-core/src/lib/plugins/external-plugin/api-plugin/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
import get from 'lodash.get'; | ||
import validator from 'validator'; | ||
|
||
export const isBrowser = () => typeof window !== 'undefined'; | ||
|
||
export const getGlobalQueryParams = () => { | ||
if (!isBrowser()) return {}; | ||
|
||
const searchParams = new URLSearchParams(window.location.search); | ||
const paramsObject: Record<string, string> = {}; | ||
|
||
searchParams.forEach((value, key) => { | ||
paramsObject[key] = value; | ||
}); | ||
|
||
return paramsObject; | ||
/** | ||
* Sanitizes query parameter values to prevent XSS and injection attacks | ||
*/ | ||
export const sanitizeQueryParam = (param: string): string => { | ||
return validator.escape(param.trim()); | ||
}; | ||
|
||
export const formatStringValues = ( | ||
str: string, | ||
data: Record<string, string | Record<string, string>>, | ||
) => { | ||
// Find all placeholders in curly braces | ||
const placeholders = str.match(/{(.*?)}/g); | ||
|
||
if (!placeholders) return str; | ||
|
||
let formattedString = str; | ||
|
||
// Replace each placeholder with its value from data | ||
for (const placeholder of placeholders) { | ||
const path = placeholder.replace(/{|}/g, ''); // Remove curly braces | ||
const value = get(data, path); | ||
export const getGlobalQueryParams = (): Record<string, string | string[]> => { | ||
if (!isBrowser()) return {}; | ||
|
||
// Replace placeholder with value if found | ||
if (value !== undefined) { | ||
formattedString = formattedString.replace(placeholder, String(value)); | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const paramsObject: Record<string, string | string[]> = {}; | ||
|
||
// Handle multiple values for the same parameter | ||
for (const [key, value] of searchParams.entries()) { | ||
const sanitizedValue = sanitizeQueryParam(value); | ||
const sanitizedKey = sanitizeQueryParam(key); | ||
|
||
if (sanitizedKey in paramsObject) { | ||
const existing = paramsObject[sanitizedKey]; | ||
paramsObject[sanitizedKey] = Array.isArray(existing) | ||
? [...existing, sanitizedValue] | ||
: [existing as string, sanitizedValue]; | ||
} else { | ||
paramsObject[sanitizedKey] = sanitizedValue; | ||
} | ||
} | ||
|
||
return formattedString; | ||
return paramsObject; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.