function shouldPersistGeneratedToken(params: {
persistRequested: boolean;
resolvedAuth: ResolvedGatewayAuth;
}): boolean { if (!params.persistRequested) { returnfalse;
}
// Keep CLI/runtime mode overrides ephemeral: startup should not silently // mutate durable auth policy when mode was chosen by an override flag. if (params.resolvedAuth.modeSource === "override") { returnfalse;
}
const nextAuth = resolveGatewayAuthFromConfig({
cfg: nextCfg,
env,
authOverride: params.authOverride,
tailscaleOverride: params.tailscaleOverride,
}); // The generated token is crypto-random, so this cannot match the weak set // in practice — but running the assertion on both branches documents that // the rule applies uniformly and guards against any future path that might // feed a non-generated value through nextAuth.
assertGatewayAuthNotKnownWeak(nextAuth);
assertHooksTokenSeparateFromGatewayAuth({ cfg: nextCfg, auth: nextAuth }); return {
cfg: nextCfg,
auth: nextAuth,
generatedToken,
persistedGeneratedToken: persist,
};
}
export function assertHooksTokenSeparateFromGatewayAuth(params: {
cfg: OpenClawConfig;
auth: ResolvedGatewayAuth;
}): void { if (params.cfg.hooks?.enabled !== true) { return;
} const hooksToken = normalizeOptionalString(params.cfg.hooks.token) ?? ""; if (!hooksToken) { return;
} const gatewayToken =
params.auth.mode === "token" ? (normalizeOptionalString(params.auth.token) ?? "") : ""; if (!gatewayToken) { return;
} if (hooksToken !== gatewayToken) { return;
} thrownew Error( "Invalid config: hooks.token must not match gateway auth token. Set a distinct hooks.token for hook ingress.",
);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.