Skip to content

Commit

Permalink
Merge branch 'canary' into kdy1/swc-pure
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Oct 23, 2023
2 parents e421dcc + 7c803a7 commit 5ec7468
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.5.7-canary.18"
"version": "13.5.7-canary.19"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "13.5.7-canary.18",
"@next/eslint-plugin-next": "13.5.7-canary.19",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -92,7 +92,7 @@
]
},
"dependencies": {
"@next/env": "13.5.7-canary.18",
"@next/env": "13.5.7-canary.19",
"@swc/helpers": "0.5.2",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -146,11 +146,11 @@
"@mswjs/interceptors": "0.23.0",
"@napi-rs/cli": "2.16.2",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "13.5.7-canary.18",
"@next/polyfill-nomodule": "13.5.7-canary.18",
"@next/react-dev-overlay": "13.5.7-canary.18",
"@next/react-refresh-utils": "13.5.7-canary.18",
"@next/swc": "13.5.7-canary.18",
"@next/polyfill-module": "13.5.7-canary.19",
"@next/polyfill-nomodule": "13.5.7-canary.19",
"@next/react-dev-overlay": "13.5.7-canary.19",
"@next/react-refresh-utils": "13.5.7-canary.19",
"@next/swc": "13.5.7-canary.19",
"@opentelemetry/api": "1.4.1",
"@playwright/test": "^1.35.1",
"@taskr/clear": "1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export function stringToUint8Array(binary: string) {
return arr
}

const encoder = new TextEncoder()

export function encrypt(key: CryptoKey, salt: string, data: Uint8Array) {
const iv = encoder.encode(salt)
export function encrypt(key: CryptoKey, iv: Uint8Array, data: Uint8Array) {
return crypto.subtle.encrypt(
{
name: 'AES-GCM',
Expand All @@ -49,8 +46,7 @@ export function encrypt(key: CryptoKey, salt: string, data: Uint8Array) {
)
}

export function decrypt(key: CryptoKey, salt: string, data: Uint8Array) {
const iv = encoder.encode(salt)
export function decrypt(key: CryptoKey, iv: Uint8Array, data: Uint8Array) {
return crypto.subtle.decrypt(
{
name: 'AES-GCM',
Expand Down
55 changes: 24 additions & 31 deletions packages/next/src/server/app-render/action-encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import {
stringToUint8Array,
} from './action-encryption-utils'

const PAYLOAD_PREFIX = 'next:'
const SALT_PREFIX = '__next_action__'

async function decodeActionBoundArg(actionId: string, arg: string) {
const key = await getActionEncryptionKey()
if (typeof key === 'undefined') {
Expand All @@ -34,19 +31,23 @@ async function decodeActionBoundArg(actionId: string, arg: string) {
)
}

// Get the payload and iv from the arg. 18 bytes * 8/6 = 24 chars in base64.
const ivPrefix = arg.slice(0, 24)
const payload = arg.slice(24)
// Get the iv (16 bytes) and the payload from the arg.
const originalPayload = atob(arg)
const ivValue = originalPayload.slice(0, 16)
const payload = originalPayload.slice(16)
if (payload === undefined) {
throw new Error('Invalid Server Action payload.')
}

const decoded = await decrypt(
key,
SALT_PREFIX + ivPrefix + actionId,
stringToUint8Array(atob(payload))
const decrypted = arrayBufferToString(
await decrypt(key, stringToUint8Array(ivValue), stringToUint8Array(payload))
)
return arrayBufferToString(decoded)

if (!decrypted.startsWith(actionId)) {
throw new Error('Invalid Server Action payload: failed to decrypt.')
}

return decrypted.slice(actionId.length)
}

async function encodeActionBoundArg(actionId: string, arg: string) {
Expand All @@ -57,17 +58,18 @@ async function encodeActionBoundArg(actionId: string, arg: string) {
)
}

// Get some random bytes for iv.
const randomBytes = new Uint8Array(18)
// Get 16 random bytes as iv.
const randomBytes = new Uint8Array(16)
crypto.getRandomValues(randomBytes)
const ivPrefix = btoa(arrayBufferToString(randomBytes.buffer))
const ivValue = arrayBufferToString(randomBytes.buffer)

const encoded = await encrypt(
const encrypted = await encrypt(
key,
SALT_PREFIX + ivPrefix + actionId,
stringToUint8Array(arg)
randomBytes,
stringToUint8Array(actionId + arg)
)
return ivPrefix + btoa(arrayBufferToString(encoded))

return btoa(ivValue + arrayBufferToString(encrypted))
}

// Encrypts the action's bound args into a string.
Expand All @@ -82,27 +84,18 @@ export async function encryptActionBoundArgs(actionId: string, args: any[]) {
// Encrypt the serialized string with the action id as the salt.
// Add a prefix to later ensure that the payload is correctly decrypted, similar
// to a checksum.
const encryped = await encodeActionBoundArg(
actionId,
PAYLOAD_PREFIX + serialized
)
const encrypted = await encodeActionBoundArg(actionId, serialized)

return encryped
return encrypted
}

// Decrypts the action's bound args from the encrypted string.
export async function decryptActionBoundArgs(
actionId: string,
encryped: Promise<string>
encrypted: Promise<string>
) {
// Decrypt the serialized string with the action id as the salt.
let decryped = await decodeActionBoundArg(actionId, await encryped)

if (!decryped.startsWith(PAYLOAD_PREFIX)) {
throw new Error('Invalid Server Action payload: failed to decrypt.')
} else {
decryped = decryped.slice(PAYLOAD_PREFIX.length)
}
const decryped = await decodeActionBoundArg(actionId, await encrypted)

// Using Flight to deserialize the args from the string.
const deserialized = await createFromReadableStream(
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/third-parties/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/third-parties",
"version": "13.5.7-canary.18",
"version": "13.5.7-canary.19",
"repository": {
"url": "vercel/next.js",
"directory": "packages/third-parties"
Expand All @@ -22,7 +22,7 @@
"third-party-capital": "1.0.20"
},
"devDependencies": {
"next": "13.5.7-canary.18",
"next": "13.5.7-canary.19",
"outdent": "0.8.0",
"prettier": "2.5.1"
},
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ec7468

Please sign in to comment.