feat: import upstream ZITADEL Login V2 v4.20.4 source workspace
This commit is contained in:
1 parent
eadd0e558b
commit
4404849fc4
644 files changed
+153201
-10
No files matched your search
@@ -0,0 +1,82 @@
|
||||
// Keeps Server Actions and server-only code in separate, recognizable places.
|
||||
//
|
||||
// - src/lib/actions/: only Server Actions. Every file starts with "use server", and every export is a
|
||||
// public, unauthenticated endpoint, so its arguments must be treated as attacker-controlled.
|
||||
// - src/lib/server/: server-only code. Every file imports "server-only" and none is a Server Action.
|
||||
// - "use server" is not allowed anywhere else, neither as a file directive nor inline in a function.
|
||||
// - Client components must not import from src/lib/server/.
|
||||
//
|
||||
// The build additionally checks the published actions against checks/server-actions.allowlist.json.
|
||||
|
||||
const ACTIONS_DIR = "/src/lib/actions/";
|
||||
const SERVER_DIR = "/src/lib/server/";
|
||||
const SERVER_IMPORT = /^@\/lib\/server(\/|$)/;
|
||||
|
||||
function directivesOf(program) {
|
||||
return program.body
|
||||
.filter((statement) => statement.type === "ExpressionStatement" && typeof statement.directive === "string")
|
||||
.map((statement) => statement.directive);
|
||||
}
|
||||
|
||||
const moduleBoundaries = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: { description: "Keep Server Actions in src/lib/actions and server-only code in src/lib/server" },
|
||||
messages: {
|
||||
useServerOutsideActions:
|
||||
'"use server" is only allowed in src/lib/actions/. Every export of such a module is a public endpoint; put the action there and the implementation in src/lib/server/.',
|
||||
missingUseServer: 'Files in src/lib/actions/ must start with "use server".',
|
||||
missingServerOnly: 'Files in src/lib/server/ must import "server-only".',
|
||||
serverImportInClient:
|
||||
"Client components must not import from src/lib/server/. Call a Server Action from src/lib/actions/ instead.",
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
create(context) {
|
||||
const filename = context.filename.replaceAll("\\", "/");
|
||||
const isTest = /\.test\.tsx?$/.test(filename);
|
||||
const inActions = filename.includes(ACTIONS_DIR);
|
||||
const inServer = filename.includes(SERVER_DIR);
|
||||
|
||||
return {
|
||||
Program(program) {
|
||||
if (isTest) {
|
||||
return;
|
||||
}
|
||||
|
||||
const directives = directivesOf(program);
|
||||
|
||||
if (inActions && !directives.includes("use server")) {
|
||||
context.report({ node: program, messageId: "missingUseServer" });
|
||||
}
|
||||
|
||||
if (
|
||||
inServer &&
|
||||
!program.body.some((statement) => statement.type === "ImportDeclaration" && statement.source.value === "server-only")
|
||||
) {
|
||||
context.report({ node: program, messageId: "missingServerOnly" });
|
||||
}
|
||||
|
||||
if (directives.includes("use client")) {
|
||||
for (const statement of program.body) {
|
||||
if (statement.type === "ImportDeclaration" && SERVER_IMPORT.test(statement.source.value)) {
|
||||
context.report({ node: statement, messageId: "serverImportInClient" });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// file-level and function-level directives are both ExpressionStatements with a `directive`
|
||||
"ExpressionStatement[directive='use server']"(node) {
|
||||
if (!inActions) {
|
||||
context.report({ node, messageId: "useServerOutsideActions" });
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
rules: {
|
||||
"module-boundaries": moduleBoundaries,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"src/lib/actions/device.ts": [
|
||||
"approveDeviceAuthorization",
|
||||
"denyDeviceAuthorization"
|
||||
],
|
||||
"src/lib/actions/flow.ts": [
|
||||
"completeFlowOrGetUrl"
|
||||
],
|
||||
"src/lib/actions/idp-intent.ts": [
|
||||
"processIDPCallback"
|
||||
],
|
||||
"src/lib/actions/idp.ts": [
|
||||
"createNewSessionForLDAP",
|
||||
"redirectToIdp"
|
||||
],
|
||||
"src/lib/actions/language.ts": [
|
||||
"setLanguageCookie"
|
||||
],
|
||||
"src/lib/actions/loginname.ts": [
|
||||
"sendLoginname"
|
||||
],
|
||||
"src/lib/actions/oidc.ts": [
|
||||
"getDeviceAuthorizationRequest"
|
||||
],
|
||||
"src/lib/actions/otp.ts": [
|
||||
"addOTP"
|
||||
],
|
||||
"src/lib/actions/passkeys.ts": [
|
||||
"registerPasskeyLink",
|
||||
"sendPasskey",
|
||||
"verifyPasskeyRegistration"
|
||||
],
|
||||
"src/lib/actions/password.ts": [
|
||||
"changePassword",
|
||||
"checkSessionAndSetPassword",
|
||||
"resetPassword",
|
||||
"sendPassword"
|
||||
],
|
||||
"src/lib/actions/register.ts": [
|
||||
"registerUser",
|
||||
"registerUserAndLinkToIDP"
|
||||
],
|
||||
"src/lib/actions/session.ts": [
|
||||
"clearSession",
|
||||
"continueWithSession",
|
||||
"skipMFAAndContinueWithNextUrl",
|
||||
"updateOrCreateSession"
|
||||
],
|
||||
"src/lib/actions/u2f.ts": [
|
||||
"addU2F",
|
||||
"verifyU2F"
|
||||
],
|
||||
"src/lib/actions/verify.ts": [
|
||||
"resendVerification",
|
||||
"sendVerification",
|
||||
"verifyTOTP"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env node
|
||||
// Fails the build when a published Server Action lives outside src/lib/actions/, or when the set of
|
||||
// published Server Actions differs from server-actions.allowlist.json.
|
||||
//
|
||||
// Next.js publishes every export of a "use server" module that the build graph reaches as a public,
|
||||
// unauthenticated POST endpoint, whether or not a client component calls it. Internal helpers that
|
||||
// trust their arguments must therefore never end up in that set. Any change to it has to be a
|
||||
// deliberate, reviewed edit of the allowlist.
|
||||
//
|
||||
// Usage: node checks/server-actions.mjs [path/to/server-reference-manifest.json]
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const manifestPath = process.argv[2] ?? join(here, "..", ".next", "server", "server-reference-manifest.json");
|
||||
const allowlistPath = join(here, "server-actions.allowlist.json");
|
||||
const ACTIONS_DIR = "src/lib/actions/";
|
||||
|
||||
function normalizeFilename(filename) {
|
||||
// the manifest stores paths relative to the workspace root (e.g. apps/login/src/lib/actions/flow.ts)
|
||||
const index = filename.indexOf("src/");
|
||||
return index === -1 ? filename : filename.slice(index);
|
||||
}
|
||||
|
||||
function published(manifest) {
|
||||
const actions = new Set();
|
||||
for (const runtime of ["node", "edge"]) {
|
||||
for (const entry of Object.values(manifest[runtime] ?? {})) {
|
||||
actions.add(`${normalizeFilename(entry.filename)}#${entry.exportedName}`);
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
function allowed(allowlist) {
|
||||
const actions = new Set();
|
||||
for (const [filename, names] of Object.entries(allowlist)) {
|
||||
for (const name of names) {
|
||||
actions.add(`${filename}#${name}`);
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
const actual = published(JSON.parse(readFileSync(manifestPath, "utf8")));
|
||||
const expected = allowed(JSON.parse(readFileSync(allowlistPath, "utf8")));
|
||||
|
||||
const outsideActionsDir = [...actual].filter((action) => !action.startsWith(ACTIONS_DIR)).sort();
|
||||
const unexpected = [...actual].filter((action) => !expected.has(action)).sort();
|
||||
const missing = [...expected].filter((action) => !actual.has(action)).sort();
|
||||
|
||||
if (outsideActionsDir.length || unexpected.length || missing.length) {
|
||||
if (outsideActionsDir.length) {
|
||||
console.error(`These Server Actions are published from outside ${ACTIONS_DIR}:`);
|
||||
outsideActionsDir.forEach((action) => console.error(` ! ${action}`));
|
||||
console.error(
|
||||
`Only modules in ${ACTIONS_DIR} may use "use server". Move the implementation to src/lib/server/ (import "server-only").`,
|
||||
);
|
||||
}
|
||||
if (unexpected.length) {
|
||||
console.error("These exports are published as Server Actions but are not in checks/server-actions.allowlist.json:");
|
||||
unexpected.forEach((action) => console.error(` + ${action}`));
|
||||
console.error(
|
||||
'Every argument of a Server Action is attacker-controlled. Move internal helpers to a module without "use server"',
|
||||
'(add import "server-only"), or add the action to the allowlist after reviewing that it derives identity and policy on the server.',
|
||||
);
|
||||
}
|
||||
if (missing.length) {
|
||||
console.error("These allowlisted Server Actions are no longer published, remove them from the allowlist:");
|
||||
missing.forEach((action) => console.error(` - ${action}`));
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Server Actions match the allowlist (${actual.size} published).`);
|
||||
Reference in new issue
Block a user