Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions packages/rc-app/endpoints/CallbackEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,54 @@ export class CallbackEndpoint extends ApiEndpoint {
persis: IPersistence
): Promise<IApiResponse> {
const { state, code } = request.query;
const contentSecurityPolicy =
"default-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-src 'self'; font-src 'self'; object-src 'none'";

Comment on lines +31 to +33
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contentSecurityPolicy is created on every request even though it’s a true constant. Consider moving it to a module-level const (e.g., CONTENT_SECURITY_POLICY) to avoid repeated allocation and make the intent clearer.

Copilot uses AI. Check for mistakes.
if (typeof state !== "string") {
return {
status: 400,
content: await getCallbackContent(
read,
null,
"",
"Invalid state parameter"
),
headers: {
"Content-Security-Policy": contentSecurityPolicy,
},
};
}

let origin;
try {
origin = decodeURIComponent(state);
} catch (e) {
Comment on lines +49 to +52
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let origin; introduces an implicit any and catch (e) declares an unused variable. Prefer typing origin as string and using an optional catch binding (catch { ... }) or _e to avoid unused-variable lint warnings.

Suggested change
let origin;
try {
origin = decodeURIComponent(state);
} catch (e) {
let origin: string;
try {
origin = decodeURIComponent(state);
} catch {

Copilot uses AI. Check for mistakes.
return {
status: 400,
content: await getCallbackContent(
read,
null,
"",
"Invalid state parameter"
),
headers: {
"Content-Security-Policy": contentSecurityPolicy,
},
};
}
Comment on lines +34 to +65
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 400-response blocks for invalid/malformed state are duplicated. Consider extracting a small helper (e.g., buildInvalidStateResponse()) to return the common { status, content, headers } shape so future changes (message, headers, etc.) only need to be made once.

Copilot uses AI. Check for mistakes.

const readEnvironment = read.getEnvironmentReader().getSettings();
const [
customOAuthName,
client_id,
client_secret,
redirect_uri,
origin,
tokenUrl,
] = await Promise.all([
readEnvironment.getValueById("custom-oauth-name"),
readEnvironment.getValueById("client-id"),
readEnvironment.getValueById("client-secret"),
getCallbackUrl(this.app),
Promise.resolve(decodeURIComponent(state)),
getTokenUrl(read),
]);

Expand Down Expand Up @@ -69,8 +103,7 @@ export class CallbackEndpoint extends ApiEndpoint {
response.data.error_description || "Unknown"
),
headers: {
"Content-Security-Policy":
"default-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-src 'self'; font-src 'self'; object-src 'none'",
"Content-Security-Policy": contentSecurityPolicy,
},
};
}
Expand All @@ -88,8 +121,7 @@ export class CallbackEndpoint extends ApiEndpoint {
false
),
headers: {
"Content-Security-Policy":
"default-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-src 'self'; font-src 'self'; object-src 'none'",
"Content-Security-Policy": contentSecurityPolicy,
},
};
}
Expand Down
Loading