-
Notifications
You must be signed in to change notification settings - Fork 365
# Fix OAuth callback crash on malformed state parameter
#1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'"; | ||||||||||||||||||
|
|
||||||||||||||||||
| 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
|
||||||||||||||||||
| let origin; | |
| try { | |
| origin = decodeURIComponent(state); | |
| } catch (e) { | |
| let origin: string; | |
| try { | |
| origin = decodeURIComponent(state); | |
| } catch { |
Copilot
AI
Apr 20, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentSecurityPolicyis created on every request even though it’s a true constant. Consider moving it to a module-levelconst(e.g.,CONTENT_SECURITY_POLICY) to avoid repeated allocation and make the intent clearer.