Questions tagged [xss]

Cross-Site Scripting: An attack method that involves injection of code or markup into a webpage. There are three major types of XSS: Reflected XSS, Stored XSS (aka persistent XSS) and DOM-based XSS (aka client side XSS).

Cross-Site Scripting (XSS) is an injection attack. It is called XSS to avoid misunderstanding with CSS (Cascading Style Sheets). XSS is in OWASP top 10 list since 2004. There are three common XSS types: Stored, Reflected and DOM based. Here is the explanation for two common types of XSS:

  1. Stored (persistent): Everywhere in a web application that stores data from user and retrieves later could be vulnerable to this type. For example, malicious script is commented by attacker for a post in a blog, script is stored as a comment in database and then is retrieved and executed automatically on targeted user's browser when the post is visited.
  2. Reflected (non-persistent): In this type, malicious code is put in URL as a parameter and then URL is sent to the targeted user. When the URL is opened, malicious code will be executed automatically by the browser.

XSS attacks are prevented by user input validation and sanitization. Everywhere an input is taken must be validated and sanitized to avoid malicious script injection. Validation methods are based on whitelisting and blacklisting.

XSS attacks are common on the web and should be prevented. XSS vulnerability could be leveraged by attacker to hijack session and even trigger DOS attack. There is a good detailed explanation about XSS attacks in The Web Application Hacker's Handbook (Chapter 12).

There are some useful best practices in OWASP for XSS prevention:

  1. Cross Site Scripting Prevention Cheat Sheet
  2. DOM based XSS Prevention Cheat Sheet

Vulnerability scanners could be used to detect XSS in web applications, here are some useful links for such tools:

  1. Acunetix
  2. Tenable
  3. Rapid7
  4. NetSparker
1463 questions
115
votes
9 answers

Why is it dangerous to open a suspicious email?

I would like to know why is it considered to be dangerous to open an email from an unknown source? I am using Gmail and I thought it's only unsafe to download an attachment and run it. The first thing that came into my mind was what if the email…
Tomas
  • 1,331
  • 3
  • 10
  • 10
92
votes
4 answers

How does XSS work?

I have very little experience in web development, but I'm interested in security. However, I haven't fully understood how XSS works. Can you explain it to med? The Wikipedia article give me a good idea but I don't think I understand it very well.
Ither
  • 1,039
  • 1
  • 9
  • 9
81
votes
6 answers

How does CORS prevent XSS?

I recently learned about CORS and got the impression that its purpose is to prevent XSS. With CORS, the browser blocks requests to different domains, unless particular headers are in place. But if a person with malicious intent injects some…
Gigi
  • 1,280
  • 1
  • 11
  • 12
71
votes
1 answer

Tell browser my site has no scripts

I have created a Tor hidden service site which has absolutely no JavaScript or other types of client side scripts. The page is HTML, CSS, images, and some JSP for handling user input. I encourage users to use NoScript, however many times users do…
k1308517
  • 1,272
  • 14
  • 27
71
votes
5 answers

Strange Payment Gateway

I have a freelance client that wants me to integrate a payment gateway into their Woocommerce site but I am being increasingly concerned about their choice of provider and the project as a whole. The Issues Against my advice the client has selected…
user5451386
  • 803
  • 6
  • 7
60
votes
9 answers

How hard should I try to prevent a user from XSSing themselves?

Let's say a user can store some data in a web app. I'm now only talking about that sort of data the user can THEMSELVES view, not that is intended to be viewed by other users of the webapp. (Or if other users may view this data then it is handled to…
gaazkam
  • 5,607
  • 11
  • 24
  • 37
56
votes
5 answers

IMG tag vulnerability

Is it safe to display images from arbitrary domains? I.e. let's say I have an image on my page: What if image.gif will return some js attack vector, but not the image? Is there any known vectors? I've tried…
Paul Podlipensky
  • 2,837
  • 4
  • 21
  • 25
53
votes
6 answers

Does injecting querystring values directly into HTML pose a security risk?

Someone reported a bug on my site that I don't really consider an issue. My site has an URL akin to this: www.site.com/ajax/ads.asp?callback=[text injection] So filetype is application/json, and I don't see how that can affect security of site. His…
Daniel
  • 1,422
  • 3
  • 21
  • 32
53
votes
1 answer

Is Django's built-in security enough?

I have learned that Django provides built-in protection against the three main types of web app attacks (SQL injection, XSS and CSRF), which is really awesome. Yet I have spoken to a few Django developers and they have essentially told me not to…
pleasedesktop
  • 633
  • 1
  • 6
  • 6
50
votes
5 answers

New XSS cheatsheet?

There is a great list of XSS vectors avaliable here: http://ha.ckers.org/xss.html, but It hasn't changed much lately (eg. latest FF version mentioned is 2.0). Is there any other list as good as this, but up to date?
naugtur
  • 1,095
  • 2
  • 12
  • 15
50
votes
4 answers

Why aren't sessions exclusive to an IP address?

Given the appropriate XSS vulnerability, an attacker can hijack somebody's session with the data that's passed to and from the server. Why aren't sessions always exclusive to the IP they were started on? i.e., when would a website/service need to…
user81147
48
votes
2 answers

Is including the data scheme in your Content Security Policy safe?

I have a Cordova app that transforms some images to base64. This violates CSP with this message: Refused to load the image 'data:image/svg+xml;charset=US-ASCII,%3C%3Fxml%20version%3D%221.0%22%20encod…E%3C%2Fg%...%3C%2Fsvg%3E' because it violates…
Martin Verner
  • 585
  • 1
  • 4
  • 8
47
votes
3 answers

I found obfuscated code in a comment on my blog. What should I do?

Today I was checking comments on my blog and I found a strange comment, here is the exact text