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: validate contract path #570

Merged
merged 1 commit into from
Nov 2, 2023
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
57 changes: 41 additions & 16 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import InteractTab from '@/views/contract/InteractTab.vue'
import ViewsTab from '@/views/contract/ViewsTab/ViewsTab.vue'
import StorageTab from '@/views/contract/StorageTab.vue'
import ContractTokensTab from '@/views/contract/TokensTab/TokensTab.vue'
import TransfersTab from '@/views/contract/TransfersTab/TransfersTab.vue'
import MetadataTab from '@/views/contract/MetadataTab/MetadataTab.vue'
import ForkTab from '@/views/contract/ForkTab.vue'
import EventsTab from '@/views/contract/EventsTab/EventsTab.vue'
Expand All @@ -38,6 +37,8 @@ import ConstantTab from "@/views/constant/ConstantTab";
import Constant from "@/views/constant/Constant";
import ContractStatsTab from "@/views/contract/StatsTab.vue";

import {checkAddress, isKT1Address} from '@/utils/tz.js'

Vue.use(VueRouter)

function validateNetwork(networks) {
Expand All @@ -49,6 +50,27 @@ function validateNetwork(networks) {
}
}


function validateAddress(networks) {
return function(to, _from, next) {
if (networks.indexOf(to.params.network) == -1 || !checkAddress(to.params.address)) {
next('/not_found');
} else {
next();
}
}
}

function validateContractAddress() {
return function(to, _from, next) {
if (!isKT1Address(to.params.address)) {
next('/not_found');
} else {
next();
}
}
}

export function newRouter(networks) {
return new Router({
linkActiveClass: '',
Expand Down Expand Up @@ -139,8 +161,8 @@ export function newRouter(networks) {
]
},
{
path: '/:network/:address([0-9A-z]{36})',
beforeEnter: validateNetwork(networks),
path: '/:network/:address',
beforeEnter: validateAddress(networks),
components: {
default: Contract,
},
Expand Down Expand Up @@ -173,19 +195,22 @@ export function newRouter(networks) {
path: 'interact/:entrypoint?',
name: 'interact',
component: InteractTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'views/:view?',
name: 'views',
component: ViewsTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'storage',
name: 'storage',
component: StorageTab,
props: true,
beforeEnter: validateContractAddress(),
children: [
{
path: 'big_map/:ptr(\\d+)',
Expand Down Expand Up @@ -219,13 +244,15 @@ export function newRouter(networks) {
path: 'code',
name: 'code',
component: CodeTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'metadata',
name: 'metadata',
component: MetadataTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'fork',
Expand All @@ -234,30 +261,28 @@ export function newRouter(networks) {
default: ForkTab,
},
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'tokens',
name: 'tokens',
component: ContractTokensTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'stats',
name: 'contract_stats',
component: ContractStatsTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
{
path: 'details',
name: 'details',
component: DetailsTab,
props: true
},
{
path: 'transfers',
name: 'transfers',
component: TransfersTab,
props: true
props: true,
beforeEnter: validateContractAddress(),
},
]
},
Expand Down
40 changes: 0 additions & 40 deletions src/views/contract/TransfersTab/TransfersTab.vue

This file was deleted.

Loading