Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent SSRF #692

Merged
merged 8 commits into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/OracleService/Protocols/OracleHttpsProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Neo.Plugins
{
class OracleHttpsProtocol : IOracleProtocol
{
private readonly HttpClient client = new HttpClient();
private readonly HttpClient client = new(new HttpClientHandler() { AllowAutoRedirect = false });

public OracleHttpsProtocol()
{
Expand All @@ -48,17 +48,24 @@ public void Dispose()
{
Utility.Log(nameof(OracleHttpsProtocol), LogLevel.Debug, $"Request: {uri.AbsoluteUri}");

if (!Settings.Default.AllowPrivateHost)
{
IPHostEntry entry = await Dns.GetHostEntryAsync(uri.Host);
if (entry.IsInternal())
return (OracleResponseCode.Forbidden, null);
}

HttpResponseMessage message;
try
{
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
message = await client.GetAsync(uri, HttpCompletionOption.ResponseContentRead, cancellation);
do
{
if (!Settings.Default.AllowPrivateHost)
{
IPHostEntry entry = await Dns.GetHostEntryAsync(uri.Host, cancellation);
if (entry.IsInternal())
return (OracleResponseCode.Forbidden, null);
}
message = await client.GetAsync(uri, HttpCompletionOption.ResponseContentRead, cancellation);
if (message.Headers.Location is not null)
{
uri = message.Headers.Location;
message = null;
}
} while (message == null);
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
catch
{
Expand Down