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 @@ -13,6 +13,7 @@
import { FeatureLocation } from '../../../types/origin';
import { UrlParams } from '../../../types/url-params';
import { isArrayEmpty } from '../../../utils/array';
import { sanitize } from '../../../utils/index';
import { WireMetadata } from '../../../wiring/wiring.types';
import { SnippetConfig } from '../../../x-installer/api/api.types';
import { initialUrlState } from '../store/initial-state';
Expand Down Expand Up @@ -255,10 +256,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] = sanitize(urlValue[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe we should sanitize all values and not just the first one. The query only has one occurrence but potentially any parameter could be malicious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urlValue is not only query param, all URL params are passing one by one. [0] is necessary because urlValue is an array of only one element, the param that is being checked.

For example, try to search for a query and select a filter, then write the special characters (<>) in the filter and in the query.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think I did not explain properly 😅 What I meant is that a url param can have more than one occurrence. Think about filters, you can select more than one filter at the same time. In that scenario you get an array with multiple entries like:

['categoryIds:12fad53d7', 'price:1600.0-2000.0']

so if you only pick the first element, you will fail to sanitize the other values.

params.all[name] = this.parseUrlParam(name, urlValue);
} else {
params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);
let urlValueExtra = urlSearchParams.get(urlKey);
urlValueExtra = sanitize(urlValueExtra!);
params.all[name] = params.extra[name] = urlValueExtra;
}
}
return params;
Expand Down