Questions tagged [xss]

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications that enables malicious attackers to inject client-side script into web pages viewed by other users. An exploited cross-site scripting vulnerability can be used by attackers to bypass access controls such as the same origin policy.

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications.

In a typical XSS attack the hacker infects a legitimate web page with his malicious client-side script. When a user visits this web page the script is downloaded to his browser and executed. There are many slight variations to this theme, however all XSS attacks follow this pattern, which is depicted in the diagram below (Ref).

How XSS works

An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came from a trusted source, the malicious script can access any cookies, session tokens, or other sensitive information retained by your browser and used with that site. These scripts can even rewrite the content of the HTML page.

More information: The Open Web Application Security Project.

4479 questions
1265
votes
16 answers

How can I sanitize user input with PHP?

Is there a catchall function somewhere that works well for sanitizing user input for SQL injection and XSS attacks, while still allowing certain types of HTML tags?
Brent
  • 23,354
  • 10
  • 44
  • 49
307
votes
9 answers

How can I prevent XSS with HTML/PHP?

How do I prevent XSS (cross-site scripting) using just HTML and PHP? I've seen numerous other posts on this topic, but I have not found an article that clear and concisely states how to actually prevent XSS.
TimTim
  • 3,191
  • 4
  • 18
  • 8
230
votes
6 answers

What is the http-header "X-XSS-Protection"?

So I've been toying around with HTTP for fun in telnet now (i.e. just typing in telnet google.com 80 and putting in random GETs and POSTs with different headers and the like) but I've come across something that google.com transmits in it's headers…
midc111
  • 2,333
  • 2
  • 15
  • 12
191
votes
2 answers

What does it mean when they say React is XSS protected?

I read this on the React tutorial. What does this mean? React is safe. We are not generating HTML strings so XSS protection is the default. How do XSS attacks work if React is safe? How is this safety achieved?
user1210233
  • 2,730
  • 5
  • 24
  • 31
141
votes
14 answers

How to pass parameters to a Script tag?

I read the tutorial DIY widgets - How to embed your site on another site for XSS Widgets by Dr. Nic. I'm looking for a way to pass parameters to the script tag. For example, to make the following work:
Tomer Lichtash
  • 9,002
  • 16
  • 55
  • 71
131
votes
10 answers

WARNING: sanitizing unsafe style value url

I want to set the background image of a DIV in a Component Template in my Angular 2 app. However I keep getting the following warning in my console and I don't get the desired effect... I am unsure if the dynamic CSS background image is being…
Mark Sandman
  • 3,293
  • 12
  • 40
  • 60
116
votes
6 answers

Do htmlspecialchars and mysql_real_escape_string keep my PHP code safe from injection?

Earlier today a question was asked regarding input validation strategies in web apps. The top answer, at time of writing, suggests in PHP just using htmlspecialchars and mysql_real_escape_string. My question is: Is this always enough? Is there more…
Cheekysoft
  • 35,194
  • 20
  • 73
  • 86
105
votes
11 answers

How do you set up use HttpOnly cookies in PHP

How can I set the cookies in my PHP apps as HttpOnly cookies?
Scott Warren
  • 1,069
  • 2
  • 9
  • 5
101
votes
3 answers

How do you use window.postMessage across domains?

It seems like the point of window.postMessage is to allow safe communication between windows/frames hosted on different domains, but it doesn't actually seem to allow that in Chrome. Here's the scenario: Embed an