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.

Security question: Use HTML by default for Toasts/Tooltips/Autocomplete and expose an XSS

See original GitHub issue

Expected Behavior

Don’t execute html/javascript by default for Toasts, Tooltips and Autocomplete

Current Behavior

By default when you add dynamics contents like Toast, Tooltips and autocomplete you inject inputs data as HTML. I think all people who use MaterializeCss implement compontents like your examples.

It’s a bad practice and by default, your input data could be sanitize or use jquery.text(‘untrustData’) instead jquery.html(‘untrustData’) or innerHTML = ‘untrustData’.

Possible Solution

If you want allow HTML, why not but sanitize the html and don’t allow javascript. If the end user want allow HTML and javascript add a new configuration with a parameter like options : { allowUnsafeData: true }

Steps to Reproduce (for bugs)

Toast

var userId = '<IFRAME SRC="javascript:alert(document.cookie);"></IFRAME>'
M.toast({html: `userId: ${userId} fail`})

Tooltips

<a class="btn tooltipped" data-position="bottom" data-tooltip="<IFRAME SRC='javascript:alert(document.cookie);'></IFRAME></script>">Hover me!</a>

Autocomplete

$('input.autocomplete').autocomplete({
    data: {
	    "Apple": "\"><IFRAME SRC=\"javascript:alert(document.cookie);\"></IFRAME>",
	    "Microsoft": null,
	    "Google": 'https://placehold.it/250x250',
    }
});

Context

I’m agree about the developper need control his data before inject it in a third party library but sametime we forget to do it.

How i find this case :

  1. (Client) Send javascript in a field
  2. (Server) Server fail and return message with javascript
  3. (Client) Reuse the message from the server and use the Toast
  4. I have a reflected XSS

It’s my fault, I didn’t validate datas and I returned this script without sanitize. If by default your library don’t allow html, I will not find this behavior.

Your Environment

  • Version used: 0.100.2 and 1.0.0

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:15
  • Comments:30 (12 by maintainers)

github_iconTop GitHub Comments

11reactions
OlivierJMcommented, May 2, 2019

This is still reported here https://www.npmjs.com/advisories/818 on npm as moderate vulnerability, that means Github and npm will keep popping up the security issue.

@Dogfalo any idea when we can expect the fix for this ?

9reactions
Dogfalocommented, Apr 9, 2019

Hi @FINDarkside, Thanks for bringing this to our attention. In the tooltip and toast, it was intended to allow html as we wanted to allow developers to customize the content. We should have made warnings clear that the input was not sanitized.

However, we will make a change to sanitize html input for all 3 of the components to help protect developers who haven’t sanitized their inputs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross Site Scripting Prevention - OWASP Cheat Sheet Series
This cheat sheet provides guidance to prevent XSS vulnerabilities. ... In order to add a variable to a HTML context safely, use HTML...
Read more >
Is HTML validation and XSS validation required in API side?
Yes, you must validate any income data that ingress in your API. Even if the injected code does not threaten your API, if...
Read more >
10.1. Preventing Cross Site Scripting Vulnerabilities
It can be difficult to write code that is safe from XSS security ... There are several reasons why you do not want...
Read more >
What is Cross-Site Scripting? XSS Cheat Sheet - Veracode
Most commonly, this is a combination of HTML and XSS provided by the attacker, but XSS can also be used to deliver malicious...
Read more >
Cross-Site Scripting (XSS) and Octopus Deploy
By default, your Octopus Server implements a strict Content Security Policy (CSP). This policy is configured to limit exposure to XSS when using...
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