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

fix: sanitized query strings on the website #240

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
"gh-pages": "^3.2.3",
"highlight.js": "^11.2.0",
"parcel": "^2.11.0",
"path-browserify": "^1.0.0",
"posthtml": "^0.16.5",
"posthtml-doctype": "^1.1.1",
"posthtml-include": "^1.7.2",
"posthtml-modules": "^0.7.4",
"path-browserify": "^1.0.0",
"process": "^0.11.10",
"sass": "^1.23.6",
"vm-browserify": "^1.1.2"
Expand Down
4 changes: 2 additions & 2 deletions docs/ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ loadIcons('./spectrum-css-icons.svg');
loadIcons('./spectrum-icons.svg');

// Import local Javascript functions
import {throttle} from './js/utils';
import {throttle, sanitizeQueryString} from './js/utils';
import {openPanelTab, openTab, openAppTab, openSideNavItem} from './js/tabs';
import toggleTooltip from './js/tooltip';

Expand All @@ -87,7 +87,7 @@ posthtml()

// Redirect for URL parameters
let url = new URL(window.location);
let params = new URLSearchParams(url.search.slice(1));
let params = new URLSearchParams(sanitizeQueryString(url.search.slice(1)));

if (params.has('colorKeys') || params.has('name')) {
let newURL;
Expand Down
3 changes: 2 additions & 1 deletion docs/ui/src/js/addFromURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ governing permissions and limitations under the License.
*/

import {addColorScaleUpdate} from './colorScale';
import {sanitizeQueryString} from './utils';

function addFromURLDialog() {
let button = document.getElementById('addFromURLButton');
Expand All @@ -33,7 +34,7 @@ function addFromURL() {
let value = input.value;

let url = new URL(value);
let params = new URLSearchParams(url.search.slice(1));
let params = new URLSearchParams(sanitizeQueryString(url.search.slice(1)));
let pathName = url.pathname;

let crs, ratios, mode;
Expand Down
4 changes: 2 additions & 2 deletions docs/ui/src/js/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {addColorScale} from './colorScale';
import {addRatioInputs, sortRatios} from './ratios';
import {getRandomColorName, getClosestColorName} from './predefinedColorNames';
import {baseScaleOptions} from './createBaseScaleOptions';
import {round} from './utils';
import {round, sanitizeQueryString} from './utils';
import {_theme, tempGray} from './initialTheme';

function paramSetup() {
let setFirstColorSmoothing = false;
let url = new URL(window.location);
let params = new URLSearchParams(url.search.slice(1));
let params = new URLSearchParams(sanitizeQueryString(url.search.slice(1)));
let themeBase = document.getElementById('themeBase');
let RATIOS;
let RATIOCOLORS;
Expand Down
16 changes: 15 additions & 1 deletion docs/ui/src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,19 @@ function colorPickerInput(e) {
}
}

function sanitizeQueryString(string) {
const map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;'
};
const reg = /[&<>"'/]/gi;
return string.replace(reg, (match) => map[match]);
}

module.exports = {
randomId,
throttle,
Expand Down Expand Up @@ -808,5 +821,6 @@ module.exports = {
getChannelsAndFunction,
orderColorsByLuminosity,
shuffleArray,
colorPickerInput
colorPickerInput,
sanitizeQueryString
};
4 changes: 2 additions & 2 deletions docs/ui/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import ClipboardJS from 'clipboard';
// Import local Javascript functions
import {_theme} from './js/initialTheme';
import {paramSetup} from './js/params';
import {throttle} from './js/utils';
import {throttle, sanitizeQueryString} from './js/utils';
import {getThemeContrastRatios, getContrastRatioInputs} from './js/getThemeData';
import {addColorScale, addColorScaleUpdate} from './js/colorScale';
import {addColorsFromImage} from './js/addColorsFromImage';
Expand Down Expand Up @@ -132,7 +132,7 @@ function updateParams() {
formula: _theme.formula
};
let url = new URL(window.location);
let params = new URLSearchParams(url.search.slice(1));
let params = new URLSearchParams(sanitizeQueryString(url.search.slice(1)));

params.set('name', name); // Theme name
params.set('config', JSON.stringify(theme)); // Configurations
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.