fix: Adjust filtering logic for secure contexts; improve tests #579
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.
Title
fix: Update filtering logic to respect secure contexts and enhance related tests
Description
This PR addresses issue #564 by modifying the multiaddr filtering logic in the trustless-gateway module to ensure that allowInsecure: false respects Secure Contexts.
Changes Made:
IP Address Filtering:
Modified the filter to ensure that when allowInsecure is false, a multiaddr with "127.0.0.1" as the IP address will still be considered valid. This addresses the need to handle secure contexts properly even when allowInsecure is disabled.
Domain Filtering:
Adjusted the filter to ensure that when allowInsecure is false, a multiaddr with "localhost" as the domain will be treated as valid.
Updated the filter to handle domains with a parent domain of "localhost", such as example.localhost, foobar.localhost, and *.localhost.
Tests Added:
Added tests to verify that the changes work as intended:
IP Address Test: Ensures that "127.0.0.1" is treated correctly when allowInsecure is false.
Domain Test: Verifies that "localhost" and parent domains of "localhost" are handled correctly when allowInsecure is false.
Related: GitHub Issue #564
Notes & open questions
None at the moment. The changes have been tested and are working as expected.
Change checklist