comparison test/test_cgi.py @ 8265:35beff316883

fix(api): issue2551384. Verify REST authorization earlier To reduce the ability of bad actors to spam (DOS) the REST endpoint with bad data and generate logs meant for debugging, modify the flow in client.py's REST handler to verify authorization earlier. If the anonymous user is allowed to use REST, this won't make a difference for a DOS attempt. The templates don't enable REST for the anonymous user by default. Most admins don't change this. The validation order for REST requests has been changed. CORS identfied an handled User authorization to use REST (return 403 on failure) REST request validated (Origin header valid etc.) (return 400 for bad request) Incorrectly formatted CORS preflight requests (e.g. missing Origin header) that are not recogized as a CORS request can now return HTTP status 403 as well as status 400 (when anonymous is allowed access). Note all CORS preflights are sent without authentication so appear as anonymous requests. The tests were updated to compensate, but it is not obvious to me from specs what the proper evaulation order/return codes should be for this case. Both 403/400 are failures and cause CORS to fail so there should be no difference but...
author John Rouillard <rouilj@ieee.org>
date Thu, 09 Jan 2025 09:30:08 -0500
parents 0242cf22ef74
children 05d8806b25ad
comparison
equal deleted inserted replaced
8264:09e8d1a4c796 8265:35beff316883
1358 1358
1359 self.assertNotIn('Access-Control-Allow-Origin', 1359 self.assertNotIn('Access-Control-Allow-Origin',
1360 cl.additional_headers 1360 cl.additional_headers
1361 ) 1361 )
1362 1362
1363 self.assertEqual(cl.response_code, 400) 1363 self.assertEqual(cl.response_code, 403)
1364 del(out[0]) 1364 del(out[0])
1365 1365
1366 # origin not set to allowed value 1366 # origin not set to allowed value
1367 # prevents authenticated request like this from 1367 # prevents authenticated request like this from
1368 # being shared with the requestor because 1368 # being shared with the requestor because

Roundup Issue Tracker: http://roundup-tracker.org/