Skip to content

Prevent HTTP header leakage on local file URIs in PHP 8.5+#888

Closed
VINICIUSOLIVER wants to merge 1 commit intojsonrainbow:mainfrom
VINICIUSOLIVER:fix/local-file-header-leak-php85
Closed

Prevent HTTP header leakage on local file URIs in PHP 8.5+#888
VINICIUSOLIVER wants to merge 1 commit intojsonrainbow:mainfrom
VINICIUSOLIVER:fix/local-file-header-leak-php85

Conversation

@VINICIUSOLIVER
Copy link

@VINICIUSOLIVER VINICIUSOLIVER commented Feb 19, 2026

Description

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • [x ] All new and existing tests pass
  • I have updated the documentation accordingly
  • [ x] My changes generate no new warnings

Additional Notes

This PR addresses an issue in PHP 8.5+ where the new global function http_get_last_response_headers() returns headers from the previous HTTP request when the current URI uses a non-HTTP wrapper (like file://).

By adding a scheme check, we ensure that HTTP headers are only retrieved when the URI is actually a web request. This prevents the schema validator from incorrectly identifying local JSON files as text/xml due to state leakage from prior API calls.

@github-actions
Copy link
Contributor

🎉 You're making a difference! We appreciate your effort and dedication. A reviewer will check it out soon, but in the meantime, give yourself a pat on the back. Keep up the great work! 💪🚀

⭐ Enjoying contributing? Star the project! ⭐Your contributions help this project grow, and we'd love your support in another way too! If you find this repo helpful, consider leaving a star 🌟 on GitHub.

@DannyvdSluijs
Copy link
Collaborator

@VINICIUSOLIVER Can you provide a test for this bug fix?

I've been looking at how headers could have been leaked but the retrieve method calls http_clear_last_response_headers before doing anything else
, see https://github.com/jsonrainbow/json-schema/blob/main/src/JsonSchema/Uri/Retrievers/FileGetContents.php#L32-L34

@zagor23
Copy link

zagor23 commented Feb 26, 2026

@VINICIUSOLIVER Can you provide a test for this bug fix?

I've been looking at how headers could have been leaked but the retrieve method calls http_clear_last_response_headers before doing anything else , see https://github.com/jsonrainbow/json-schema/blob/main/src/JsonSchema/Uri/Retrievers/FileGetContents.php#L32-L34

It calls http_clear_last_response_headers... on v6 (main) branch.
It doesn't call on 5.x.x branch, where this problem exists.
Version 5.3.1 introduced this PHP 8.5 fix:
b5a44b6

But it also introduced a leaking headers issue, since it does not call http_clear_last_response_headers.

However, on the main branch, we have this issue resolved in version 6.7.2:
def86e5

The bottom line is, I believe we need the same fix for the 5.x.x version as there is in 6.7.2.
@DannyvdSluijs FYI

@DannyvdSluijs
Copy link
Collaborator

Ahh okay, so that is actually why is asked if the PR shouldn't be against the 5.x.x branch. Since I'm free now I'll see what I can do ATm. Thanks for your efforts and sharing your findings.

DannyvdSluijs added a commit that referenced this pull request Feb 27, 2026
…ch (#893)

## Description
See #843 

## Related Issue
Port of #843 
Fixes #860 
Replaces #888 

## Type of Change

<!-- Mark the appropriate option with an "x" -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Other (please describe):

## Checklist

<!-- Mark completed items with an "x" -->

- [x] I have read the [CONTRIBUTING](CONTRIBUTING.md) guidelines
- [x] My code follows the code style of this project
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] All new and existing tests pass
- [x] I have updated the documentation accordingly
- [x] My changes generate no new warnings

## Additional Notes

<!-- Add any additional information that might be helpful for reviewers
-->
@DannyvdSluijs
Copy link
Collaborator

This PR was replaced by #893 and is part of the 5.3.2 release

https://github.com/jsonrainbow/json-schema/releases/tag/5.3.2

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.

3 participants