Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target blank dynamic link should fail #1784

Merged
merged 3 commits into from
May 15, 2018

Conversation

kenearley
Copy link

@kenearley kenearley commented May 11, 2018

Made from the suggestion in @ksdmitrieva's issue, I believe this is the right approach even though you would get false positives since it cannot check for relative paths in dynamic links. However, I think that would be rare since it's not best practice to use target='_blank' on internal links anyway.

@ljharb
Copy link
Member

ljharb commented May 12, 2018

I think that since it can generate false positives, it should be behind an option.

@kenearley
Copy link
Author

kenearley commented May 12, 2018 via email

@kenearley
Copy link
Author

kenearley commented May 14, 2018

@ljharb I've added the option and set "always" as the default since it seems the safer state.

One thing I noticed is that you still would not get the error if you assigned the href using the spread operator to assign the href prop. Should that be covered in another option?

@ljharb
Copy link
Member

ljharb commented May 14, 2018

I think if you can expand the error so it applies to an inline spread-"href", that would be generally useful?

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM

@kenearley
Copy link
Author

To be fair, if you set ALL your props within an object (eg. target, rel, etc) and then use the spread, it would bypass all these checks. Am I right?

@ljharb
Copy link
Member

ljharb commented May 14, 2018

Yes, that's generally true - but spreading props is an antipattern anyways, so it also might be OK to allow the checks to be bypassed in that case.

@ksdmitrieva
Copy link

Thanks, @kenearley, for moving this along. The whole idea of the vulnerability is when untrusted link is added without "rel=noopener". When the link is hard-coded, it's most likely trusted. Otherwise, why would you add untrusted links to your application. Untrusted links will most likely come from user input. Anyway, I'm glad this is added.
Interesting edge case with the spread operator. If it's an antipattern, I wonder if there is a rule that highlights that usage.

@ljharb ljharb merged commit dec6791 into jsx-eslint:master May 15, 2018
@kenearley kenearley deleted the target-blank-dynamic-link branch May 17, 2018 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants