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

Sim is vulnerable to xss #3

Open
phet-steele opened this issue Apr 4, 2017 · 10 comments
Open

Sim is vulnerable to xss #3

phet-steele opened this issue Apr 4, 2017 · 10 comments
Assignees
Labels

Comments

@phet-steele
Copy link

phet-steele commented Apr 4, 2017

Run the sim with ?stringTest=xss to be redirected. Running on current master (4/4 1:30 PM).

@jonathanolson
Copy link
Contributor

It's passing a string directly to HTMLText. @pixelzoom, can we remove the HTMLText part of this for chains, or replace it with subsuptext?

@pixelzoom
Copy link
Contributor

We could replace with SubSupText. But why is this not a general vulnerability for any sim that uses HTMLText?

@pixelzoom pixelzoom removed their assignment Apr 4, 2017
@jonathanolson
Copy link
Contributor

But why is this not a general vulnerability for any sim that uses HTMLText?

It's very much a general vulnerability if you pass a translated string (i.e. a string that can be controlled by query parameters) to an HTMLText. That's one of the primary reasons for the stringTest=xss testing.

We really need more rich-text support, whether that parses it and uses Text nodes (so it could be rendered in WebGL/etc.), or whether it's validation-based and uses HTMLText (which would reject or reform strings that could be potential exploits).

@pixelzoom
Copy link
Contributor

Rather than replace HTMText with SubSupText in the chains example, it would preferable to fix the vulnerability in HTMLText.

Also noting that that chains should include a SubSupText example, and it currently does not, see #4.

@jonathanolson
Copy link
Contributor

Rather than replace HTMText with SubSupText in the chains example, it would preferable to fix the vulnerability in HTMLText.

It's not a vulnerability in HTMLText directly, as it's designed to allow arbitrary content.

I'm looking into things like https://github.com/ecto/bleach for the browser, which would sanitize the incoming string to remove anything not on a whitelist.

If we have a list of desired rich-text support, it may be more beneficial to extend/generalize SubSupText.

@jonathanolson
Copy link
Contributor

Best solution so far looks to find an HTML parser (e.g. https://github.com/andrejewski/himalaya) and then either construct white-listed HTML from it (rendered with HTMLText), or to use that parsing to do the equivalent of a more-structured SubSupText that handles more markup with Text nodes.

e.g.:

himalaya.parse( '<b>boo <i>who</i></b><sup>2</sup>' );
// gives
[
  {
    "type": "Element",
    "tagName": "b",
    "attributes": {},
    "children": [
      {
        "type": "Text",
        "content": "boo "
      },
      {
        "type": "Element",
        "tagName": "i",
        "attributes": {},
        "children": [
          {
            "type": "Text",
            "content": "who"
          }
        ]
      }
    ]
  },
  {
    "type": "Element",
    "tagName": "sup",
    "attributes": {},
    "children": [
      {
        "type": "Text",
        "content": "2"
      }
    ]
  }
]

tagging for developer meeting discussion (I'll be able to describe the different approaches and their drawbacks).

jonathanolson added a commit to phetsims/scenery-phet that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/acid-base-solutions that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/area-builder that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/area-model-multiplication that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/arithmetic that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/atomic-interactions that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/balancing-act that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/balancing-chemical-equations that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/balloons-and-static-electricity that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/beers-law-lab that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/bending-light that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/build-a-molecule that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/build-an-atom that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/projectile-motion that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/proportion-playground that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/protein-synthesis that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/reactants-products-and-leftovers that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/resistance-in-a-wire that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/rutherford-scattering that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/scenery-phet that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/simula-rasa that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/states-of-matter that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/states-of-matter-basics that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/trig-tour that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/under-pressure that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/unit-rates that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/wave-on-a-string that referenced this issue Apr 5, 2017
jonathanolson added a commit to phetsims/scenery-phet that referenced this issue Apr 6, 2017
@jonathanolson
Copy link
Contributor

Documentation on RichText (for discussion during developer meeting):

Displays rich text with HTML-style tags by splitting it into multiple (child) Text nodes.

It should be a close to drop-in replacement for SubSupText, and supports the following markup and features:

  • <b> and <strong> for bold text
  • <i> and <em> for italic text
  • <sub> and <sup> for subscripts / superscripts
  • <u> for underlined text
  • <s> for strikethrough text
  • <font> tags with attributes color="cssString", face="familyString", size="cssSize"
  • <span> tags with a dir="ltr" / dir="rtl" attribute
  • Unicode bidirectional marks (present in PhET strings) for full RTL support

Examples from the scenery-phet demo:

  • new RichText( 'RichText can have <b>bold</b> and <i>italic</i> text.' ),
  • new RichText( 'Can do H<sub>2</sub>O (A<sub>sub</sub> and A<sup>sup</sup>), or nesting: x<sup>2<sup>2</sup></sup>' ),
  • new RichText( 'Additionally: <font color="blue">color</font>, <font size="30px">sizes</font>, <font face="serif">faces</font>, <s>strikethrough</s>, and <u>underline</u>' ),
  • new RichText( 'These <b><em>can</em> <u><font color="red">be</font> mixed<sup>1</sup></u></b>.' ),
  • new RichText( '\u202aHandles bidirectional text: \u202b<font color="#0a0">مقابض</font> النص ثنائي <b>الاتجاه</b><sub>2</sub>\u202c\u202c' )

@pixelzoom
Copy link
Contributor

In #3 (comment), it looks like @jonathanolson has created something new, RichText. Highly recommend to create a scenery-phet issue for reviewing that, rather than bury it in this issue.

@pixelzoom
Copy link
Contributor

I have moved discussion of RichText to phetsims/scenery-phet#300.

@zepumph
Copy link
Member

zepumph commented Sep 22, 2023

@jonathanolson is this still a problem? Ready to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants