Skip to content

Preserve original $_SERVER headers in CsrfCounterMeasureTest - #407

Closed
jrauh01 wants to merge 1 commit into
mainfrom
csrf-tests-preserve-headers
Closed

Preserve original $_SERVER headers in CsrfCounterMeasureTest#407
jrauh01 wants to merge 1 commit into
mainfrom
csrf-tests-preserve-headers

Conversation

@jrauh01

@jrauh01 jrauh01 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

CsrfCounterMeasureTest manipulated the global $_SERVER superglobal to exercise the CSRF request-safety logic (HTTP_SEC_FETCH_SITE, REQUEST_METHOD). Its tearDown() unconditionally unset() these keys, discarding whatever values were present before the test ran. Any later test that relies on those values would observe a cleared global state it never set.

Change

setUp() now captures the original values of HTTP_SEC_FETCH_SITE and REQUEST_METHOD before clearing them, and tearDown() restores them: unsetting only the keys that were absent originally, and reinstating the rest. The test suite no longer leaks mutations of these globals into other tests.

The test unconditionally unset `HTTP_SEC_FETCH_SITE` and `REQUEST_METHOD`
in tearDown, discarding whatever values the environment held before the
test ran. Capture the originals in setUp and restore them afterwards so
the suite no longer leaks a cleared global state into later tests.
@jrauh01 jrauh01 self-assigned this Aug 10, 2026
@cla-bot cla-bot Bot added the cla/signed label Aug 10, 2026
@nilmerg

nilmerg commented Aug 10, 2026

Copy link
Copy Markdown
Member

I'm genuinely interested how this was noticed. To me, the previous setUp/tearDown logic looks fine as in a unittest environment these headers are not set or relevant. Other tests have to set up their own prerequisites and should not depend on global state.

@jrauh01

jrauh01 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

I'm genuinely interested how this was noticed.

To be honest I just tried to follow Icinga/icingaweb2@6d9619d. There was no specific problem observed happening.

@nilmerg

nilmerg commented Aug 10, 2026

Copy link
Copy Markdown
Member

Then I'd question the same over there. Regardless, this isn't a best practice either so I'd rather not see it applied without reason.

@jrauh01 jrauh01 closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants