mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-30 19:12:16 +00:00
# Which Problems Are Solved Invalid formatting in the login codebase due to invalid prettier configuration # How the Problems Are Solved Fxed .prettierignore wildcards for login source files # Additional Changes Removed .prettierrc file because there is already a prettier.config.mjs file # Additional Context
36 lines
1017 B
TypeScript
36 lines
1017 B
TypeScript
const BASE_DIRECTIVES: Record<string, string[]> = {
|
|
"default-src": ["'self'"],
|
|
"script-src": ["'self'", "'unsafe-inline'", "'unsafe-eval'"],
|
|
"connect-src": ["'self'"],
|
|
"style-src": ["'self'", "'unsafe-inline'"],
|
|
"font-src": ["'self'"],
|
|
"img-src": ["'self'"],
|
|
"frame-ancestors": ["'none'"],
|
|
"object-src": ["'none'"],
|
|
};
|
|
|
|
export interface CSPOptions {
|
|
serviceUrl?: string;
|
|
iframeOrigins?: string[];
|
|
}
|
|
|
|
export function buildCSP(options: CSPOptions = {}): string {
|
|
const directives: Record<string, string[]> = { ...BASE_DIRECTIVES };
|
|
|
|
if (options.serviceUrl) {
|
|
directives["img-src"] = [...directives["img-src"], options.serviceUrl];
|
|
}
|
|
|
|
if (options.iframeOrigins && options.iframeOrigins.length > 0) {
|
|
directives["frame-ancestors"] = [...options.iframeOrigins];
|
|
}
|
|
|
|
return serializeCSP(directives);
|
|
}
|
|
|
|
function serializeCSP(directives: Record<string, string[]>): string {
|
|
return Object.entries(directives)
|
|
.map(([key, values]) => [key, ...values].join(" "))
|
|
.join("; ");
|
|
}
|