Skip to content

Conversation

@ashwini-orchestral
Copy link
Contributor

The default Nginx configuration can have many vulnerabilities, a fix for a few of them.

  1. Disable unwanted HTTP methods - Allowing TRACE or DELETE is risky as it can allow a Cross-Site Tracking attack and potentially allow a hacker to steal the cookie information.
  2. HTTP requests with a large byte range in the range header can trigger the crash so have to handle this by using this proxy_set_header Range "";

@pull-request-size pull-request-size bot added the size/XS PR that changes 0-9 lines. Quick fix/merge. label Mar 19, 2021
Copy link
Contributor

@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

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

Got some questions. Please clarify. Thanks.


if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 405;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this section required below for the main API server on 443 ssl?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we also restrict this on the 443 server, note these

Copy link
Member

@Kami Kami Mar 19, 2021

Choose a reason for hiding this comment

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

Yeah, as @m4dcoder said this is likely untested and won't work - API operations also utilize PUT, POST, OPTIONS (for cors) HTTP method.

And likely correct CORS headers we send should already be sufficient, but if we can correctly identify unused methods, I'm also find with filtering those out at the nginx level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@m4dcoder - I have modified the code and the only TRACE will not be allowed.

root /opt/stackstorm/static/webui/;
index index.html;

proxy_set_header Range "";
Copy link
Contributor

Choose a reason for hiding this comment

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

How about the other locations above (i.e. /auth/, /api/, etc.)?

Copy link
Member

Choose a reason for hiding this comment

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

Is this more of a hypothetical / possible vulnerability or the code is actually vulnerable to this issue?

Because afaik, st2api doesn't handle Range header anywhere (so it should just be ignored). Or does it apply to nginx server static files?

@pull-request-size pull-request-size bot added size/S PR that changes 10-29 lines. Very easy to review. and removed size/XS PR that changes 0-9 lines. Quick fix/merge. labels Mar 22, 2021
Comment on lines 18 to 20
if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 405;
}
Copy link
Member

@arm4b arm4b Mar 22, 2021

Choose a reason for hiding this comment

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

Suggested change
if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 405;
}

Similar to what @m4dcoder was saying before, looks like the directive added is not effective for the HTTP server section here as it's just redirecting to the HTTPS one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a directive for HTTPS as well.
TRACE will be not be allowed in the HTTP method. Screenshots of testing for your reference.
trace_nginx_request
trace_nginx_response

I have added max_ranges 0 to disable the partial content responses on Nginx. If a range is set as a byte then it is more vulnerable. It is recommended to not set the range as a byte.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the update.

As per my comment above - we also needs to support / whitelist OPTIONS that's used by st2web for CORS purposes.

@Kami Kami added this to the 3.5.0 milestone Apr 1, 2021
@Kami
Copy link
Member

Kami commented Apr 1, 2021

Thanks for the contribution.

I will add a changelog entry and merge it into master.

@Kami Kami merged commit 2c565b7 into StackStorm:master Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR that changes 10-29 lines. Very easy to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants