Fix DNS pinning - #27
Open
jtojnar wants to merge 2 commits into
Open
Conversation
Allows running tests without internet and also makes them reproducible.
Previously, the pinning would create a pinned URI but then overwrite the resolved IP address in its host part with the original host, reverting the pinning. This was the case since the beginning (504a338). Not sure why the original `uri` had the `host` part replaced. I thought it might have been to set the `Host` header but any PSR-7 implementation should have already been setting that: https://www.php-fig.org/psr/psr-7/#host-header > During construction, implementations MUST attempt to set the Host header from a provided URI if no Host header is provided. And then, the `Request-URI` would remain unpinned. Let’s replace it while keeping the `Host` header. If it is set to a different value, it has probably been done intentionally. Also test that the headers are properly updated.
Contributor
Author
|
I am not actually sure how helpful DNS pinning is here. It might prevent some TOCTOU-based attacks but since the plug-in is scoped per request, the usefulness will be limited. |
j0k3r
reviewed
Aug 19, 2026
|
|
||
| if ((string) $uri !== (string) $request->getUri()) { | ||
| $request = $request->withUri($uri->withHost($urlData['host'])); | ||
| $request = $request->withUri($uri, true); |
Owner
There was a problem hiding this comment.
We should instead first rewrite the validated host and then apply the pinned URI while asking PSR-7 to preserve that Host. This is to avoid a forced host to persist.
Suggested change
| $request = $request->withUri($uri, true); | |
| $request = $request | |
| ->withUri($uri->withHost($urlData['host'])) | |
| ->withUri($uri, true); |
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.
Previously, the pinning would create a pinned URI but then overwrite the resolved IP address in its host part with the original host, reverting the pinning. This was the case since the beginning (504a338).
Not sure why the original
urihad thehostpart replaced. I thought it might have been to set theHostheader but any PSR-7 implementation should have already been setting that:https://www.php-fig.org/psr/psr-7/#host-header
And then, the
Request-URIwould remain unpinned.Let’s replace it while keeping the
Hostheader.If it is set to a different value, it has probably been done intentionally.
Also test that the headers are properly updated. This required introducing a DNS resolver abstraction.