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

Reject non-standard HTTP methods at edge #103

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

nimalank7
Copy link
Contributor

@nimalank7 nimalank7 commented Aug 30, 2024

Description:

  • Previously non-standard/unimplemented HTTP requests such as DEBUG will pass through Fastly and hit the origin where nginx rejects them as 501. See MDN documentation as to why this is the appropriate status code to return
  • Here Fastly is configured to throw a 501 and return custom HTML. The error code 806 and not 805 is used as the latter is used by _security_txt_response.vcl in the shared VCL
  • FASTLYPURGE is how the non-standard PURGE method appears in VCL
  • Tested in integration and staging:
curl -w '\n%{http_code}\n' -X DEBUG https://www.staging.publishing.service.gov.uk

        <!DOCTYPE html>
        <html>
          <head>
            <title>Welcome to GOV.UK</title>
            <style>
              body { font-family: Arial, sans-serif; margin: 0; }
              header { background: black; }
              h1 { color: white; font-size: 29px; margin: 0 auto; padding: 10px; max-width: 990px; }
              p { color: black; margin: 30px auto; max-width: 990px; }
            </style>
          </head>
          <body>
501

Description:
- Previously non-standard/unimplemented HTTP requests such as `DEBUG` will pass through Fastly and hit the origin where nginx rejects them as 501. See [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501)
as to why this is the appropriate status code to return
- Here Fastly is configured to throw a 501 and return custom HTML. The error code `806` and not `805` is used as the latter is used by `_security_txt_response.vcl` in the [shared VCL](https://github.com/alphagov/govuk-fastly/blob/main/modules/shared/_security_txt_response.vcl)
- `FASTLYPURGE` is how the non-standard `PURGE` method appears in [VCL](https://www.fastly.com/documentation/reference/vcl/variables/client-request/req-method/)
- Tested in integration and staging:

```
curl -w '\n%{http_code}\n' -X DEBUG https://www.staging.publishing.service.gov.uk

        <!DOCTYPE html>
        <html>
          <head>
            <title>Welcome to GOV.UK</title>
            <style>
              body { font-family: Arial, sans-serif; margin: 0; }
              header { background: black; }
              h1 { color: white; font-size: 29px; margin: 0 auto; padding: 10px; max-width: 990px; }
              p { color: black; margin: 30px auto; max-width: 990px; }
            </style>
          </head>
          <body>
501
```

- See [proof of concept here](#78) with data to show that it won't block anything unintentionally
- Closes #79
@nimalank7 nimalank7 force-pushed the reject-nonstandard-HTTP-methods-edge branch from 5c01f63 to 72a03d0 Compare August 30, 2024 15:22
@nimalank7 nimalank7 requested a review from a team August 30, 2024 15:34
Comment on lines +622 to +638
synthetic {"
<!DOCTYPE html>
<html>
<head>
<title>Welcome to GOV.UK</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; }
header { background: black; }
h1 { color: white; font-size: 29px; margin: 0 auto; padding: 10px; max-width: 990px; }
p { color: black; margin: 30px auto; max-width: 990px; }
</style>
</head>
<body>
<header><h1>GOV.UK</h1></header>
<p>We cannot find the page you're looking for. Please try searching on <a href="https://www.gov.uk/">GOV.UK</a>.</p>
</body>
</html>"};
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably could just return some text rather than HTML. Unlikely that a browser will send a non-standard HTTP method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True.

@nimalank7 nimalank7 merged commit 266b339 into main Sep 2, 2024
4 checks passed
@nimalank7 nimalank7 deleted the reject-nonstandard-HTTP-methods-edge branch September 2, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reject unimplemented/nonstandard HTTP methods at the edge.
2 participants