Repository navigation
test(middleware): test invalid charsets and trailing newlines in X-Request-ID (#501) - #504
Conversation
|
Apologies for the silence on this one, that is on me: I wrote this up when I reviewed it and never actually posted it, so you have had a conflicted PR and no explanation for three days. What happened: #509 arrived with the same fix and I merged that one, which is why this now conflicts. Same character class, same 1-128 bound, same decision to replace a bad id rather than reject the request. You two got there independently, which was the best evidence the fix was right. I did not want to just close yours, because it covers input classes #509 does not, and there is one case neither of you pinned. Neither PR tests a trailing newline. Yours puts it mid-string, which every variant of the regex rejects. Trailing is the position that matters: So if you are still up for it, could you rebase onto main as a tests-only change:
That makes this the PR that closes the injection vector in the suite. Happy to push the rebase myself if you would rather not redo it, just say. |
…quest-ID Keep unit test coverage for invalid character classes and empty strings, and assert that trailing \n and \r\n characters are rejected. Closes smaramwbc#501 Signed-off-by: Suparva <suparva@outlook.in>
8d4bb70 to
b1de679
Compare
|
Rebased onto main and converted this to a tests-only change as suggested: kept the invalid charset loop + empty string case, dropped the duplicate tests, and added checks for trailing \n and \r\n. All middleware tests pass locally. |
|
Exactly it, thanks for turning it around. Checked the trailing case does the job: swapping Merging. |
Description
Validates client-supplied
X-Request-IDheaders against length (1-128 chars) and permitted correlation ID character set (^[A-Za-z0-9._:-]{1,128}$). If missing, empty, overly long, or containing invalid characters, a freshly generated 16-character hex UUID is used instead.Related Issue
Closes #501
Type of Change
Changes Made
_VALID_ID = re.compile(r"^[A-Za-z0-9._:\-]{1,128}$")inserver/core/middleware.py.RequestIDMiddleware.dispatch, validatedsupplied = request.headers.get(_HEADER, "")against_VALID_ID.fullmatch(supplied), falling back touuid.uuid4().hex[:16].tests/test_middleware.pycovering:tests/integration/test_edge_cases.pyverifying overly long IDs are replaced.Testing
Test Commands Run
Checklist