Skip to content

Commit caf1587

Browse files
committed
Do not allow POST requests to /sitemaps
We get relatively frequent vulnerability scans to the sitemaps endpoint, attempting to post data. We should handle this.
1 parent 9795cb7 commit caf1587

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/rummager/app.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ def get_type_from_request_body(request_body)
317317
serve_from_s3(sitemap)
318318
end
319319

320+
post "/sitemaps/*" do
321+
headers = { "Allow" => "GET" }
322+
body = { message: "Method Not Allowed: Use GET to access the sitemap." }.to_json
323+
halt(405, headers, body)
324+
end
325+
320326
def serve_from_s3(key)
321327
o = Services.s3_client.get_object(bucket: ENV["AWS_S3_SITEMAPS_BUCKET_NAME"], key:)
322328

spec/integration/app/sitemap_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@
5555
end
5656
end
5757
end
58+
59+
describe "post /sitemaps/*" do
60+
it "returns a 405 error message" do
61+
post "/sitemaps/server/anything/stuff.php"
62+
expect(last_response.status).to eq(405)
63+
expect(last_response.headers["Allow"]).to eq("GET")
64+
expect(last_response.body).to eq({ message: "Method Not Allowed: Use GET to access the sitemap." }.to_json)
65+
end
66+
end
5867
end

0 commit comments

Comments
 (0)