-
Notifications
You must be signed in to change notification settings - Fork 47.9k
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
Allow passing a string directly to dangerouslySetInnerHTML #1515
Conversation
Instead of checking |
I thought about that and the primary reason I don't want to do that is; if you pass an object with a So apart from passing an object with an uintended |
I think if we're going to do this we should just break it now rather than continue to support |
+1 for dropping |
I'm down. Will be a bit of work to update internally but it's worth it. I think we should probably support both for a release though. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
function frameworkLevelBlessedFunction(name) {
return { __html: 'I\'m sure this is safe, ' + encode(name) + '!' };
} Now you can lint every other caller... function indirection(data) {
return frameworkLevelBlessedFunction(data.name);
} and components... render() {
return <div dangerouslySetInnerHTML={indirection(this.props.data)} />;
} to make sure that none of them declare However, you ALWAYS have to lint against people setting I would be fine with allowing |
That logic makes sense to me. I'm in favor of keeping the current situation because it's too hard for most people to set up lint rules to forbid innerHTML and people will end up just writing insecure code instead. |
@sebmarkbage Interesting perspective, but if |
Is there a pattern for this in other frameworks / libraries / languages to indicate it's unsafe? "dangerous" is slightly more annoying to type than "unsafe", so let's do that.
(We should probably also deprecate nicely with a warning and letting both work for a release) |
@zpao I personally prefer the sound of PS. We should also document the purpose of |
Follow-up; perhaps there should be a |
I split the naming discussion into #2134 So this PR should probably be closed. I'm leaving it open for now until another issue/PR is opened to address the "lack of documented justification" for EDIT: I meant "lack of documented justification", not "lack of justification" :). |
Not sure what you mean about a new issue/PR. Are there still concerns about it's justification? |
@sebmarkbage Not in my opinion, but AFAIK the justification is not documented anywhere. |
Good point. Let's add an explanation to the docs before closing this.
|
In response to #1370 and to move the discussion along.
As far as I understand it,
{__html: X}
is not really intended as another safe-guard, but a remnant of how XHP worked/works.Here's a fully backwards-compatible implementation, with a bunch of test-cases added to ensure correct functioning.