Fix over-blocking of safe URLs by the unsafe link filter - #1131
Merged
colinodell merged 2 commits intoJul 12, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regex anchoring bug in the “unsafe link” detection logic which previously caused safe URLs to be misclassified as unsafe when they merely contained vbscript:, file:, or data: later in the URL (e.g., in query parameters), resulting in dropped href/src when unsafe links are forbidden.
Changes:
- Add unit tests covering
RegexHelper::isLinkPotentiallyUnsafe()for dangerous leading schemes and safe URLs containing those substrings elsewhere. - Fix
REGEX_UNSAFE_PROTOCOLso the^anchor applies to all protocol alternatives.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/unit/Util/RegexHelperTest.php | Adds data-driven tests reproducing the over-blocking and validating safe/unsafe URL cases. |
| src/Util/RegexHelper.php | Corrects the unsafe-protocol regex to properly anchor all alternatives at the start of the URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
colinodell
approved these changes
Jul 12, 2026
colinodell
left a comment
Member
There was a problem hiding this comment.
Thanks for catching and fixing this!
Member
Author
|
Nice, this was merged in the JS package too, so they are kept in sync. :) |
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.
When
allow_unsafe_linksis disabled, the^anchor inREGEX_UNSAFE_PROTOCOLbinds only to the first alternative, sovbscript:,file:, anddata:match anywhere in the URL rather than just at the start. Safe links such as https://example.com/view?src=data:image/png are misclassified as unsafe and silently lose theirhref/src.The first commit adds tests demonstrating the bug and the second applies the one-line fix.
The JS implementation has a similar bug: commonmark/commonmark.js#305.