From 71618b9150bf582fd98975d39f6125c3d5417f45 Mon Sep 17 00:00:00 2001 From: Jonah Beckford <9566106-jonahbeckford@users.noreply.gitlab.com> Date: Wed, 28 May 2025 23:58:50 -0700 Subject: [PATCH] Allow localhost proxies to access Preview server For example, the GitHub Codespaces port forwarding will appear as http://localhost:PORT to the Preview server. But since the Preview server is bound to an IP address like http://127.0.0.1:PORT, the existing Origin validation will not accept http://localhost:PORT. + Accept http://localhost:PORT as a valid Origin --- .../Remote/HtmlTransport/HtmlTransport.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/HtmlTransport.cs b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/HtmlTransport.cs index 869e682940..490411fe23 100644 --- a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/HtmlTransport.cs +++ b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/HtmlTransport.cs @@ -124,6 +124,10 @@ namespace Avalonia.DesignerSupport.Remote.HtmlTransport } else { + if (req.Headers.TryGetValue("Origin", out var origin)) + { + throw new Exception($"Origin '{origin}' doesn't match Url"); + } throw new Exception("Origin doesn't match Url"); } } @@ -134,7 +138,7 @@ namespace Avalonia.DesignerSupport.Remote.HtmlTransport bool IsValidOrigin(SimpleWebSocketHttpRequest request) { return request.Headers.TryGetValue("Origin", out var origin) && - (origin == _listenUri.OriginalString || origin.StartsWith("vscode-webview:")); + (origin == _listenUri.OriginalString || origin.StartsWith("vscode-webview:") || origin.StartsWith("http://localhost:")); } async void SocketReceiveWorker(SimpleWebSocket socket)