mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 02:53:29 +00:00
Update site redirect regex for validation (#3216)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Update the regex for validating site redirect
|
||||||
@@ -69,7 +69,11 @@ async function resolvePage(context: GitBookSiteContext, params: PagePathParams |
|
|||||||
|
|
||||||
// If a page still can't be found, we try with the API, in case we have a redirect at site level.
|
// If a page still can't be found, we try with the API, in case we have a redirect at site level.
|
||||||
const redirectPathname = withLeadingSlash(rawPathname);
|
const redirectPathname = withLeadingSlash(rawPathname);
|
||||||
if (/^\/[a-zA-Z0-9-_.\/]+[a-zA-Z0-9-_.]$/.test(redirectPathname)) {
|
if (
|
||||||
|
/^\/(?:[A-Za-z0-9\-._~]|%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~]|%[0-9A-Fa-f]{2})+)*$/.test(
|
||||||
|
redirectPathname
|
||||||
|
)
|
||||||
|
) {
|
||||||
const redirectSources = new Set<string>([
|
const redirectSources = new Set<string>([
|
||||||
// Test the pathname relative to the root
|
// Test the pathname relative to the root
|
||||||
// For example hello/world -> section/variant/hello/world
|
// For example hello/world -> section/variant/hello/world
|
||||||
|
|||||||
@@ -765,7 +765,12 @@ export const getComputedDocument = cache({
|
|||||||
* Mimic the validation done on source server-side to reduce API usage.
|
* Mimic the validation done on source server-side to reduce API usage.
|
||||||
*/
|
*/
|
||||||
function validateSiteRedirectSource(source: string) {
|
function validateSiteRedirectSource(source: string) {
|
||||||
return source.length <= 512 && /^\/[a-zA-Z0-9-_.\\/]+[a-zA-Z0-9-_.]$/.test(source);
|
return (
|
||||||
|
source.length <= 512 &&
|
||||||
|
/^\/(?:[A-Za-z0-9\-._~]|%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~]|%[0-9A-Fa-f]{2})+)*$/.test(
|
||||||
|
source
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user