Repository navigation
Fix HTML in marker message - #10278
Conversation
|
Do we need to worry about XSS here? |
c4a5a20 to
e3f38ad
Compare
Unescapes text when setting innerHTML for marker
|
I accidentally closed this! I don't think XSS is an issue but I only tried setting a marker message with Maybe it makes more sense to allow certain HTML tags or build options for setting text colours? |
I think this is the right call. Or even, since we already support ANSI escapes... we could allow (and document) the use of ANSI escapes for colored text, and ask users to use things like If we go that route, I think it would suffice to have the text "rendered" by a virtual console. I think we do something similar e.g. here: |
Allows ANSI colors and formatting for marker text
|
I've managed to switch over to using the VirtualConsole to render the ANSI codes. I was a bit stuck for a bit until I realized the trim was removing the ANSI escape characters. I have tried to inject HTML into the marker text and it's escaped as expected. I've retargeted to merge into spotted wakerobin since the docs will need updating. |
kevinushey
left a comment
There was a problem hiding this comment.
Very nice!
The next thing we could do is update the documentation in the rstudioapi package, which provides the user-facing interface to source marker generation. That documentation lives here:
Would you be willing to update the documentation there, giving a note that ANSI escapes are supported? (And so, colors as generated via the cli package can be used.)
|
We can also add a stub to the relevant NEWS file for SW? |
|
I've reset the NEWS file and added in the change. The doc change is over here: rstudio/rstudioapi#242 |
|
What types of text and content can the VirtualConsole render using ANSI escapes? |
|
Any of the color and background color codes could be used (ie. |
|
Thanks for the clarification @timtmok. I understand the need to avoid exploits but I think that the colored or styled text in #9010 was primarily to demonstrate the issue and not actually how users would like to use the feature. Personally, I was looking at using source markers with rich text as a way to provide better feedback to users who are learning R. Being able to include basic HTML, including things like links, lists, formatted text, etc (essentially the HTML produced by strict markdown) made this feature attractive for that purpose, especially since the feedback could be linked to a specific line. This would be even more useful when combined with #10062. There are also a few other IDEs that have this feature and show rich text in linting-related popovers. |
For what it's worth, @romainfrancois's work in #10299 should make it possible to create custom hyperlinks here as well. The only thing that might not fit here would be lists. If we wanted to support this case while remaining safe, we could (in theory) allow for strict Markdown text, which we'd then render to HTML before display. I think it'd be helpful to have an illustrative example of what kind of error you might expect an R user to see, and what text / output you'd like to be able to display, + what interactive features that could have. We could also just support all of HTML, ANSI text, and strict Markdown -- it sounds like I missed the simple fact that we already had the infrastructure for rendering HTML, but needed a change in |
|
Strict markdown would definitely work for me, or even HTML with a subset of allowed tags. One example might be the goodpractice package, where source markers could be used to provide package authoring advice, e.g.
Another example would be auto-grading messages for example through gradethis. In this scenario, a grading script could read an R script or R Markdown document and produce teaching-related content or advice to a learner. Here's an example of the feedback we might want to provide:
This example brings up another idea. It would be extra awesome if there were a mechanism to interact with the IDE in basic ways. The one that comes to mind specifically would be to be able to open a help topic in the Help pane -- rather than linking to external documentation as in the example above. |


Intent
Addresses #9010

Allow HTML in the marker message
Approach
Unescapes text when setting innerHTML for marker. The marker has escaped text so it would never be processed as HTML in the marker pane.
Automated Tests
none
QA Notes
Marker text containing HTML will need to be escaped or it will be rendered as HTML.
Setting the text to
<div style="color:red;">I am red</div>should be treated as literal text when showing up in the marker pane.Checklist
NEWS.md