Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HtmlSanitizer] Add support for securing links#60539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

Spomky
Copy link
Contributor

@SpomkySpomky commentedMay 25, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix #
LicenseMIT

IntroduceensureSafeBlankTarget to automatically addrel="noopener noreferrer" to<a> elements withtarget="_blank", mitigating reverse tabnabbing risks.

<!-- Before --><ahref="https://site.example"target="_blank">Outgoing link</a><!-- After --><ahref="https://site.example"target="_blank"rel="noopener noreferrer">Outgoing link</a>

TheallowUnsafeBlankTargets method allows opting out of this behavior if needed.

ℹ️ Info: Modern browsers already considernoopener event if missing. However the presence of therel attribute is still considered as [a good practice]
(https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html#tabnabbing) by the OWASP.
⚠ Warning: I modifiedNode::setAttribute to allow overwriting existing attributes. I might have missed the reason for the commentAlways use only the first declaration (ease sanitization).
⚠ Warning: The logic is implemented inDomVisitor. It works, however I am wondering if an abstraction is needed.

Introduce `ensureSafeBlankTarget` to automatically add `rel="noopener noreferrer"` to `<a>` elements with `target="_blank"`, mitigating reverse tabnabbing risks. The `allowUnsafeBlankTargets` method allows opting out of this behavior if needed. Included tests validate the new functionality.
@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.3" but it seems your PR description refers to branch "7.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@nicolas-grekas
Copy link
Member

/cc@tgalopin can you please check this PR?

@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

I'm mixed on this one:browsers already implement the mitigation.
When people will upgrade to Symfony 7.4, even more people will have upgraded to a recent enough browser.

To me, this feels like a niche and dying concern. People that care should configure the sanitizer on their own so that we can keep the code simpler IMHO.

@@ -58,10 +58,7 @@ public function getAttribute(string $name): ?string

public function setAttribute(string $name, ?string $value): void
{
// Always use only the first declaration (ease sanitization)

Choose a reason for hiding this comment

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

I'd like we really understand what this means before removing.

@Seldaek
Copy link
Member

I agree this isn't really needed, considering doing this only requires this (or similar):

            ->forceAttribute('a', 'rel', 'nofollow noindex noopener')

Of course this will apply to all links and not just target=_blank ones, but I think this is probably safer. Why should other targets not have the noopener flag? They open in a new window too, so IMO this PR introduces a vulnerability.

@Spomky
Copy link
ContributorAuthor

OK noted. Many thanks for your feedback.
So let's close it.

@SpomkySpomky closed thisJun 2, 2025
@SpomkySpomky deleted the features/safe-target-blank branchJune 2, 2025 13:55
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

5 participants
@Spomky@carsonbot@nicolas-grekas@Seldaek@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp