Unverified Commit f111dc7f authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Use fast-jwt instead of jsonwebtoken (#100818)

`jsonwebtoken` still uses `SlowBuffer` and is thus incompatible with
Node.js 26 (`SlowBuffer` was removed):
https://github.com/auth0/node-jsonwebtoken/issues/992

Use https://npmx.dev/package/fast-jwt instead of
https://npmx.dev/package/jsonwebtoken.

https://npmx.dev/package/jose is ~~way bigger~~ only has async APIs
parent 4e03bf93
...@@ -71,7 +71,7 @@ const sharedExternals = [ ...@@ -71,7 +71,7 @@ const sharedExternals = [
'critters', 'critters',
'next/dist/compiled/node-html-parser', 'next/dist/compiled/node-html-parser',
'next/dist/compiled/compression', 'next/dist/compiled/compression',
'next/dist/compiled/jsonwebtoken', 'next/dist/compiled/fast-jwt',
'next/dist/compiled/@opentelemetry/api', 'next/dist/compiled/@opentelemetry/api',
'next/dist/compiled/@mswjs/interceptors/ClientRequest', 'next/dist/compiled/@mswjs/interceptors/ClientRequest',
'next/dist/compiled/ws', 'next/dist/compiled/ws',
......
...@@ -204,7 +204,6 @@ ...@@ -204,7 +204,6 @@
"@types/express-serve-static-core": "4.17.33", "@types/express-serve-static-core": "4.17.33",
"@types/fresh": "0.5.0", "@types/fresh": "0.5.0",
"@types/glob": "7.1.1", "@types/glob": "7.1.1",
"@types/jsonwebtoken": "9.0.0",
"@types/lodash": "4.14.198", "@types/lodash": "4.14.198",
"@types/lodash.curry": "4.1.6", "@types/lodash.curry": "4.1.6",
"@types/path-to-regexp": "1.7.0", "@types/path-to-regexp": "1.7.0",
...@@ -266,6 +265,7 @@ ...@@ -266,6 +265,7 @@
"domain-browser": "4.19.0", "domain-browser": "4.19.0",
"edge-runtime": "4.0.1", "edge-runtime": "4.0.1",
"events": "3.3.0", "events": "3.3.0",
"fast-jwt": "6.3.5",
"find-up": "4.1.0", "find-up": "4.1.0",
"fresh": "0.5.2", "fresh": "0.5.2",
"glob": "7.1.7", "glob": "7.1.7",
...@@ -283,7 +283,6 @@ ...@@ -283,7 +283,6 @@
"is-wsl": "2.2.0", "is-wsl": "2.2.0",
"jest-worker": "27.5.1", "jest-worker": "27.5.1",
"json5": "2.2.3", "json5": "2.2.3",
"jsonwebtoken": "9.0.0",
"loader-runner": "4.3.0", "loader-runner": "4.3.0",
"loader-utils2": "npm:loader-utils@2.0.4", "loader-utils2": "npm:loader-utils@2.0.4",
"loader-utils3": "npm:loader-utils@3.1.3", "loader-utils3": "npm:loader-utils@3.1.3",
......
Copyright 2020-2021 nearForm
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This source diff could not be displayed because it is too large. You can view the blob instead.
{"name":"fast-jwt","main":"index.js","author":"NearForm Ltd","license":"Apache-2.0"}
The MIT License (MIT)
Copyright (c) 2015 Auth0, Inc. <support@auth0.com> (http://auth0.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This source diff could not be displayed because it is too large. You can view the blob instead.
{"name":"jsonwebtoken","main":"index.js","author":"auth0","license":"MIT"}
// DO NOT MODIFY THIS FILE DIRECTLY
// It's for aliasing the `semver` package to be a noop for the `jsonwebtoken` package.
// We're trying to minimize the size of the worker bundle.
export function satisfies() {
return true
}
...@@ -180,25 +180,24 @@ function setPreviewData<T>( ...@@ -180,25 +180,24 @@ function setPreviewData<T>(
throw new Error('invariant: invalid previewModeSigningKey') throw new Error('invariant: invalid previewModeSigningKey')
} }
const jsonwebtoken = const { createSigner } =
require('next/dist/compiled/jsonwebtoken') as typeof import('next/dist/compiled/jsonwebtoken') require('next/dist/compiled/fast-jwt') as typeof import('next/dist/compiled/fast-jwt')
const { encryptWithSecret } = const { encryptWithSecret } =
require('../../crypto-utils') as typeof import('../../crypto-utils') require('../../crypto-utils') as typeof import('../../crypto-utils')
const payload = jsonwebtoken.sign( const sign = createSigner({
{ key: options.previewModeSigningKey,
data: encryptWithSecret( algorithm: 'HS256',
Buffer.from(options.previewModeEncryptionKey), // Preview maxAge is in seconds, but fast-jwt expects milliseconds.
JSON.stringify(data) ...(options.maxAge !== undefined
), ? { expiresIn: options.maxAge * 1000 }
}, : undefined),
options.previewModeSigningKey, })
{ const payload = sign({
algorithm: 'HS256', data: encryptWithSecret(
...(options.maxAge !== undefined Buffer.from(options.previewModeEncryptionKey),
? { expiresIn: options.maxAge } JSON.stringify(data)
: undefined), ),
} })
)
// limit preview mode cookie to 2KB since we shouldn't store too much // limit preview mode cookie to 2KB since we shouldn't store too much
// data here and browsers drop cookies over 4KB // data here and browsers drop cookies over 4KB
......
...@@ -85,11 +85,14 @@ export function tryGetPreviewData( ...@@ -85,11 +85,14 @@ export function tryGetPreviewData(
data: string data: string
} }
try { try {
const jsonwebtoken = const { createVerifier } =
require('next/dist/compiled/jsonwebtoken') as typeof import('next/dist/compiled/jsonwebtoken') require('next/dist/compiled/fast-jwt') as typeof import('next/dist/compiled/fast-jwt')
encryptedPreviewData = jsonwebtoken.verify( const verify = createVerifier({
tokenPreviewData, key: options.previewModeSigningKey,
options.previewModeSigningKey algorithms: ['HS256'],
})
encryptedPreviewData = verify(
tokenPreviewData
) as typeof encryptedPreviewData ) as typeof encryptedPreviewData
} catch { } catch {
// TODO: warn // TODO: warn
......
...@@ -1280,18 +1280,15 @@ export async function ncc_json5(task, opts) { ...@@ -1280,18 +1280,15 @@ export async function ncc_json5(task, opts) {
.ncc({ packageName: 'json5', externals }) .ncc({ packageName: 'json5', externals })
.target('src/compiled/json5') .target('src/compiled/json5')
} }
externals['jsonwebtoken'] = 'next/dist/compiled/jsonwebtoken' externals['fast-jwt'] = 'next/dist/compiled/fast-jwt'
export async function ncc_jsonwebtoken(task, opts) { export async function ncc_fast_jwt(task, opts) {
await task await task
.source(relative(__dirname, require.resolve('jsonwebtoken'))) .source(relative(__dirname, require.resolve('fast-jwt')))
.ncc({ .ncc({
packageName: 'jsonwebtoken', packageName: 'fast-jwt',
externals: { externals,
...externals,
semver: 'next/dist/lib/semver-noop',
},
}) })
.target('src/compiled/jsonwebtoken') .target('src/compiled/fast-jwt')
} }
externals['loader-runner'] = 'next/dist/compiled/loader-runner' externals['loader-runner'] = 'next/dist/compiled/loader-runner'
export async function ncc_loader_runner(task, opts) { export async function ncc_loader_runner(task, opts) {
...@@ -2345,7 +2342,7 @@ export async function ncc(task, opts) { ...@@ -2345,7 +2342,7 @@ export async function ncc(task, opts) {
'ncc_is_docker', 'ncc_is_docker',
'ncc_is_wsl', 'ncc_is_wsl',
'ncc_json5', 'ncc_json5',
'ncc_jsonwebtoken', 'ncc_fast_jwt',
'ncc_loader_runner', 'ncc_loader_runner',
'ncc_loader_utils2', 'ncc_loader_utils2',
'ncc_loader_utils3', 'ncc_loader_utils3',
......
...@@ -698,8 +698,8 @@ declare module 'next/dist/compiled/json5' { ...@@ -698,8 +698,8 @@ declare module 'next/dist/compiled/json5' {
import m from 'json5' import m from 'json5'
export = m export = m
} }
declare module 'next/dist/compiled/jsonwebtoken' { declare module 'next/dist/compiled/fast-jwt' {
import m from 'jsonwebtoken' import * as m from 'fast-jwt'
export = m export = m
} }
declare module 'next/dist/compiled/lodash.curry' { declare module 'next/dist/compiled/lodash.curry' {
......
...@@ -1487,9 +1487,6 @@ importers: ...@@ -1487,9 +1487,6 @@ importers:
'@types/glob': '@types/glob':
specifier: 7.1.1 specifier: 7.1.1
version: 7.1.1 version: 7.1.1
'@types/jsonwebtoken':
specifier: 9.0.0
version: 9.0.0
'@types/lodash': '@types/lodash':
specifier: 4.14.198 specifier: 4.14.198
version: 4.14.198 version: 4.14.198
...@@ -1673,6 +1670,9 @@ importers: ...@@ -1673,6 +1670,9 @@ importers:
events: events:
specifier: 3.3.0 specifier: 3.3.0
version: 3.3.0 version: 3.3.0
fast-jwt:
specifier: 6.3.5
version: 6.3.5
find-up: find-up:
specifier: 4.1.0 specifier: 4.1.0
version: 4.1.0 version: 4.1.0
...@@ -1724,9 +1724,6 @@ importers: ...@@ -1724,9 +1724,6 @@ importers:
json5: json5:
specifier: 2.2.3 specifier: 2.2.3
version: 2.2.3 version: 2.2.3
jsonwebtoken:
specifier: 9.0.0
version: 9.0.0
loader-runner: loader-runner:
specifier: 4.3.0 specifier: 4.3.0
version: 4.3.0 version: 4.3.0
...@@ -4540,6 +4537,10 @@ packages: ...@@ -4540,6 +4537,10 @@ packages:
resolution: {integrity: sha512-/gKJun8NNiWGZJkGzI/Ragc53cOdcLNdzjLaIa+GEjguQs0ulsurx8WN0jijdK9yPqDvziX995sMRLyLt1uZMQ==} resolution: {integrity: sha512-/gKJun8NNiWGZJkGzI/Ragc53cOdcLNdzjLaIa+GEjguQs0ulsurx8WN0jijdK9yPqDvziX995sMRLyLt1uZMQ==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
'@lukeed/ms@2.0.2':
resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==}
engines: {node: '>=8'}
'@mantine/core@7.10.1': '@mantine/core@7.10.1':
resolution: {integrity: sha512-l9ypojKN3PjwO1CSLIsqxi7mA25+7w+xc71Q+JuCCREI0tuGwkZsKbIOpuTATIJOjPh8ycLiW7QxX1LYsRTq6w==} resolution: {integrity: sha512-l9ypojKN3PjwO1CSLIsqxi7mA25+7w+xc71Q+JuCCREI0tuGwkZsKbIOpuTATIJOjPh8ycLiW7QxX1LYsRTq6w==}
peerDependencies: peerDependencies:
...@@ -7969,6 +7970,9 @@ packages: ...@@ -7969,6 +7970,9 @@ packages:
asn1.js@4.10.1: asn1.js@4.10.1:
resolution: {integrity: sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==} resolution: {integrity: sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==}
asn1.js@5.4.1:
resolution: {integrity: sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==}
asn1@0.2.4: asn1@0.2.4:
resolution: {integrity: sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==} resolution: {integrity: sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==}
...@@ -10619,6 +10623,10 @@ packages: ...@@ -10619,6 +10623,10 @@ packages:
fast-json-stable-stringify@2.1.0: fast-json-stable-stringify@2.1.0:
resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==}
fast-jwt@6.3.5:
resolution: {integrity: sha512-H05ACsqy2i91TwJeLLHcTgQu6cmcmwdyvfIavjtv3ig+sQZRPsSiksXR3QFPvdk0aXmJdKIePE0OsvO4ndt4zw==}
engines: {node: '>=20'}
fast-levenshtein@2.0.6: fast-levenshtein@2.0.6:
resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==}
...@@ -13504,6 +13512,9 @@ packages: ...@@ -13504,6 +13512,9 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
hasBin: true hasBin: true
mnemonist@0.40.6:
resolution: {integrity: sha512-c4mbin5HCz77Srw1L3nwThCH/0hLVYuY3oMF2plP2tKfp/gqzSgHP63qRUOpL8jutYWNNCr49LUlKSt7exkaww==}
module-details-from-path@1.0.3: module-details-from-path@1.0.3:
resolution: {integrity: sha512-ySViT69/76t8VhE1xXHK6Ch4NcDd26gx0MzKXLO+F7NOtnqH68d9zF94nT8ZWSxXh8ELOERsnJO/sWt1xZYw5A==} resolution: {integrity: sha512-ySViT69/76t8VhE1xXHK6Ch4NcDd26gx0MzKXLO+F7NOtnqH68d9zF94nT8ZWSxXh8ELOERsnJO/sWt1xZYw5A==}
...@@ -13883,6 +13894,9 @@ packages: ...@@ -13883,6 +13894,9 @@ packages:
objectorarray@1.0.5: objectorarray@1.0.5:
resolution: {integrity: sha512-eJJDYkhJFFbBBAxeh8xW+weHlkI28n2ZdQV/J/DNfWfSKlGEf2xcfAbZTv3riEXHAhL9SVOTs2pRmXiSTf78xg==} resolution: {integrity: sha512-eJJDYkhJFFbBBAxeh8xW+weHlkI28n2ZdQV/J/DNfWfSKlGEf2xcfAbZTv3riEXHAhL9SVOTs2pRmXiSTf78xg==}
obliterator@2.0.5:
resolution: {integrity: sha512-42CPE9AhahZRsMNslczq0ctAEtqk8Eka26QofnqC346BZdHDySk3LWka23LI7ULIw11NmltpiLagIq8gBozxTw==}
obuf@1.1.2: obuf@1.1.2:
resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==} resolution: {integrity: sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==}
...@@ -15728,6 +15742,10 @@ packages: ...@@ -15728,6 +15742,10 @@ packages:
restructure@3.0.0: restructure@3.0.0:
resolution: {integrity: sha512-Xj8/MEIhhfj9X2rmD9iJ4Gga9EFqVlpMj3vfLnV2r/Mh5jRMryNV+6lWh9GdJtDBcBSPIqzRdfBQ3wDtNFv/uw==} resolution: {integrity: sha512-Xj8/MEIhhfj9X2rmD9iJ4Gga9EFqVlpMj3vfLnV2r/Mh5jRMryNV+6lWh9GdJtDBcBSPIqzRdfBQ3wDtNFv/uw==}
ret@0.5.1:
resolution: {integrity: sha512-Z/nyvABwcRnRD2mMP7Kz6G1dFZZqX1mNErOnxF42OCQKE07b9k9hK9SQxHL3LFEZUdzQaLM4dId1E/E6Vm4WhA==}
engines: {node: '>=10'}
retext-english@3.0.4: retext-english@3.0.4:
resolution: {integrity: sha512-yr1PgaBDde+25aJXrnt3p1jvT8FVLVat2Bx8XeAWX13KXo8OT+3nWGU3HWxM4YFJvmfqvJYJZG2d7xxaO774gw==} resolution: {integrity: sha512-yr1PgaBDde+25aJXrnt3p1jvT8FVLVat2Bx8XeAWX13KXo8OT+3nWGU3HWxM4YFJvmfqvJYJZG2d7xxaO774gw==}
...@@ -15892,6 +15910,10 @@ packages: ...@@ -15892,6 +15910,10 @@ packages:
resolution: {integrity: sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==} resolution: {integrity: sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
safe-regex2@5.1.2:
resolution: {integrity: sha512-tAtCGFPPP02VroDVzp4daGi6bC7jWG+41D47GKf18FeH/ubvKQHT9VmhAkvtjNOmJwqtApzWeUpEhkyEYULvmw==}
hasBin: true
safe-stable-stringify@2.5.0: safe-stable-stringify@2.5.0:
resolution: {integrity: sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==} resolution: {integrity: sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==}
engines: {node: '>=10'} engines: {node: '>=10'}
...@@ -20959,6 +20981,8 @@ snapshots: ...@@ -20959,6 +20981,8 @@ snapshots:
dependencies: dependencies:
call-bind: 1.0.8 call-bind: 1.0.8
'@lukeed/ms@2.0.2': {}
'@mantine/core@7.10.1(@mantine/hooks@7.10.1(react@19.3.0-canary-dc9aed36-20261027))(@types/react@19.2.18)(react-dom@19.3.0-canary-dc9aed36-20261027(react@19.3.0-canary-dc9aed36-20261027))(react@19.3.0-canary-dc9aed36-20261027)': '@mantine/core@7.10.1(@mantine/hooks@7.10.1(react@19.3.0-canary-dc9aed36-20261027))(@types/react@19.2.18)(react-dom@19.3.0-canary-dc9aed36-20261027(react@19.3.0-canary-dc9aed36-20261027))(react@19.3.0-canary-dc9aed36-20261027)':
dependencies: dependencies:
'@floating-ui/react': 0.26.16(react-dom@19.3.0-canary-dc9aed36-20261027(react@19.3.0-canary-dc9aed36-20261027))(react@19.3.0-canary-dc9aed36-20261027) '@floating-ui/react': 0.26.16(react-dom@19.3.0-canary-dc9aed36-20261027(react@19.3.0-canary-dc9aed36-20261027))(react@19.3.0-canary-dc9aed36-20261027)
...@@ -23803,18 +23827,6 @@ snapshots: ...@@ -23803,18 +23827,6 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
'@typescript-eslint/parser@8.71.0(eslint@9.37.0(jiti@2.6.1)(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.2)':
dependencies:
'@typescript-eslint/scope-manager': 8.71.0
'@typescript-eslint/types': 8.71.0
'@typescript-eslint/typescript-estree': 8.71.0(supports-color@8.1.1)(typescript@6.0.2)
'@typescript-eslint/visitor-keys': 8.71.0
debug: 4.4.3(supports-color@8.1.1)
eslint: 9.37.0(jiti@2.6.1)(supports-color@8.1.1)
typescript: 6.0.2
transitivePeerDependencies:
- supports-color
'@typescript-eslint/parser@8.71.0(eslint@9.37.0(jiti@2.6.1)(supports-color@9.4.0))(supports-color@9.4.0)(typescript@6.0.2)': '@typescript-eslint/parser@8.71.0(eslint@9.37.0(jiti@2.6.1)(supports-color@9.4.0))(supports-color@9.4.0)(typescript@6.0.2)':
dependencies: dependencies:
'@typescript-eslint/scope-manager': 8.71.0 '@typescript-eslint/scope-manager': 8.71.0
...@@ -24670,6 +24682,13 @@ snapshots: ...@@ -24670,6 +24682,13 @@ snapshots:
inherits: 2.0.4 inherits: 2.0.4
minimalistic-assert: 1.0.1 minimalistic-assert: 1.0.1
asn1.js@5.4.1:
dependencies:
bn.js: 4.11.9
inherits: 2.0.4
minimalistic-assert: 1.0.1
safer-buffer: 2.1.2
asn1@0.2.4: asn1@0.2.4:
dependencies: dependencies:
safer-buffer: 2.1.2 safer-buffer: 2.1.2
...@@ -28292,6 +28311,14 @@ snapshots: ...@@ -28292,6 +28311,14 @@ snapshots:
fast-json-stable-stringify@2.1.0: {} fast-json-stable-stringify@2.1.0: {}
fast-jwt@6.3.5:
dependencies:
'@lukeed/ms': 2.0.2
asn1.js: 5.4.1
ecdsa-sig-formatter: 1.0.11
mnemonist: 0.40.6
safe-regex2: 5.1.2
fast-levenshtein@2.0.6: {} fast-levenshtein@2.0.6: {}
fast-string-truncated-width@3.0.3: {} fast-string-truncated-width@3.0.3: {}
...@@ -32439,6 +32466,10 @@ snapshots: ...@@ -32439,6 +32466,10 @@ snapshots:
mkdirp@1.0.4: {} mkdirp@1.0.4: {}
mnemonist@0.40.6:
dependencies:
obliterator: 2.0.5
module-details-from-path@1.0.3: {} module-details-from-path@1.0.3: {}
moment@2.24.0: {} moment@2.24.0: {}
...@@ -32851,6 +32882,8 @@ snapshots: ...@@ -32851,6 +32882,8 @@ snapshots:
objectorarray@1.0.5: {} objectorarray@1.0.5: {}
obliterator@2.0.5: {}
obuf@1.1.2: {} obuf@1.1.2: {}
obug@2.1.4: {} obug@2.1.4: {}
...@@ -34908,6 +34941,8 @@ snapshots: ...@@ -34908,6 +34941,8 @@ snapshots:
restructure@3.0.0: {} restructure@3.0.0: {}
ret@0.5.1: {}
retext-english@3.0.4: retext-english@3.0.4:
dependencies: dependencies:
parse-english: 4.2.0 parse-english: 4.2.0
...@@ -35102,6 +35137,10 @@ snapshots: ...@@ -35102,6 +35137,10 @@ snapshots:
es-errors: 1.3.0 es-errors: 1.3.0
is-regex: 1.2.1 is-regex: 1.2.1
safe-regex2@5.1.2:
dependencies:
ret: 0.5.1
safe-stable-stringify@2.5.0: {} safe-stable-stringify@2.5.0: {}
safer-buffer@2.1.2: {} safer-buffer@2.1.2: {}
export default (req, res) => { import type { NextApiRequest, NextApiResponse } from 'next'
export default (req: NextApiRequest, res: NextApiResponse) => {
if (req.query.tooBig) { if (req.query.tooBig) {
try { try {
res.setPreviewData(new Array(2000).fill('a').join('')) res.setPreviewData(new Array(2000).fill('a').join(''))
} catch (err) { } catch (err: any) {
return res.status(500).end('too big') return res.status(500).end(err.message)
} }
} else { } else {
res.setPreviewData(req.query, { res.setPreviewData(req.query, {
...(req.query.cookieMaxAge ...(req.query.cookieMaxAge
? { maxAge: req.query.cookieMaxAge } ? { maxAge: Number(req.query.cookieMaxAge) }
: undefined),
...(req.query.cookiePath
? { path: req.query.cookiePath as string }
: undefined), : undefined),
...(req.query.cookiePath ? { path: req.query.cookiePath } : undefined),
}) })
} }
......
// run deploy tests: v1
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import cookie from 'cookie' import cookie from 'cookie'
...@@ -46,7 +47,9 @@ describe('Prerender Preview Mode', () => { ...@@ -46,7 +47,9 @@ describe('Prerender Preview Mode', () => {
it('should throw error when setting too large of preview data', async () => { it('should throw error when setting too large of preview data', async () => {
const res = await next.fetch('/api/preview?tooBig=true') const res = await next.fetch('/api/preview?tooBig=true')
expect(res.status).toBe(500) expect(res.status).toBe(500)
expect(await res.text()).toBe('too big') expect(await res.text()).toBe(
'Preview data is limited to 2KB currently, reduce how much data you are storing as preview data to continue'
)
}) })
let previewCookieString: string let previewCookieString: string
...@@ -73,6 +76,15 @@ describe('Prerender Preview Mode', () => { ...@@ -73,6 +76,15 @@ describe('Prerender Preview Mode', () => {
expect(cookies[1]).toHaveProperty('__next_preview_data') expect(cookies[1]).toHaveProperty('__next_preview_data')
expect(cookies[1]).not.toHaveProperty('Max-Age') expect(cookies[1]).not.toHaveProperty('Max-Age')
const payload = JSON.parse(
Buffer.from(
cookies[1].__next_preview_data.split('.')[1],
'base64url'
).toString()
)
expect(payload).toHaveProperty('iat', expect.any(Number))
expect(payload).not.toHaveProperty('exp')
previewCookieString = previewCookieString =
cookie.serialize('__prerender_bypass', cookies[0].__prerender_bypass) + cookie.serialize('__prerender_bypass', cookies[0].__prerender_bypass) +
'; ' + '; ' +
...@@ -102,6 +114,53 @@ describe('Prerender Preview Mode', () => { ...@@ -102,6 +114,53 @@ describe('Prerender Preview Mode', () => {
} }
expect(cookies[1]).toHaveProperty('__next_preview_data') expect(cookies[1]).toHaveProperty('__next_preview_data')
expect(cookies[1]['Max-Age']).toBe(expiry) expect(cookies[1]['Max-Age']).toBe(expiry)
const payload = JSON.parse(
Buffer.from(
cookies[1].__next_preview_data.split('.')[1],
'base64url'
).toString()
)
expect(payload.exp - payload.iat).toBe(Number(expiry))
})
it.each(['0', '-60'])(
'should reject preview data with maxAge %s',
async (maxAge) => {
const previewRes = await next.fetch(`/api/preview?cookieMaxAge=${maxAge}`)
expect(previewRes.status).toBe(200)
const cookies = previewRes.headers
.get('set-cookie')!
.split(',')
.map((raw) => cookie.parse(raw))
const previewCookie =
cookie.serialize('__prerender_bypass', cookies[0].__prerender_bypass) +
'; ' +
cookie.serialize('__next_preview_data', cookies[1].__next_preview_data)
const res = await next.fetch('/api/read', {
headers: { Cookie: previewCookie },
})
expect(res.status).toBe(200)
expect(await res.json()).toEqual({ previewData: false })
}
)
it('should reject preview data with an invalid signature', async () => {
const cookies = cookie.parse(previewCookieString)
const token = cookies.__next_preview_data.split('.')
token[2] = (token[2][0] === 'a' ? 'b' : 'a') + token[2].slice(1)
const previewCookie =
cookie.serialize('__prerender_bypass', cookies.__prerender_bypass) +
'; ' +
cookie.serialize('__next_preview_data', token.join('.'))
const res = await next.fetch('/api/read', {
headers: { Cookie: previewCookie },
})
expect(res.status).toBe(200)
expect(await res.json()).toEqual({ previewData: false })
}) })
it('should set custom path cookies', async () => { it('should set custom path cookies', async () => {
......
// run deploy tests: v1
import fs from 'fs-extra' import fs from 'fs-extra'
import cookie from 'cookie' import cookie from 'cookie'
import cheerio from 'cheerio' import cheerio from 'cheerio'
......
// run deploy tests: v1
import { nextTestSetup, isNextStart } from 'e2e-utils' import { nextTestSetup, isNextStart } from 'e2e-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import cookie from 'cookie' import cookie from 'cookie'
......
...@@ -327,7 +327,6 @@ async function readNormalizedNFT(next, name) { ...@@ -327,7 +327,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/lib/resolve-from.js", "/node_modules/next/dist/lib/resolve-from.js",
"/node_modules/next/dist/lib/route-pattern-normalizer.js", "/node_modules/next/dist/lib/route-pattern-normalizer.js",
"/node_modules/next/dist/lib/scheduler.js", "/node_modules/next/dist/lib/scheduler.js",
"/node_modules/next/dist/lib/semver-noop.js",
"/node_modules/next/dist/lib/server-external-packages.jsonc", "/node_modules/next/dist/lib/server-external-packages.jsonc",
"/node_modules/next/dist/lib/setup-exception-listeners.js", "/node_modules/next/dist/lib/setup-exception-listeners.js",
"/node_modules/next/dist/lib/static-env.js", "/node_modules/next/dist/lib/static-env.js",
...@@ -616,8 +615,8 @@ async function readNormalizedNFT(next, name) { ...@@ -616,8 +615,8 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/client/components/static-generation-bailout.js", "/node_modules/next/dist/client/components/static-generation-bailout.js",
"/node_modules/next/dist/client/lib/console.js", "/node_modules/next/dist/client/lib/console.js",
"/node_modules/next/dist/compiled/@opentelemetry/api/index.js", "/node_modules/next/dist/compiled/@opentelemetry/api/index.js",
"/node_modules/next/dist/compiled/fast-jwt/index.js",
"/node_modules/next/dist/compiled/hash.js/sha256/256.js", "/node_modules/next/dist/compiled/hash.js/sha256/256.js",
"/node_modules/next/dist/compiled/jsonwebtoken/index.js",
"/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js", "/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",
"/node_modules/next/dist/compiled/source-map/source-map.js", "/node_modules/next/dist/compiled/source-map/source-map.js",
"/node_modules/next/dist/compiled/stacktrace-parser/stack-trace-parser.cjs.js", "/node_modules/next/dist/compiled/stacktrace-parser/stack-trace-parser.cjs.js",
...@@ -628,7 +627,6 @@ async function readNormalizedNFT(next, name) { ...@@ -628,7 +627,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/lib/is-error.js", "/node_modules/next/dist/lib/is-error.js",
"/node_modules/next/dist/lib/picocolors.js", "/node_modules/next/dist/lib/picocolors.js",
"/node_modules/next/dist/lib/scheduler.js", "/node_modules/next/dist/lib/scheduler.js",
"/node_modules/next/dist/lib/semver-noop.js",
"/node_modules/next/dist/server/app-render/action-async-storage-instance.js", "/node_modules/next/dist/server/app-render/action-async-storage-instance.js",
"/node_modules/next/dist/server/app-render/action-async-storage.external.js", "/node_modules/next/dist/server/app-render/action-async-storage.external.js",
"/node_modules/next/dist/server/app-render/after-task-async-storage-instance.js", "/node_modules/next/dist/server/app-render/after-task-async-storage-instance.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment