[Server] Add DNS rebinding protection feature with middleware#260
Draft
chr-hertel wants to merge 2 commits intomainfrom
Draft
[Server] Add DNS rebinding protection feature with middleware#260chr-hertel wants to merge 2 commits intomainfrom
chr-hertel wants to merge 2 commits intomainfrom
Conversation
Use immutable withBody()/withHeader() pattern instead of mutable stream write, and add missing Content-Type: text/plain header on 403 responses. Aligns error response style with other middleware. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a server-side HTTP middleware to mitigate DNS rebinding attacks by validating Host and Origin headers against an allowlist, and wires it into the conformance test server to satisfy the conformance suite requirement.
Changes:
- Introduces
DnsRebindingProtectionMiddlewareforHost/Originallowlist validation (defaulting to localhost variants). - Adds unit tests covering allow/deny behavior, case-insensitivity, and custom allowlists.
- Enables the middleware in the conformance server and updates docs/changelog accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/Server/Transport/Http/Middleware/DnsRebindingProtectionMiddleware.php |
Implements DNS rebinding protection by rejecting non-allowed Host/Origin. |
tests/Unit/Server/Transport/Http/Middleware/DnsRebindingProtectionMiddlewareTest.php |
Unit tests for middleware allow/deny and ordering behavior. |
tests/Conformance/server.php |
Adds the new middleware to the conformance server transport pipeline. |
tests/Conformance/conformance-baseline.yml |
Removes the DNS rebinding protection item from the baseline list. |
docs/transports.md |
Documents how to enable/configure the DNS rebinding middleware. |
CHANGELOG.md |
Notes the addition of DnsRebindingProtectionMiddleware. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Server/Transport/Http/Middleware/DnsRebindingProtectionMiddleware.php
Show resolved
Hide resolved
src/Server/Transport/Http/Middleware/DnsRebindingProtectionMiddleware.php
Show resolved
Hide resolved
tests/Unit/Server/Transport/Http/Middleware/DnsRebindingProtectionMiddlewareTest.php
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding HTTP middleware for DNS middleware protection - following conformance requirements.