Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter integer header names during SAPI discovery #157

Merged

Conversation

weierophinney
Copy link
Member

Q A
Documentation yes
Bugfix yes
BC Break yes
New Feature no
RFC no
QA no

Description

Integer strings have the nasty habit of being cast to actual integers by PHP, making them problematic for usage in an associative array, despite being valid per the RFC 7230 ABNF.

Additionally, having them pass through marshal_headers_from_sapi() means that once ServerRequest gets them and tries to use them, HeaderSecurity::assertValidName() will raise an exception for integers, which could lead to unexpected server errors.

This patch chooses to filter such header names out entirely.
It also documents the change, and ways to address it if you previously depended on integer header field names.

Fixes #11

Integer strings have the nasty habit of being cast to actual integers by PHP, making them problematic for usage in an associative array, despite being valid per the RFC 7230 ABNF.

Additionally, having them pass through `marshal_headers_from_sapi()` means that once `ServerRequest` gets them and tries to use them, `HeaderSecurity::assertValidName()` will raise an exception for integers, which could lead to unexpected server errors.

This patch chooses to filter such header names out entirely.
Doing so prevents those server errors.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Creates a "security features" document that brings in the former v2 "forward migration" document around filtering x-forwarded-* headers, and also adds narrative around filtering integer headers.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney added this to the 3.0.0 milestone May 4, 2023
@weierophinney weierophinney added BC Break Bug Something isn't working Documentation labels May 4, 2023
@Xerkus Xerkus linked an issue May 4, 2023 that may be closed by this pull request
Copy link
Member

@Xerkus Xerkus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServerRequestFactory::fromGlobals() needs test to ensure it filters out integer-like headers since marshalHeadersFromSapi() is an implementation detail.

Copy link
Member

@Xerkus Xerkus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typo, otherwise good.

docs/book/v3/migration.md Outdated Show resolved Hide resolved
docs/book/v3/security.md Outdated Show resolved Hide resolved
docs/book/v3/security.md Show resolved Hide resolved
weierophinney and others added 6 commits May 4, 2023 16:01
Co-authored-by: Aleksei Khudiakov <[email protected]>
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Adds integer and string-integer keys from the `marshalHeadersFromSapi()` test case to the ServerRequestFactory test cases to demonstrate they get filtered out.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Links to PHP bug 80309 in discussion of the string integer value to integer conversion.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
When a header field is added with `withHeader()` or `withHeaderLine()`, these will accept strings that have digits only, which can also lead to the issues presented elsewhere.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Co-authored-by: Aleksei Khudiakov <[email protected]>
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@Xerkus Xerkus merged commit 2515f41 into laminas:3.0.x May 4, 2023
@weierophinney weierophinney deleted the feature/filter-integer-header-names branch May 4, 2023 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC Break Bug Something isn't working Documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle request headers with numeric keys
2 participants