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 3 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
17 changes: 15 additions & 2 deletions src/OracleService/Protocols/OracleHttpsProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 Down Expand Up @@ -40,15 +40,28 @@ public void Dispose()

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

HttpResponseMessage message;
try
{
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
download:
message = await client.GetAsync(uri, HttpCompletionOption.ResponseContentRead, cancellation);
if (message.StatusCode == HttpStatusCode.NotFound && message.Headers.Location is not null)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
uri = message.Headers.Location;
if (!Settings.Default.AllowPrivateHost)
{
// Follow
IPHostEntry entry = await Dns.GetHostEntryAsync(uri.Host, cancellation);
if (entry.IsInternal())
return (OracleResponseCode.Forbidden, null);
}
goto download;
Copy link

@vang1ong7ang vang1ong7ang Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this result in infinite redirections?

infinite redirections will be stopped by the timeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me can add a max-redirect

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which timeout stops infinite redirections in the current implementation?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which timeout stops infinite redirections in the current implementation?

It seems that no timeout will stop the infinite redirections now.

}
}
catch
{
Expand Down