Saturday, December 2, 2023

What is XSS (Cross-Site Scripting)? – A Detailed Understanding Of the Type of XSS

XSS is a very commonly exploited vulnerability type that is very widely spread and easily detectable, and also it is one of the important vulnerabilities in OWASP TOP 10.

Cross-site scripting, which is often called “XSS,” is one of the most common security flaws in web services today. XSS is mainly about running arbitrary code in a user’s browser, but it is much more than that.

It breaks the trust between a website and its users, and when it’s used in a bad way, it can lead to a number of bad things.

Table of Contents

What is XSS(Cross-Site Scripting )?
Understanding XSS – Cross-Site Scripting
Potential Risks of Cross-Site Scripting
Defenses against Cross-Site Scripting

What is XSS(Cross-Site Scripting )?

Cross-site scripting is a type of security flaw that is often found in web apps. It lets attackers put malicious code on web pages that other people can see.

Then, these scripts can be run in the victim’s browser, which could lead to a number of bad things, like stealing session cookies, messing up web pages, or doing things on the victim’s behalf without their knowledge.

XSS flaws happen when a web application puts untrusted data on its pages without properly validating or escaping it. This lets an attacker put code that can be run on the page.

Because XSS attacks can cause a lot of damage and are common, it’s important for coders to know about them and take steps to stop them.

An attacker can inject untrusted snippets of JavaScript into your application without validation.

This JavaScript is then executed by the victim who is visiting the target site. It is classified into three types.

  • Reflected XSS
  • Stored XSS
  • DOM-Based XSS

In Reflected XSS, an attacker sends the victim a link to the target application through email, social media, etc.

This link has a script that executes when visiting the target site.

In Stored XSS, the attacker can plant a persistent script in the target website which will execute when anyone visits it.

With DOM-based XSS, no HTTP request is required; the script is injected as a result of modifying the DOM of the target site in the client-side code in the victim’s browser and is then executed.

Understanding XSS – Cross-Site Scripting


                                   Searched for <strong>gbhackers</strong>


Imagine that we have a URL like this, and we are searching for gbhackers, and it will reflect the following query in the browser.

We trust the domain, and we trust the resource being entered in the search page, so now the untrusted part gbhackers was the query string entered by the browser; the attacker can manipulate the value anything they like, for example, they change like this <script>alert(document.cookie)</script>.

This is just a simple query to pop up an alert on the webpage if someone requested the page of the attacker’s website and passed the document.

Cookies as a parameter in the website, then the attacker can gather all cookies. If they get Auth cookies, they can simply hijack user sessions.

XSS Attack

Potential Risks of Cross-Site Scripting

The attacker can compromise or take over the victim’s user account in the application.

They could retrieve data from the target web application, modify content on the target page, redirect the victim to another malicious or spoof site, or use it to install other malware on the victim’s system.

The consequences of any of the above can seriously impact your ability to conduct business, your customers, and your organization’s reputation.

XSS Attack Flow

Defenses against Cross-Site Scripting

Cross-site scripting (XSS) attacks can be stopped by using good coding techniques, and security tools, and being aware. Here is a complete list of ways to protect against XSS:

  • What input do we trust?
  • Does it adhere to expected patterns?
  • Never reflect untrusted data.
  • Applies to data within our database too.
  • Encoding of context(Java/attribute/HTML/CSS).
  • HttpOnly and Secure Flags
  • Use Frameworks that Automatically Handle XSS
  • Implement WAF (Web Application Firewall)


Cross-site scripting is a strong example of how complicated web services are and how vulnerable they can be. As we’ve looked at the different kinds of XSS threats, it’s clear that they can be different, but their effects are always bad.

They make it harder for people to trust websites, which could lead to unauthorized access to data, spoofing, or even bad things happening without the user’s understanding.

As technology gets better, so do attacks. However, with a thorough understanding of security measures and careful use, we can try to stay one step ahead of possible risks like XSS.


1. What is XSS in HTML?

Cross-site scripting is a weakness in HTML that lets attackers put bad code into web pages. Once these scripts are run in a user’s browser, they can steal information, take over sessions, or change the look of websites.

It happens when a web application puts user input that hasn’t been checked into its HTML output, which lets scripts run without the user’s permission. Input validation, output encoding, and using security tags like Content Security Policy are all good ways to protect yourself.

2. What are the three main types of XSS vulnerabilities?

  • Stored XSS (Persistent XSS): The malicious script is saved on the server and executed when a user accesses a specific page or feature.
  • Reflected XSS (Non-Persistent XSS): The malicious script is executed immediately after being injected, typically via URL parameters.
  • DOM-based XSS: The vulnerability exists in client-side scripts that modify the Document Object Model (DOM) of a page.

3. What type of XSS is stored?

Stored XSS, which is also called Persistent XSS, is a kind of Cross-Site Scripting vulnerability in which the attacker’s malicious script is saved on the target computer.

When other people go to the page or feature that is affected, the script is run in their browsers. This kind of XSS is especially dangerous because the target doesn’t have to do anything, like click on a dangerous link.

Instead, the attack can happen when someone visits a website that has been hacked. Stored XSS is a major security risk because it stays around and affects more people.


Latest articles

Active Attacks Targeting Google Chrome & ownCloud Flaws: CISA Warns

The CISA announced two known exploited vulnerabilities active attacks targeting Google Chrome & own...

Cactus Ransomware Exploiting Qlik Sense code execution Vulnerability

A new Cactus Ransomware was exploited in the code execution vulnerability to Qlik Sense...

Hackers Bypass Antivirus with ScrubCrypt Tool to Install RedLine Malware

The ScrubCrypt obfuscation tool has been discovered to be utilized in attacks to disseminate the RedLine Stealer...

Hotel’s Hacked Logins Let Attacker Steal Guest Credit Cards

According to a recent report by Secureworks, a well-planned and advanced phishing attack was...

Critical Zoom Vulnerability Let Attackers Take Over Meetings

Zoom, the most widely used video conferencing platform has been discovered with a critical...

Hackers Using Weaponized Invoice to Deliver LUMMA Malware

Hackers use weaponized invoices to exploit trust in financial transactions, embedding malware or malicious...

US-Seized Crypto Currency Mixer Used by North Korean Lazarus Hackers

The U.S. Treasury Department sanctioned the famous cryptocurrency mixer Sinbad after it was claimed...
Cyber Writes
Cyber Writes
Work done by a Team Of Security Experts from Cyber Writes ( - World’s First Dedicated Content-as-a-Service (CaaS) Platform for Cybersecurity. For Exclusive Cyber Security Contents, Reach at: [email protected]

API Attack Simulation Webinar

Live API Attack Simulation

In the upcoming webinar, Karthik Krishnamoorthy, CTO and Vivek Gopalan, VP of Products at Indusface demonstrate how APIs could be hacked.The session will cover:an exploit of OWASP API Top 10 vulnerability, a brute force account take-over (ATO) attack on API, a DDoS attack on an API, how a WAAP could bolster security over an API gateway

Related Articles