Skip to content

[Server] Add DNS rebinding protection feature with middleware#260

Draft
chr-hertel wants to merge 2 commits intomainfrom
dns-rebinding-protection
Draft

[Server] Add DNS rebinding protection feature with middleware#260
chr-hertel wants to merge 2 commits intomainfrom
dns-rebinding-protection

Conversation

@chr-hertel
Copy link
Member

@chr-hertel chr-hertel commented Mar 10, 2026

Adding HTTP middleware for DNS middleware protection - following conformance requirements.

  • need to review myself first

@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Mar 10, 2026
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>
@chr-hertel chr-hertel marked this pull request as draft March 10, 2026 23:36
@chr-hertel chr-hertel self-assigned this Mar 10, 2026
@chr-hertel chr-hertel requested a review from Copilot March 10, 2026 23:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DnsRebindingProtectionMiddleware for Host/Origin allowlist 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants