Skip to content

Commit

Permalink
fix: don't resolve paths to non-existent routes
Browse files Browse the repository at this point in the history
If the resolved path for a given locale is 404 then don't attempt to
change the path to locale specific. Avoids redirecting unnecessarily to
a route that doesn't exist anyway.

That also fixes the security issue with redirecting to a different
domain but just in case added an additional measure against that.

Resolves #1092
  • Loading branch information
rchl committed Mar 7, 2021
1 parent 4043968 commit 4e389bc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
2 changes: 1 addition & 1 deletion src/templates/plugin.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default async (context) => {
redirectPath = app.localePath(route.fullPath, locale)
}

if (redirectPath === route.fullPath) {
if (redirectPath === route.fullPath || redirectPath.startsWith('//')) {
return ''
}

Expand Down
14 changes: 0 additions & 14 deletions src/templates/plugin.routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ function localeRoute (route, locale) {
let localizedRoute = Object.assign({}, route)

if (route.path && !route.name) {
const isDefaultLocale = locale === defaultLocale
// if route has a path defined but no name, resolve full route using the path
const isPrefixed =
// don't prefix default locale
!(isDefaultLocale && [STRATEGIES.PREFIX_EXCEPT_DEFAULT, STRATEGIES.PREFIX_AND_DEFAULT].includes(strategy)) &&
// no prefix for any language
!(strategy === STRATEGIES.NO_PREFIX) &&
// no prefix for different domains
!i18n.differentDomains
const resolvedRoute = this.router.resolve(route.path).route
const resolvedRouteName = this.getRouteBaseName(resolvedRoute)
if (resolvedRouteName) {
Expand All @@ -70,11 +61,6 @@ function localeRoute (route, locale) {
query: resolvedRoute.query,
hash: resolvedRoute.hash
}
} else {
if (isPrefixed) {
localizedRoute.path = `/${locale}${route.path}`
}
localizedRoute.path = localizedRoute.path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/'
}
} else {
if (!route.name && !route.path) {
Expand Down

0 comments on commit 4e389bc

Please sign in to comment.