Browse Source

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
pull/18950/head
Jonah Beckford 10 months ago
parent
commit
71618b9150
  1. 6
      src/Avalonia.DesignerSupport/Remote/HtmlTransport/HtmlTransport.cs

6
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)

Loading…
Cancel
Save