Skip to content

Commit

Permalink
fix: checkIsValidUrl before redirecting users
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick1904 committed Feb 11, 2022
1 parent 2d0175d commit eaaf54f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 99 deletions.
3 changes: 2 additions & 1 deletion packages/frontend/src/components/accounts/LinkdropLanding.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { selectAccountSlice } from '../../redux/slices/account';
import { actions as linkdropActions } from '../../redux/slices/linkdrop';
import { selectStatusMainLoader } from '../../redux/slices/status';
import { selectActionsPending } from '../../redux/slices/status';
import { checkIsValidUrl } from '../../utils/helper-api';
import AccountDropdown from '../common/AccountDropdown';
import Balance from '../common/balance/Balance';
import FormButton from '../common/FormButton';
Expand Down Expand Up @@ -98,7 +99,7 @@ class LinkdropLanding extends Component {
handleClaimNearDrop = async () => {
const { fundingContract, fundingKey, redirectTo, claimLinkdropToAccount, accountId, url, setLinkdropAmount } = this.props;
await claimLinkdropToAccount(fundingContract, fundingKey);
if (url?.redirectUrl) {
if (url?.redirectUrl && checkIsValidUrl(url?.redirectUrl)) {
window.location = `${url.redirectUrl}?accountId=${accountId}`;
} else {
setLinkdropAmount(this.state.balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
redirectTo,
clearAccountState
} from '../../../redux/actions/account';
import { checkIsValidUrl } from '../../../utils/helper-api';
import AutoImport from './AutoImport';


export function AutoImportWrapper({
secretKey,
accountId,
Expand All @@ -21,8 +23,8 @@ export function AutoImportWrapper({
const location = useSelector(getLocation);
const URLParams = parse(location.search);
const [recoveryFailed, setRecoveryFailed] = useState(false);
const successUrl = URLParams.success_url;
const failureUrl = URLParams.failure_url;
const successUrl = checkIsValidUrl(URLParams.success_url) ? URLParams.success_url : null;
const failureUrl = checkIsValidUrl(URLParams.failure_url) ? URLParams.failure_url : null;

useEffect(() => {
handleRecoverWithSecretKey();
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/redux/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DISABLE_CREATE_ACCOUNT } from '../../config';
import {
showAlert
} from '../../utils/alerts';
import { checkIsValidUrl } from '../../utils/helper-api';
import {
loadState,
saveState,
Expand Down Expand Up @@ -213,7 +214,9 @@ export const allowLogin = () => async (dispatch, getState) => {
parsedUrl.searchParams.set('public_key', publicKey);
}
parsedUrl.searchParams.set('all_keys', allKeys.join(','));
window.location = parsedUrl.href;
if (checkIsValidUrl(parsedUrl.href)) {
window.location = parsedUrl.href;
}
} else {
await dispatch(withAlert(addAccessKey(wallet.accountId, contractId, publicKey, false, methodNames), { data: { title } }));
dispatch(redirectTo('/authorized-apps', { globalAlertPreventClear: true }));
Expand Down Expand Up @@ -478,7 +481,7 @@ export const finishAccountSetup = () => async (dispatch, getState) => {
const redirectUrl = selectAccountUrlRedirectUrl(getState());
const accountId = selectAccountId(getState());

if (redirectUrl) {
if (redirectUrl && checkIsValidUrl(redirectUrl)) {
window.location = `${redirectUrl}?accountId=${accountId}`;
} else {
dispatch(redirectToApp('/'));
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/routes/LoginWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Mixpanel } from '../mixpanel/index';
import {
selectAccountLocalStorageAccountId
} from '../redux/slices/account';
import { checkIsValidUrl } from '../utils/helper-api';
import { LOCKUP_ACCOUNT_ID_SUFFIX } from '../utils/wallet';

export const LOGIN_ACCESS_TYPES = {
Expand All @@ -26,7 +27,7 @@ export function LoginWrapper() {
const URLParams = parse(location.search);
const contractId = URLParams.contract_id;
const publicKey = URLParams.public_key;
const failureUrl = URLParams.failure_url;
const failureUrl = checkIsValidUrl(URLParams.failure_url) ? URLParams.failure_url : null;
const invalidContractId = URLParams.invalidContractId;

const contractIdUrl = `${EXPLORER_URL}/accounts/${contractId}`;
Expand Down
13 changes: 13 additions & 0 deletions packages/frontend/src/utils/helper-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@ export async function getAccountIds(publicKey) {
controller = new AbortController();
return await fetch(`${ACCOUNT_HELPER_URL}/publicKey/${publicKey}/accounts`, { signal: controller.signal }).then((res) => res.json());
}

export function checkIsValidUrl(url) {
if (!url) {
return false;
}

const urlProtocol = new URL(url).protocol;
if (urlProtocol !== 'http:' && urlProtocol !== 'https:') {
return false;
}

return true;
}
101 changes: 8 additions & 93 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1119,14 +1119,6 @@
resolved "https://registry.yarnpkg.com/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz#98c23c950a3d9b6c8f0daed06da6c3af06981340"
integrity sha512-H9XAx3hc0BQHY6l+IFSWHDySypcXsvsuLhgYLUGywmJ5pswRVQJUHpOsobnLYp2ZUaUlKiKDrgWWhosOwAEM8Q==

"@hypnosphi/create-react-context@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@hypnosphi/create-react-context/-/create-react-context-0.3.1.tgz#f8bfebdc7665f5d426cba3753e0e9c7d3154d7c6"
integrity sha512-V1klUed202XahrWJLLOT3EXNeCpFHCcJntdFGI15ntCwau+jfT386w7OFTMaCqOgXUH1fa0w/I1oZs+i/Rfr0A==
dependencies:
gud "^1.0.0"
warning "^4.0.3"

"@iarna/toml@^2.2.0":
version "2.2.5"
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
Expand Down Expand Up @@ -2041,7 +2033,7 @@
integrity sha512-TUu1io4U1CzvV5gGzLMGwQLFuA7Hj/RmRD1y0Ys1MdCcyErBced/cLIymQJtC5zZTYW6JlbJTQ3EmZb+HUaG4g==
dependencies:
fs-extra "^10.0.0"
ini "^1.3.4"
ini "^2.0.0"
inquirer "^8.2.0"

"@nodelib/fs.scandir@2.1.5":
Expand Down Expand Up @@ -2356,7 +2348,6 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"


"@sentry/browser@^6.4.1":
version "6.16.1"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.16.1.tgz#4270ab0fbd1de425e339b3e7a364feb09f470a87"
Expand Down Expand Up @@ -2435,23 +2426,6 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@stardust-ui/react-component-event-listener@~0.38.0":
version "0.38.0"
resolved "https://registry.yarnpkg.com/@stardust-ui/react-component-event-listener/-/react-component-event-listener-0.38.0.tgz#1787faded94b40ad41226e6289baf13e701c6e7f"
integrity sha512-sIP/e0dyOrrlb8K7KWumfMxj/gAifswTBC4o68Aa+C/GA73ccRp/6W1VlHvF/dlOR4KLsA+5SKnhjH36xzPsWg==
dependencies:
"@babel/runtime" "^7.1.2"
prop-types "^15.7.2"

"@stardust-ui/react-component-ref@~0.38.0":
version "0.38.0"
resolved "https://registry.yarnpkg.com/@stardust-ui/react-component-ref/-/react-component-ref-0.38.0.tgz#52d555f2d5edd213c923c93a106f7de940e427ef"
integrity sha512-xjs6WnvJVueSIXMWw0C3oWIgAPpcD03qw43oGOjUXqFktvpNkB73JoKIhS4sCrtQxBdct75qqr4ZL6JiyPcESw==
dependencies:
"@babel/runtime" "^7.1.2"
prop-types "^15.7.2"
react-is "^16.6.3"

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down Expand Up @@ -3873,7 +3847,7 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

classnames@^2.2.5, classnames@^2.2.6:
classnames@^2.2.5:
version "2.3.1"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e"
integrity sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA==
Expand Down Expand Up @@ -4836,18 +4810,6 @@ dedent@0.7.0, dedent@^0.7.0:
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
integrity sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=

deep-equal@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.1.1.tgz#b5c98c942ceffaf7cb051e24e1434a25a2e6076a"
integrity sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==
dependencies:
is-arguments "^1.0.4"
is-date-object "^1.0.1"
is-regex "^1.0.4"
object-is "^1.0.1"
object-keys "^1.1.1"
regexp.prototype.flags "^1.2.0"

deep-extend@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
Expand Down Expand Up @@ -5707,7 +5669,7 @@ execa@^5.0.0:
signal-exit "^3.0.3"
strip-final-newline "^2.0.0"

exenv@^1.2.0, exenv@^1.2.2:
exenv@^1.2.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50=
Expand Down Expand Up @@ -6987,11 +6949,6 @@ ini@^1.3.2, ini@^1.3.4, ini@~1.3.0:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

ini@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5"
integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==

init-package-json@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/init-package-json/-/init-package-json-2.0.3.tgz#c8ae4f2a4ad353bcbc089e5ffe98a8f1a314e8fd"
Expand Down Expand Up @@ -7134,14 +7091,6 @@ is-accessor-descriptor@^1.0.0:
dependencies:
kind-of "^6.0.0"

is-arguments@^1.0.4:
version "1.1.1"
resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b"
integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==
dependencies:
call-bind "^1.0.2"
has-tostringtag "^1.0.0"

is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
Expand Down Expand Up @@ -7406,7 +7355,7 @@ is-reference@^1.2.1:
dependencies:
"@types/estree" "*"

is-regex@^1.0.4, is-regex@^1.0.5, is-regex@^1.1.0, is-regex@^1.1.3, is-regex@^1.1.4:
is-regex@^1.0.5, is-regex@^1.1.0, is-regex@^1.1.3, is-regex@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.4.tgz#eef5663cd59fa4c0ae339505323df6854bb15958"
integrity sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==
Expand Down Expand Up @@ -8034,11 +7983,6 @@ jpeg-js@^0.4.2:
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.3.tgz#6158e09f1983ad773813704be80680550eff977b"
integrity sha512-ru1HWKek8octvUHFHvE5ZzQ1yAsJmIvRdGWvSoKV52XKyuyYA437QWDttXT8eZXDSbuMpHlLzPDZUPd6idIz+Q==

jquery@x.*:
version "3.6.0"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==

js-sha256@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
Expand Down Expand Up @@ -8225,11 +8169,6 @@ just-curry-it@^3.1.0:
resolved "https://registry.yarnpkg.com/just-curry-it/-/just-curry-it-3.2.1.tgz#7bb18284c8678ed816bfc5c19e44400605fbe461"
integrity sha512-Q8206k8pTY7krW32cdmPsP+DqqLgWx/hYPSj9/+7SYqSqz7UuwPbfSe07lQtvuuaVyiSJveXk0E5RydOuWwsEg==

keyboard-key@^1.0.4:
version "1.1.0"
resolved "https://registry.yarnpkg.com/keyboard-key/-/keyboard-key-1.1.0.tgz#6f2e8e37fa11475bb1f1d65d5174f1b35653f5b7"
integrity sha512-qkBzPTi3rlAKvX7k0/ub44sqOfXeLc/jcnGGmj5c7BJpU8eDrEVPyhCvNYAaoubbsLm9uGWwQJO1ytQK1a9/dQ==

keypress@0.1.x:
version "0.1.0"
resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.1.0.tgz#4a3188d4291b66b4f65edb99f806aa9ae293592a"
Expand Down Expand Up @@ -9537,7 +9476,7 @@ object-inspect@~1.4.0:
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.4.1.tgz#37ffb10e71adaf3748d05f713b4c9452f402cbc4"
integrity sha512-wqdhLpfCUbEsoEwl3FXwGyv8ief1k/1aUdIPCqVnupM6e8l63BEJdiF/0swtn04/8p05tG/T0FrpTlfwvljOdw==

object-is@^1.0.1, object-is@^1.0.2, object-is@^1.1.2:
object-is@^1.0.2, object-is@^1.1.2:
version "1.1.5"
resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.5.tgz#b9deeaa5fc7f1846a0faecdceec138e5778f53ac"
integrity sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==
Expand Down Expand Up @@ -10276,11 +10215,6 @@ pngjs@^5.0.0:
resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-5.0.0.tgz#e79dd2b215767fd9c04561c01236df960bce7fbb"
integrity sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==

popper.js@^1.14.4:
version "1.16.1"
resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.16.1.tgz#2a223cb3dc7b6213d740e40372be40de43e65b1b"
integrity sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==

posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
Expand Down Expand Up @@ -11058,7 +10992,7 @@ react-helmet@^6.1.0:
react-fast-compare "^3.1.1"
react-side-effect "^2.1.0"

react-is@^16.13.1, react-is@^16.6.0, react-is@^16.6.3, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6:
react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down Expand Up @@ -11106,19 +11040,6 @@ react-phone-number-input@2.3.11:
react-lifecycles-compat "^3.0.4"
react-responsive-ui "^0.14.123"

react-popper@^1.3.4:
version "1.3.11"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-1.3.11.tgz#a2cc3f0a67b75b66cfa62d2c409f9dd1fcc71ffd"
integrity sha512-VSA/bS+pSndSF2fiasHK/PTEEAyOpX60+H5EPAjoArr8JGm+oihu4UbrqcEBpQibJxBVCpYyjAX7abJ+7DoYVg==
dependencies:
"@babel/runtime" "^7.1.2"
"@hypnosphi/create-react-context" "^0.3.1"
deep-equal "^1.1.1"
popper.js "^1.14.4"
prop-types "^15.6.1"
typed-styles "^0.0.7"
warning "^4.0.2"

react-redux@^7.2.4:
version "7.2.6"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.6.tgz#49633a24fe552b5f9caf58feb8a138936ddfe9aa"
Expand Down Expand Up @@ -11418,7 +11339,7 @@ regex-not@^1.0.0, regex-not@^1.0.2:
extend-shallow "^3.0.2"
safe-regex "^1.1.0"

regexp.prototype.flags@^1.2.0, regexp.prototype.flags@^1.3.1:
regexp.prototype.flags@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.1.tgz#7ef352ae8d159e758c0eadca6f8fcb4eef07be26"
integrity sha512-JiBdRBq91WlY7uRJ0ds7R+dU02i6LKi8r3BuQhNXn+kmeLN+EfHhfjqMRis1zJxnlu88hq/4dx0P2OP3APRTOA==
Expand Down Expand Up @@ -11800,7 +11721,6 @@ seamless-immutable@^7.1.3:
resolved "https://registry.yarnpkg.com/seamless-immutable/-/seamless-immutable-7.1.4.tgz#6e9536def083ddc4dea0207d722e0e80d0f372f8"
integrity sha512-XiUO1QP4ki4E2PHegiGAlu6r82o5A+6tRh7IkGGTVg/h+UoeX4nFBeCGPOhb4CYjvkqsfm/TUtvOMYC1xmV30A==


"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0, semver@^5.7.0, semver@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand Down Expand Up @@ -12994,11 +12914,6 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

typed-styles@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.7.tgz#93392a008794c4595119ff62dde6809dbc40a3d9"
integrity sha512-pzP0PWoZUhsECYjABgCGQlRGL1n7tOHsgwYv3oIiEpJwGhFTuty/YNeduxQYzXXa3Ge5BdT6sHYIQYpl4uJ+5Q==

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
Expand Down Expand Up @@ -13348,7 +13263,7 @@ walker@^1.0.7:
dependencies:
makeerror "1.0.12"

warning@^4.0.2, warning@^4.0.3:
warning@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"
integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==
Expand Down

0 comments on commit eaaf54f

Please sign in to comment.