question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encode closing Tag

See original GitHub issue

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;']
];

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
jburghardtcommented, Oct 10, 2019

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>
1reaction
ljharbcommented, Oct 10, 2019

It seems like indeed </ specifically should be escaped.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML URL Encoding Reference - W3Schools
Character From Windows‑1252 From UTF‑8 space %20 %20 ! %21 %21 " %22 %22
Read more >
Encode and decode a piece of text to its HTML equivalent
The HTML character encoder converts all applicable characters to their ... to use the < character as it is used in the HTML...
Read more >
Escape </ in script tag contents - html - Stack Overflow
I came here looking for a way to universally escape </script> inside the JavaScript code. After bit of research I figured that if...
Read more >
WebD2: Common HTML Tags - University of Washington
An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text...
Read more >
html_escape - Rust - Docs.rs
For example, to put a text between a start tag <foo> and an end tag </foo> , use the encode_text function to escape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found