Repository navigation
Closed
Labels
P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:securityThis issue is about security boundaries, credentials, authz, sandboxing, or sensitive data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
Description
Problem
CanvasWindow.xaml.cs subscribes to CoreWebView2 events but never unsubscribes them. If the window is recreated (e.g. during node teardown → recreate), handlers accumulate on the old WebView2 instance. Additionally, an anonymous lambda captures _trustedGatewayOrigin and _gatewayToken, which can become stale if tokens rotate.
Relevant code:
CanvasWebView.CoreWebView2.WebMessageReceived += _webMessageReceivedHandler;
CanvasWebView.CoreWebView2.WebResourceRequested += (s, args) => { ... };
CanvasWebView.CoreWebView2.NavigationCompleted += OnNavigationCompleted;Impact
- Memory leaks: handlers and captured variables are kept alive by the WebView2 event list.
- Security: stale auth tokens may be injected into requests after a token refresh or gateway switch.
- Hard to diagnose because the leak is in native COM interop, not managed GC.
Suggested fix
- Store the
WebResourceRequestedlambda in a field so it can be unsubscribed (-=). - Unsubscribe all handlers in
OnWindowClosedorDispose. - Null out
_gatewayTokenafter disposal to avoid keeping it rooted by a closure. - Consider reusing a single
CanvasWindowinstance rather than recreating it, which would make lifecycle management simpler.
Files
src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs
Reacted by clawsweeper
Metadata
Metadata
Assignees
Labels
P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:securityThis issue is about security boundaries, credentials, authz, sandboxing, or sensitive data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Activity
clawsweeper commentedon May 27, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 27, 2026, 9:00 AM ET / 13:00 UTC.
Summary
Keep open: current main still wires an anonymous WebResourceRequested handler that captures the trusted origin and gateway token, while the close path only unsubscribes WebMessageReceived and NavigationCompleted.
Reproducibility: yes. Source inspection on current main shows the WebResourceRequested lambda captures trustedOrigin/token locals and has no corresponding unsubscribe in OnWindowClosed; I did not run a live WebView2 repro.
Next step
A narrow fix is likely, but the token-injection path is security-sensitive enough that a maintainer should review the lifecycle approach before assigning automated repair.
Security
Needs attention: The issue is security-sensitive because current main can retain and inject a stale bearer token through a WebView2 request handler.
Review details
Best possible solution:
Store the WebResourceRequested handler in a field, remove the matching filter and unsubscribe all CoreWebView2 handlers on close, clear gateway auth fields on disposal, and add focused regression coverage plus a tray/WebView2 smoke.
Do we have a high-confidence way to reproduce the issue?
Yes. Source inspection on current main shows the WebResourceRequested lambda captures trustedOrigin/token locals and has no corresponding unsubscribe in OnWindowClosed; I did not run a live WebView2 repro.
Is this the best way to solve the issue?
Yes. The suggested fix is the narrow maintainable direction: give the WebResourceRequested handler a field identity, unsubscribe it during close/disposal, avoid captured stale token state, and cover the lifecycle behavior.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against bf21e7b216aa.
Label changes
Label changes:
P2: The report describes a bounded CanvasWindow lifecycle and credential-injection bug with limited blast radius.impact:security: The issue is about stale gateway bearer tokens being retained and injected after token refresh or gateway switch.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.clawsweeper:needs-security-review: Current issue advisory state selects this label.Label justifications:
P2: The report describes a bounded CanvasWindow lifecycle and credential-injection bug with limited blast radius.impact:security: The issue is about stale gateway bearer tokens being retained and injected after token refresh or gateway switch.Evidence reviewed
Security concerns:
src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs:308The WebResourceRequested lambda copies _gatewayToken into a local token and is never unsubscribed, so token rotation or gateway switching can leave an old bearer value attached to the WebView2 request pipeline.
Confidence: 0.86
What I checked:
AGENTS.md:1, bf21e7b216aa)src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs:302, bf21e7b216aa)src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs:438, bf21e7b216aa)src/OpenClaw.Tray.WinUI/Services/NodeService.cs:843, bf21e7b216aa)tests/OpenClaw.Tray.Tests/TrayMenuWindowMarkupTests.cs:24, bf21e7b216aa)docs/CONNECTION_ARCHITECTURE.md:133, bf21e7b216aa)Likely related people:
src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs,src/OpenClaw.Tray.WinUI/Services/NodeService.cs)src/OpenClaw.Tray.WinUI/Windows/CanvasWindow.xaml.cs)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.shanselman commentedon May 28, 2026
Addressed by merged PR #564. CanvasWindow now stores and removes the WebView2 auth handler/filter, avoids the anonymous stale-token capture, and clears gateway auth state on close.