File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
app/(global)/~gitbook/image Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' gitbook ' : minor
3
+ ---
4
+
5
+ Image optimization endpoint redirects to underlying image URL if the signature is not the latest.
Original file line number Diff line number Diff line change 1
1
import { NextRequest } from 'next/server' ;
2
2
3
- import { isSignatureVersion , SignatureVersion , verifyImageSignature } from '@/lib/image-signatures' ;
3
+ import {
4
+ CURRENT_SIGNATURE_VERSION ,
5
+ isSignatureVersion ,
6
+ SignatureVersion ,
7
+ verifyImageSignature ,
8
+ } from '@/lib/image-signatures' ;
4
9
import { resizeImage , CloudflareImageOptions , checkIsSizableImageURL } from '@/lib/images' ;
5
10
import { parseImageAPIURL } from '@/lib/urls' ;
6
11
@@ -39,6 +44,10 @@ export async function GET(request: NextRequest) {
39
44
return new Response ( `Invalid signature "${ signature ?? '' } " for "${ url } "` , { status : 400 } ) ;
40
45
}
41
46
47
+ if ( signatureVersion !== CURRENT_SIGNATURE_VERSION ) {
48
+ return Response . redirect ( url , 302 ) ;
49
+ }
50
+
42
51
// Cloudflare-specific options are in the cf object.
43
52
const options : CloudflareImageOptions = {
44
53
fit : 'scale-down' ,
Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ import { host } from './links';
11
11
*/
12
12
export type SignatureVersion = '0' | '1' | '2' ;
13
13
14
+ /**
15
+ * The current version of the signature.
16
+ */
17
+ export const CURRENT_SIGNATURE_VERSION : SignatureVersion = '2' ;
18
+
14
19
/**
15
20
* A mapping of signature versions to signature functions.
16
21
*/
@@ -48,7 +53,7 @@ export function generateImageSignature(input: string): {
48
53
version : SignatureVersion ;
49
54
} {
50
55
const result = generateSignatureV2 ( input ) ;
51
- return { signature : result , version : '2' } ;
56
+ return { signature : result , version : CURRENT_SIGNATURE_VERSION } ;
52
57
}
53
58
54
59
// Reused buffer for FNV-1a hashing in the v2 algorithm
You can’t perform that action at this time.
0 commit comments