Skip to content

Conversation

@matipojo
Copy link
Member

@matipojo matipojo commented Oct 20, 2025

✨ PR Description

Purpose: Add functionality to load Angie sidebar anywhere in WordPress admin and trigger AI responses through programmatic prompts.

Main changes:

  • Created sidebar loading system with iframe utilities, responsive layout, and theme support
  • Added triggerAngie() method to programmatically send prompts to Angie with context
  • Implemented URL hash-based trigger mechanism for deep-linking to specific prompts

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We'd love your feedback! 🚀

reject(new Error('Angie trigger request timed out'));
}, timeout);

const responseHandler = (event: MessageEvent) => {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Copilot Autofix

AI 4 months ago

The best way to fix this issue is to ensure that responseHandler verifies the event.origin property before processing the event. Specifically, only events from trusted origins should be processed. Since the SDK accepts an origin option (line 10 in AngieMcpSdkOptions), we should use this property where available, and otherwise default to the current origin (window.location.origin). The code adjustment is fully contained within the handler function at lines 221-228 in src/angie-mcp-sdk.ts.

  • We will retrieve the configured origin (from an instance property such as this.origin).
  • In responseHandler, add a check: If event.origin does not match the expected origin, exit early (return).
  • We should avoid changing behavior otherwise; just only act on messages from the correct origin.

No new imports are required; all necessary functionality is provided by the DOM and standard JavaScript.


Suggested changeset 1
src/angie-mcp-sdk.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/angie-mcp-sdk.ts b/src/angie-mcp-sdk.ts
--- a/src/angie-mcp-sdk.ts
+++ b/src/angie-mcp-sdk.ts
@@ -218,7 +218,12 @@
         reject(new Error('Angie trigger request timed out'));
       }, timeout);
 
+      const expectedOrigin = this.options?.origin || window.location.origin;
       const responseHandler = (event: MessageEvent) => {
+        if (event.origin !== expectedOrigin) {
+          // Ignore messages from unexpected origins
+          return;
+        }
         if (event.data?.type === MessageEventType.SDK_TRIGGER_ANGIE_RESPONSE && 
             event.data?.payload?.requestId === requestId) {
           clearTimeout(timeoutId);
EOF
@@ -218,7 +218,12 @@
reject(new Error('Angie trigger request timed out'));
}, timeout);

const expectedOrigin = this.options?.origin || window.location.origin;
const responseHandler = (event: MessageEvent) => {
if (event.origin !== expectedOrigin) {
// Ignore messages from unexpected origins
return;
}
if (event.data?.type === MessageEventType.SDK_TRIGGER_ANGIE_RESPONSE &&
event.data?.payload?.requestId === requestId) {
clearTimeout(timeoutId);
Copilot is powered by AI and may make mistakes. Always verify output.
throw new Error( 'Iframe not found' );
}
} catch ( error ) {
console.error( `AngieMcpSdk:Failed to create client for SDK server "${ payload.serverName }":`, error );

Check failure

Code scanning / CodeQL

Use of externally-controlled format string High

Format string depends on a
user-provided value
.

Copilot Autofix

AI 4 months ago

The best way to fix this problem is to ensure that unsanitized user-controlled data is not interpolated directly into format strings. Instead, use a static format string and pass the user-controlled value as a separate argument to console.error, so that any format specifiers in the input are not interpreted as part of the format string. Specifically, change line 71 to use the static string "AngieMcpSdk:Failed to create client for SDK server \"%s\":, with payload.serverName passed as an argument to console.error before error. This fix will involve only a small change at line 71 of src/sdk.ts.

Suggested changeset 1
src/sdk.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/sdk.ts b/src/sdk.ts
--- a/src/sdk.ts
+++ b/src/sdk.ts
@@ -68,7 +68,7 @@
 						throw new Error( 'Iframe not found' );
 					}
 				} catch ( error ) {
-					console.error( `AngieMcpSdk:Failed to create client for SDK server "${ payload.serverName }":`, error );
+					console.error( 'AngieMcpSdk:Failed to create client for SDK server "%s":', payload.serverName, error );
 				}
 				break;
 
EOF
@@ -68,7 +68,7 @@
throw new Error( 'Iframe not found' );
}
} catch ( error ) {
console.error( `AngieMcpSdk:Failed to create client for SDK server "${ payload.serverName }":`, error );
console.error( 'AngieMcpSdk:Failed to create client for SDK server "%s":', payload.serverName, error );
}
break;

Copilot is powered by AI and may make mistakes. Always verify output.
}

export function setupMessageListener(): void {
window.addEventListener( 'message', function( event ) {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Copilot Autofix

AI 4 months ago

To fix this problem, the code should verify that the event.origin of the incoming postMessage events matches a list of trusted origins before taking any action. This check should occur at the start of the message handler. The best way to implement this is to define an allowlist of trusted origins (ideally, somewhere easy to update/maintain, e.g., as a constant at the top), and compare event.origin against this list before executing any logic based on the message. If the origin is not trusted, the message should be ignored, potentially with a warning in the console for easier debugging.

Required changes:

  • Add a constant (e.g., TRUSTED_ORIGIN) or an array (e.g., TRUSTED_ORIGINS) containing the expected/trusted domain(s) at the top of the file or before the message handler.
  • Modify the message handler in setupMessageListener() to check event.origin before acting on the message.
  • No new libraries are required, as this can be accomplished with standard JS/TS features.

Suggested changeset 1
src/sidebar.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/sidebar.ts b/src/sidebar.ts
--- a/src/sidebar.ts
+++ b/src/sidebar.ts
@@ -253,8 +253,18 @@
 	};
 }
 
+// Define trusted origins for postMessage validation.
+// TODO: Update this to the specific trusted origin(s) for your application.
+const TRUSTED_ORIGINS = [
+	'https://www.example.com', // Replace with your actual trusted origin(s)
+];
+
 export function setupMessageListener(): void {
 	window.addEventListener( 'message', function( event ) {
+		if (!TRUSTED_ORIGINS.includes(event.origin)) {
+			console.warn(`Untrusted message origin received: ${event.origin}`);
+			return;
+		}
 		if ( event.data && event.data.type === 'toggleAngieSidebar' ) {
 			const { force, skipTransition } = event.data.payload || {};
 			if ( window.toggleAngieSidebar ) {
EOF
@@ -253,8 +253,18 @@
};
}

// Define trusted origins for postMessage validation.
// TODO: Update this to the specific trusted origin(s) for your application.
const TRUSTED_ORIGINS = [
'https://www.example.com', // Replace with your actual trusted origin(s)
];

export function setupMessageListener(): void {
window.addEventListener( 'message', function( event ) {
if (!TRUSTED_ORIGINS.includes(event.origin)) {
console.warn(`Untrusted message origin received: ${event.origin}`);
return;
}
if ( event.data && event.data.type === 'toggleAngieSidebar' ) {
const { force, skipTransition } = event.data.payload || {};
if ( window.toggleAngieSidebar ) {
Copilot is powered by AI and may make mistakes. Always verify output.
@matipojo matipojo changed the title v1.0.3 Support loading Angie sidebar everywhere v1.0.3 Support loading Angie sidebar everywhere and trigger with prompt Oct 20, 2025
@matipojo matipojo changed the title v1.0.3 Support loading Angie sidebar everywhere and trigger with prompt v1.0.3 Support loading Angie sidebar anywhere and trigger with prompt Oct 20, 2025
@matipojo matipojo merged commit 5330b5f into master Oct 20, 2025
14 of 15 checks passed
@matipojo matipojo deleted the load-sidebar branch October 20, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant