Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

fix(sdk): decline redirects to unsupported URI schemes

xxwtiancai778e5000eb65
diff --git a/sdks/sandbox/csharp/src/OpenSandbox/Internal/ProtectedRedirectHandler.cs b/sdks/sandbox/csharp/src/OpenSandbox/Internal/ProtectedRedirectHandler.cs
index 8084a7fec..6ee36c61d 100644
--- a/sdks/sandbox/csharp/src/OpenSandbox/Internal/ProtectedRedirectHandler.cs
+++ b/sdks/sandbox/csharp/src/OpenSandbox/Internal/ProtectedRedirectHandler.cs
@@ -127,6 +127,14 @@ internal sealed class ProtectedRedirectHandler : DelegatingHandler
target = new Uri(source, target);
}
+ // Native auto-redirect only follows HTTP(S); other schemes (e.g.
+ // ftp://) are left to the caller as the original redirect response.
+ if (!string.Equals(target.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) &&
+ !string.Equals(target.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
+ {
+ return null;
+ }
+
// Modern .NET never follows a secure-to-insecure redirect.
if (source.Scheme == Uri.UriSchemeHttps && target.Scheme != Uri.UriSchemeHttps)
{
diff --git a/sdks/sandbox/csharp/tests/OpenSandbox.Tests/ProtectedRedirectHandlerTests.cs b/sdks/sandbox/csharp/tests/OpenSandbox.Tests/ProtectedRedirectHandlerTests.cs
index d75d3ee3a..4bd082784 100644
--- a/sdks/sandbox/csharp/tests/OpenSandbox.Tests/ProtectedRedirectHandlerTests.cs
+++ b/sdks/sandbox/csharp/tests/OpenSandbox.Tests/ProtectedRedirectHandlerTests.cs
@@ -77,6 +77,21 @@ public class ProtectedRedirectHandlerTests
Assert.False(content.Disposed);
}
+ [Theory]
+ [InlineData("ftp://other.test/file")]
+ [InlineData("file:///etc/hostname")]
+ public async Task DeclinesRedirectsToUnsupportedUriSchemes(string location)
+ {
+ var calls = 0;
+ using var content = new TrackingContent();
+ using var client = Client((_, _) => { calls++; return Task.FromResult(Redirect(302, location, content)); });
+ using var response = await client.GetAsync("http://example.test");
+ Assert.Equal(1, calls);
+ Assert.False(content.Disposed);
+ Assert.Equal(HttpStatusCode.Found, response.StatusCode);
+ Assert.Equal(new Uri(location), response.Headers.Location);
+ }
+
[Fact]
public async Task RedirectLimitReturnsLastResponseAndDisposesIntermediateResponses()
{