Skip to content
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

feat: prevent special characters from url #1266

Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@
this.urlLoaded = true;
}

/**
* Detects if the user typing or pasting special/forbidden characters in some URL param.
*
* @internal
* @param urlValue - Param from the url that will be checked for special characters.
* @returns Param without special characters.
*/
protected hasSpecialKeys(urlValue: string): string {
lauramargar marked this conversation as resolved.
Show resolved Hide resolved
if (/[<>]/.test(urlValue ?? '')) {
let value = urlValue.replace(/<.*>/g, '');
Fixed Show fixed Hide fixed
if (!/</.test(value ?? '')) {
value = value.replace(/.*>/g, '');
} else if (!/>/.test(value ?? '')) {
value = value.replace(/<.*/g, '');
Fixed Show fixed Hide fixed
}
return value;
} else {
return urlValue;
}
}

/**
* Creates the wire metadata to include in every emitted {@link XEvent}.
*
Expand Down Expand Up @@ -255,10 +276,13 @@
const urlKey = this.getUrlKey(name);
if (urlSearchParams.has(urlKey)) {
if (name in initialUrlState) {
const urlValue = urlSearchParams.getAll(urlKey);
let urlValue = urlSearchParams.getAll(urlKey);
urlValue[0] = this.hasSpecialKeys(urlValue[0]);
params.all[name] = this.parseUrlParam(name, urlValue);
} else {
params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);
let urlValueExtra = urlSearchParams.get(urlKey);
urlValueExtra = this.hasSpecialKeys(urlValueExtra!);
params.all[name] = params.extra[name] = urlValueExtra;
}
}
return params;
Expand Down