Skip to content

Remove more .html(...) calls.#5041

Closed
jdfreder wants to merge 6 commits intoipython:masterfrom
jdfreder:html-scrub
Closed

Remove more .html(...) calls.#5041
jdfreder wants to merge 6 commits intoipython:masterfrom
jdfreder:html-scrub

Conversation

@jdfreder
Copy link
Copy Markdown
Contributor

@jdfreder jdfreder commented Feb 5, 2014

  • Removed the .html(...) calls that could be removed without rewriting lots of notebook code.
  • Added comment to each remaining call to .html(...)
  • Added TODO: SCRUB comments before every .html(...) call that needs to be scrubbed.

Closes #5034

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is no danger to using html here, and the html case is clearer. We only need to be concerned about html calls where there can be variable input. Literals are not an issue.

@jdfreder
Copy link
Copy Markdown
Contributor Author

jdfreder commented Feb 6, 2014

Comments addressed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can just use html, and just be more careful above about what we allow in. Only prompt_number is input, and we can verity that it's an integer, which is perfectly safe. No need for these shenanigans.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In fact, with encodeURIComponent above, I'm not sure there is anything to change here at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, and it should be one of the rare injection point that is tested :-) And I think that like IO, that deal with encode/decode. Escaping should be handled as soon as things get grabbed from the .ipynb not at higher lever.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The problem I have with using .html() in situations where we could get by with .text() is that the content we are passing to .html() today may be safe. But over time, things can creep in-the part of the code creating the content is usually far from the actual call to .html(). I think we should be very aggressive about removing uses of html and all remaining ones should have:

  1. A comment about why the content is absolutely always safe....or
  2. A call to is_safe to verify the content is in fact safe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As illustrated by the patch here, this is not actually a case where we can get by with .text(). Escaping the prompt input (already done) and then building html with literals (already done) is perfectly safe.

@minrk
Copy link
Copy Markdown
Member

minrk commented Feb 6, 2014

I think this is a bit overzealous, and we need to be clearer about when and why .html is unsafe. Often, it is perfectly safe, and the right thing to use. .html is safe when:

  • it is a simple literal
  • we control what goes into the call
  • html is escaped

Because of this, the 'CAUTION' warnings on every .html call are much too enthusiastic. A simple comment about why each call is reasonable should be sufficient, and when it's just a literal, a comment even seems unnecessary because it is obviously perfectly fine.

@ellisonbg ellisonbg self-assigned this Feb 8, 2014
@ellisonbg ellisonbg added this to the 2.0 milestone Feb 8, 2014
@jdfreder
Copy link
Copy Markdown
Contributor Author

I'll go back over this and remove the overzealous comments. I think it would be easier for me to just go through with a different PR and use the changed lines here as a reference of where I need to jump to- closing this one here.

@jdfreder jdfreder closed this Feb 11, 2014
@jdfreder jdfreder deleted the html-scrub branch March 10, 2014 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit the places where we call .html(something)

4 participants