hypernova icon indicating copy to clipboard operation
hypernova copied to clipboard

Encode closing Tag

Open jburghardt opened this issue 5 years ago • 8 comments

Currently encoding in the index.js only includes

const ENCODE = [
  ['&', '&'],
  ['>', '>'],
];

If a component is being rendered SSR and includes a property with a closing script tag, the script tag in the SSrendered HTML will close the hypernova script.

<script type="application/json" data-hypernova-key="App" data-hypernova-id="....">
   <!-- {"props": ..., "title":"</script "} 

which will throw an error in the JSON.parse method of the payload.

is there a reason closing tags are not encoded here ? Following changes would suffice:

var ENCODE = [
['&', '&amp;'],
['>', '&gt;'],
['<', '&lt;']
];

jburghardt avatar Oct 09 '19 11:10 jburghardt

</script shouldn't close anything? you'd need </script>, and the > is escaped.

ljharb avatar Oct 09 '19 18:10 ljharb

<script with a blank after the t does close the hypernova script

jburghardt avatar Oct 10 '19 07:10 jburghardt

It seems like indeed </ specifically should be escaped.

ljharb avatar Oct 10 '19 07:10 ljharb

This is what could happen

<html>
   <head></head>
   <body>
   
   <script type="application/json" id="hypernova-app"><!-- {"props": {"message": "Evil user comment containing </script ", "foo": "bar"}} --></script>
    
   <script type="text/javascript">
  document.addEventListener('DOMContentLoaded', function () {
   window.alert(document.getElementById('hypernova-app').innerHTML);
   });
   </script>
  
 </body>
</html>

jburghardt avatar Oct 10 '19 07:10 jburghardt

It seems like indeed </ specifically should be escaped.

escaping just < should be enough.

jburghardt avatar Oct 10 '19 08:10 jburghardt

That will cause a lot more escaping, of all html tags, unnecessarily. We should only escape the pair.

ljharb avatar Oct 10 '19 16:10 ljharb

Yep you are right, i updated the pull request.

jburghardt avatar Oct 11 '19 08:10 jburghardt

@duoertai could you please take a look at this issue?

csharplus avatar May 08 '22 00:05 csharplus