Skip to content

Commit

Permalink
sanitize ULRs before parsing query params
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Oct 26, 2022
1 parent 6689b21 commit 799a6fe
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-dodos-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-shared': minor
---

Add `sanitizeURL` utility.
5 changes: 5 additions & 0 deletions .changeset/smart-rules-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-application-query': patch
'@finos/legend-extension-dsl-data-space': patch
'@finos/legend-shared': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import {
CheckIcon,
MenuContentItemLabel,
} from '@finos/legend-art';
import { debounce, getQueryParameters } from '@finos/legend-shared';
import {
debounce,
getQueryParameters,
sanitizeURL,
} from '@finos/legend-shared';
import { observer } from 'mobx-react-lite';
import { Fragment, useEffect, useMemo, useRef, useState } from 'react';
import {
Expand Down Expand Up @@ -645,7 +649,7 @@ export const ServiceQueryCreator = observer(() => {
const gav = params[LEGEND_QUERY_PATH_PARAM_TOKEN.GAV];
const servicePath = params[LEGEND_QUERY_PATH_PARAM_TOKEN.SERVICE_PATH];
const executionKey = getQueryParameters<ServiceQueryCreatorQueryParams>(
applicationStore.navigator.getCurrentAddress(),
sanitizeURL(applicationStore.navigator.getCurrentAddress()),
true,
)[LEGEND_QUERY_QUERY_PARAM_TOKEN.SERVICE_EXECUTION_KEY];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
CheckIcon,
MenuContentDivider,
} from '@finos/legend-art';
import { getQueryParameters, guaranteeNonNullable } from '@finos/legend-shared';
import {
getQueryParameters,
guaranteeNonNullable,
sanitizeURL,
} from '@finos/legend-shared';
import { observer, useLocalObservable } from 'mobx-react-lite';
import React, { createContext, useContext, useEffect } from 'react';
import {
Expand Down Expand Up @@ -251,7 +255,7 @@ export const QuerySetupLandingPage = withQuerySetupLandingPageStore(
const setupStore = useQuerySetupLandingPageStore();
const applicationStore = useLegendQueryApplicationStore();
const params = getQueryParameters<QuerySetupQueryParams>(
applicationStore.navigator.getCurrentAddress(),
sanitizeURL(applicationStore.navigator.getCurrentAddress()),
true,
);
const showAdvancedActions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { observer, useLocalObservable } from 'mobx-react-lite';
import { getQueryParameters } from '@finos/legend-shared';
import { getQueryParameters, sanitizeURL } from '@finos/legend-shared';
import { useApplicationStore, useParams } from '@finos/legend-application';
import { useDepotServerClient } from '@finos/legend-server-depot';
import {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const DataSpaceQueryCreator = observer(() => {
params[DATA_SPACE_QUERY_CREATOR_PATH_PARAM_TOKEN.EXECUTION_CONTEXT];
const runtimePath = params[LEGEND_QUERY_PATH_PARAM_TOKEN.RUNTIME_PATH];
const classPath = getQueryParameters<DataSpaceQueryEditorQueryParams>(
applicationStore.navigator.getCurrentAddress(),
sanitizeURL(applicationStore.navigator.getCurrentAddress()),
true,
)[DATA_SPACE_QUERY_CREATOR_QUERY_PARAM_TOKEN.CLASS_PATH];

Expand Down
1 change: 1 addition & 0 deletions packages/legend-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test:watch": "jest --watch"
},
"dependencies": {
"@braintree/sanitize-url": "6.0.1",
"@types/lodash-es": "4.17.6",
"@types/object-hash": "2.2.1",
"@types/pako": "2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/legend-shared/src/network/NetworkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
stringify as _stringifyQueryParams,
} from 'query-string';
import { returnUndefOnError } from '../error/ErrorUtils.js';
import { sanitizeUrl } from '@braintree/sanitize-url';

/**
* Unlike the download call (GET requests) which is gziped, the upload call send uncompressed data which is in megabytes realms
Expand Down Expand Up @@ -554,3 +555,5 @@ export const buildUrl = (parts: string[]): string =>
parts
.map((part) => part.replaceAll(/^\/+/g, '').replaceAll(/\/+$/g, ''))
.join(URL_SEPARATOR);

export const sanitizeURL = (val: string): string => sanitizeUrl(val);
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,13 @@ __metadata:
languageName: node
linkType: hard

"@braintree/sanitize-url@npm:6.0.1":
version: 6.0.1
resolution: "@braintree/sanitize-url@npm:6.0.1"
checksum: 6f9221299aac0c841a17ecb1ebc60eb43c794f05b5136ca9b87116c8472b7e96f21e56ba2da8369f964112c6055fab791a37015bbea4bd5a189cc38206d214ad
languageName: node
linkType: hard

"@changesets/apply-release-plan@npm:^6.1.1":
version: 6.1.1
resolution: "@changesets/apply-release-plan@npm:6.1.1"
Expand Down Expand Up @@ -2987,6 +2994,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@finos/legend-shared@workspace:packages/legend-shared"
dependencies:
"@braintree/sanitize-url": 6.0.1
"@finos/legend-dev-utils": "workspace:*"
"@jest/globals": 29.2.2
"@types/lodash-es": 4.17.6
Expand Down

0 comments on commit 799a6fe

Please sign in to comment.