Skip to content

Commit

Permalink
173 Updates TZP dapp to sanitize network type at all possible inputs,…
Browse files Browse the repository at this point in the history
… adds explicit checks for vec access in worker
  • Loading branch information
krhoda committed Dec 2, 2021
1 parent 758b89d commit 955a310
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 306 deletions.
6 changes: 4 additions & 2 deletions dapp/src/routes/Search/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { useNavigate } from 'svelte-navigator';
import { onMount } from 'svelte';
import { defaultSearchOpts, search, network, alert } from 'src/store';
import type NetworkType from 'enumsNetworkType';
import NetworkType from 'enums/NetworkType';
import { findAddressFromDomain } from './searchHelper';
import './search.scss';
Expand All @@ -32,7 +32,9 @@
};
const setSelectedNetwork = () => {
network.set(localNetwork as NetworkType);
if (Object.values(NetworkType).includes(localNetwork as NetworkType)) {
network.set(localNetwork as NetworkType);
}
};
const searchProfiles = async () => {
Expand Down
12 changes: 8 additions & 4 deletions dapp/src/routes/View.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
search,
network,
} from 'src/store';
import type NetworkType from 'enumsNetworkType';
import NetworkType from 'enums/NetworkType';
import { BasePage, LoadingSpinner, PublicProfileView } from 'components';
const params = useParams();
Expand All @@ -21,9 +21,13 @@
onMount(() => {
// TODO: Generalize over claim types?
if (!$searchClaims?.basic.content || !$searchClaims?.twitter.content) {
network.set(
($params.network as NetworkType) || ('mainnet' as NetworkType)
);
const n = $params.network;
if (Object.values(NetworkType).includes(n as NetworkType)) {
network.set(n as NetworkType);
} else {
network.set(NetworkType.MAINNET)
}
fetching = true;
search($params.address, defaultSearchOpts).finally(() => {
fetching = false;
Expand Down
17 changes: 11 additions & 6 deletions dapp/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,13 @@ wallet.subscribe((w) => {
}
});

network.subscribe((network) => {
if (network === NetworkType.CUSTOM) {
network.subscribe((n) => {
if (!Object.values(NetworkType).includes(n as NetworkType)) {
network.set(NetworkType.MAINNET)
return
}

if (n === NetworkType.CUSTOM) {
networkStr.set('custom');
// TODO can't read from writeable, but then I don't understand why others work.
networkStrTemp = 'custom';
Expand All @@ -404,12 +409,12 @@ network.subscribe((network) => {
tzktBaseTemp = 'http://localhost:5000';
tzktBase.set(tzktBaseTemp);
} else {
networkStr.set(network);
networkStr.set(n);
// TODO can't read from writeable, but then I don't understand why others work.
networkStrTemp = network;
strNetwork = network;
networkStrTemp = n;
strNetwork = n;

urlNode = `https://${network}.api.tez.ie/`;
urlNode = `https://${n}.api.tez.ie/`;
nodeUrl.set(urlNode);

tzktBaseTemp = `https://api.${networkStrTemp}.tzkt.io`;
Expand Down
Loading

0 comments on commit 955a310

Please sign in to comment.