File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
app/lib/link_checker/uri_checker Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,12 @@ def initialize(options = {})
9595 end
9696 end
9797
98+ class CRLFArgumentError < Error
99+ def initialize ( options = { } )
100+ super ( summary : :page_returns_unparseable_headers , message : :site_returns_crlf_headers , **options )
101+ end
102+ end
103+
98104 class HttpChecker < Checker
99105 def call
100106 if uri . host . blank?
@@ -276,6 +282,21 @@ def make_request(method, check_ssl: true)
276282 ) ,
277283 )
278284 nil
285+ # Ruby net-http cannot handle responses with headers with CR/LF characters in, and such responses raise
286+ # an argument error. We want to catch these and add to the report for now, rather than continuing to raise these
287+ # as errors, which can trigger alerting. We are planning on raising this to be fixed at the net-http level which may
288+ # mean we do not have to handle these here.
289+ # Doing some fuzzy matching on the error message to try and ensure a bit of resilience, allowing for changes to the
290+ # exact error message in the exception.
291+ rescue ArgumentError => e
292+ raise e unless e . message =~ /(.*)header(.*) CR\/ LF/
293+
294+ add_problem (
295+ CRLFArgumentError . new (
296+ from_redirect : from_redirect? ,
297+ ) ,
298+ )
299+ nil
279300 end
280301
281302 def run_connection_request ( method , check_ssl : true )
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ def get_string(symbol)
6060 PageWithRating
6161 PageContainsThreat
6262 SecurityProblem
63+ CRLFArgumentError
6364 ] . freeze
6465 end
6566end
Original file line number Diff line number Diff line change 9090
9191 website_unavailable : Website unavailable
9292
93+ page_returns_unparseable_headers : Website returned a response header with CR/LF characters
94+
95+ site_returns_crlf_headers :
96+ singular : The page returns headers which contain CR/LF (Windows line break) characters, which we cannot parse
97+ redirect : This redirects to a web page which returns headers which contain CR/LF (Windows line break) characters, which we cannot handle
98+
9399 website_host_offline :
94100 singular : The website hosting this link is offline.
95101 redirect : This redirects to a website that is offline.
Original file line number Diff line number Diff line change 142142 include_examples "has warnings"
143143 end
144144
145+ context "header with CR/LF character" do
146+ let ( :uri ) { "http://www.not-gov.uk/header_with_CRLF_character" }
147+ before do
148+ stub_request ( :get , uri )
149+ . to_return ( headers : { "Invalid" => "A header containing a carriage return \r character" } )
150+ end
151+
152+ include_examples "has errors"
153+ include_examples "has a problem summary" , "Website returned a response header with CR/LF characters"
154+ end
155+
156+ it "does not recue from other argument error" do
157+ uri = "http://www.not-gov.uk/raises_argument_error"
158+ error = ArgumentError . new ( "something that's nothing to do with headers and carriage return line feed chars" )
159+
160+ stub_request ( :get , uri ) . to_raise ( error )
161+
162+ expect { described_class . new ( uri ) . call } . to raise_error ( error )
163+ end
164+
145165 context "slow response" do
146166 let ( :uri ) { "http://www.not-gov.uk/slow_response" }
147167
You can’t perform that action at this time.
0 commit comments