Skip to content
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

Iframe webauthn postmessage #2825

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sea-snake
Copy link
Contributor

@sea-snake sea-snake commented Jan 29, 2025

Motivation

Changes

Tests


🟡 Some screens were changed

export const WEBAUTHN_IFRAME_PATH = "#iframe/webauthn";

export const webAuthnInIframeFlow = (): Promise<never> => {
window.addEventListener("message", async (event) => {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Copilot Autofix AI 1 day ago

To fix the problem, we need to verify the origin of the incoming message in the postMessage handler. This involves checking the event.origin property against a list of trusted origins before processing the message. This ensures that only messages from trusted sources are handled, mitigating the risk of malicious messages.

The best way to fix the problem without changing existing functionality is to add an origin check at the beginning of the postMessage handler. We will define a list of trusted origins and compare the event.origin against this list. If the origin is not trusted, we will simply return and not process the message.

Suggested changeset 1
src/frontend/src/flows/iframeWebAuthn.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/frontend/src/flows/iframeWebAuthn.ts b/src/frontend/src/flows/iframeWebAuthn.ts
--- a/src/frontend/src/flows/iframeWebAuthn.ts
+++ b/src/frontend/src/flows/iframeWebAuthn.ts
@@ -6,2 +6,7 @@
   window.addEventListener("message", async (event) => {
+    const trustedOrigins = ["https://trusted-origin.com"];
+    if (!trustedOrigins.includes(event.origin)) {
+      console.warn(`Untrusted origin: ${event.origin}`);
+      return;
+    }
     // event.source?.postMessage("why does it not work?");
EOF
@@ -6,2 +6,7 @@
window.addEventListener("message", async (event) => {
const trustedOrigins = ["https://trusted-origin.com"];
if (!trustedOrigins.includes(event.origin)) {
console.warn(`Untrusted origin: ${event.origin}`);
return;
}
// event.source?.postMessage("why does it not work?");
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant