1
- import { ContentAPITokenPayload , GitBookAPI } from '@gitbook/api' ;
1
+ import { ContentAPITokenPayload , CustomizationThemeMode , GitBookAPI } from '@gitbook/api' ;
2
2
import { setTag , setContext } from '@sentry/nextjs' ;
3
3
import assertNever from 'assert-never' ;
4
4
import jwt from 'jsonwebtoken' ;
5
5
import type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies' ;
6
6
import { NextResponse , NextRequest } from 'next/server' ;
7
7
import hash from 'object-hash' ;
8
+ import rison from 'rison' ;
8
9
9
10
import {
10
11
PublishedContentWithCache ,
@@ -17,6 +18,7 @@ import {
17
18
DEFAULT_API_ENDPOINT ,
18
19
getPublishedContentSite ,
19
20
getSiteData ,
21
+ validateSerializedCustomization ,
20
22
} from '@/lib/api' ;
21
23
import { race } from '@/lib/async' ;
22
24
import { buildVersion } from '@/lib/build' ;
@@ -259,12 +261,12 @@ export async function middleware(request: NextRequest) {
259
261
}
260
262
261
263
const customization = url . searchParams . get ( 'customization' ) ;
262
- if ( customization ) {
264
+ if ( customization && validateSerializedCustomization ( customization ) ) {
263
265
headers . set ( 'x-gitbook-customization' , customization ) ;
264
266
}
265
267
266
268
const theme = url . searchParams . get ( 'theme' ) ;
267
- if ( theme ) {
269
+ if ( theme === CustomizationThemeMode . Dark || theme === CustomizationThemeMode . Light ) {
268
270
headers . set ( 'x-gitbook-theme' , theme ) ;
269
271
}
270
272
0 commit comments