The Wayback Machine - https://web.archive.org/web/20241127054048/https://www.geeksforgeeks.org/what-is-cross-site-scripting-xss/
Open In App

What is Cross Site Scripting (XSS) ?

Last Updated : 28 Nov, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Cross Site Scripting (XSS) is a vulnerability in a web application that allows a third party to execute a script in the user’s browser on behalf of the web application. Cross-site Scripting is one of the most prevalent vulnerabilities present on the web today. The exploitation of XSS against a user can lead to various consequences such as account compromise, account deletion, privilege escalation, malware infection and many more. In its initial days, it was called CSS and it was not exactly what it is today. Initially, it was discovered that a malicious website could utilize JavaScript to read data from other website’s responses by embedding them in an iframe, run scripts and modify page contents. It was called CSS (Cross Site Scripting) then. The definition changed when Netscape introduced the Same Origin Policy and cross-site scripting was restricted from enabling cross-origin response reading. Soon it was recommended to call this vulnerability as XSS to avoid confusion with Cascading Style Sheets(CSS). The possibility of getting XSSed arises when a website does not properly handle the input provided to it from a user before inserting it into the response. In such a case, a crafted input can be given that when embedded in the response acts as a JS code block and is executed by the browser. Depending on the context, there are two types of XSS –

  1. Reflected XSS: If the input has to be provided each time to execute, such XSS is called reflected. These attacks are mostly carried out by delivering a payload directly to the victim. Victim requests a page with a request containing the payload and the payload comes embedded in the response as a script. An example of reflected XSS is XSS in the search field.
  2. Stored XSS: When the response containing the payload is stored on the server in such a way that the script gets executed on every visit without submission of payload, then it is identified as stored XSS. An example of stored XSS is XSS in the comment thread.

There is another type of XSS called DOM based XSS and its instances are either reflected or stored. DOM-based XSS arises when user-supplied data is provided to the DOM objects without proper sanitizing. An example of code vulnerable to XSS is below, notice the variables firstname and lastname : 

php




<?php
 
   if(isset($_GET["firstname"]) && isset($_GET["lastname"]))
   {  
 
       $firstname = $_GET["firstname"];
       $lastname = $_GET["lastname"];   
 
       if($firstname == "" or $lastname == "")
       {
 
           echo "<font color=\"red\">Please enter both fields...</font>";      
 
       }
 
       else           
       {
 
           echo "Welcome " . $firstname. " " . $lastname;  
 
       }
   }
   ?>


User-supplied input is directly added in the response without any sanity check. Attacker an input something like – 

html




<script> alert(1) </script>


and it will be rendered as JavaScript.   There are two aspects of XSS (and any security issue) –

  1. Developer: If you are a developer, the focus would be secure development to avoid having any security holes in the product. You do not need to dive very deep into the exploitation aspect, just have to use tools and libraries while applying the best practices for secure code development as prescribed by security researchers. Some resources for developers are – a). OWASP Encoding Project : It is a library written in Java that is developed by the Open Web Application Security Project(OWASP). It is free, open source and easy to use. b). The “X-XSS-Protection” Header : This header instructs the browser to activate the inbuilt XSS auditor to identify and block any XSS attempts against the user. c). The XSS Protection Cheat Sheet by OWASP : This resource enlists rules to be followed during development with proper examples. The rules cover a large variety of cases where a developer can miss something that can lead to the website being vulnerable to XSS. d). Content Security Policy : It is a stand-alone solution for XSS like problems, it instructs the browser about “safe” sources apart from which no script should be executed from any origin.
  2. Security researchers: Security researchers, on the other hand, would like similar resources to help them hunt down instances where the developer became lousy and left an entry point. Researchers can make use of – a). CheatSheets – 1. XSS filter evasion cheat sheet by OWASP. 2. XSS cheat sheet by Rodolfo Assis. 3. XSS cheat sheet by Veracode. b). Practice Labs – 1. bWAPP 2. DVWA(Damn vulnerable Web Application) 3. prompt.ml 4. CTFs c). Reports – 1. Hackerone Hacktivity 2. Personal blogs of eminent security researchers like Jason Haddix, Geekboy, Prakhar Prasad, Dafydd Stuttard(Portswigger) etc.


Previous Article
Next Article

Similar Reads

Difference Between XSS and SQL Injection
Cyber security has become an essential part of the digital world due to the rise in malicious attackers. Cyber security ensures to the protection of data, and systems from cyber attacks like Denial of Service attacks, Ransomware attacks, Virus attacks, etc. These attacks are possible by finding vulnerabilities in the system, network, or any softwar
4 min read
Cyber Security Interview Questions with Answers
Cybersecurity is the act of protecting computer systems, networks, programs, and data from digital attacks, unauthorized access, damage, or theft. Cybersecurity is a critical aspect of modern technology, with its importance growing as digital systems become increasingly integrated into our daily lives. With threats ranging from data breaches to mal
15+ min read
Introduction to Dirb - Kali Linux
Dirb is an online directory scanner that searches web servers for hidden files, directories, and pages. It is a free and open-source utility included in the Kali Linux distribution, a popular operating system for penetration testing and ethical hacking. Dirb may be used to detect typical web server folders and files, such as admin pages, backup fil
7 min read
How to hack android phones with Phonesploit
Understanding how to hack Android phones with Phonesploit has become a topic of interest and concern. Phonesploit is a powerful tool that allows users to remotely access and control Android devices, offering capabilities ranging from retrieving sensitive information to executing commands on the target device. This tool leverages vulnerabilities in
6 min read
Cyber Security Tutorial
Cyber security, also known as information technology security, refers to the practice of protecting systems, networks, and programs from digital attacks. These cyber-attacks are usually aimed at accessing, changing, or destroying sensitive information, extorting money from users, or interrupting normal business processes. This cybersecurity tutoria
6 min read
What is Google Dorking?
Google Dorking is a technique used by hackers and security researchers to find sensitive information on websites using Google's search engine. It is also known as Google hacking or Google Dorking. Search FiltersGoogle Dorking involves using advanced search operations in Google to search for specific keywords, file types, or website parameters. Thes
4 min read
Sniffing of Login Credential or Password Capturing in Wireshark
Wireshark is a free and open-source packet analysis tool that lets you capture and analyze network traffic in real-time. It is available for Windows, macOS, and Linux operating systems. Wireshark captures network packets and displays the captured data in a human-readable format for easy analysis and troubleshooting of network issues. It can scan a
3 min read
Ethical Hacking Tutorial
This Ethical Hacking tutorial covers both basic and advanced concepts of Ethical Hacking. Whether you are a beginner or an experienced cybersecurity professional, this tutorial is the perfect resource to learn how to tackle vulnerabilities and weaknesses in systems before malicious hackers can exploit them. From understanding the hacking basics to
11 min read
IP Filtering in Wireshark
Wireshark is a network packet analyzer or tracer. Network Packet Analyzer displays captured packet data in as much detail as possible. It is a popular open-source network protocol analyzer used by ethical hackers to analyze network traffic to identify vulnerabilities or potential security breaches. So, in this article, we will understand how we can
3 min read
Difference Between Conventional Crime and Cybercrime
Pre-requisites: Cybercrime, Cybercrime Causes, And Measures To Prevent It Crime generally refers to an illegal act that's punishable by law and regulation. According to Merriam-Webster, wordbook crime is described as “an act or the commission of an act that's interdicted or the elision of a duty that's commanded by a public law and that makes the l
3 min read
What is Salami Attack?
A salami attack is a method of cybercrime that attackers or a hacker typically used to commit financial crimes. Cybercriminals steal money or resources from financial accounts on a system one at a time. This attack occurs when several minor attacks combine to create a sturdy attack. because of this sort of cybercrime, these attacks frequently go un
3 min read
Nmap Cheat Sheet
Nmap (Network Mapper) is a free and open-source network detection and security scanning utility. Many network and system administrators also find it useful for tasks such as network inventory, managing service upgrade schedules, and monitoring server or service availability. Nmap uses raw IP packets in a novel way to determine the hosts available o
4 min read
How To Extract rockyou.txt.gz File in Kali Linux?
The first thing that comes to mind when we think of brute-forcing a login with word lists is rockyou.txt. There is a lot of talk on the internet about rockyou.txt being the most popular file used by hackers and crackers to extract passwords. The interesting thing about this is that ethical hackers can use it to breach the security of any web applic
2 min read
What is ARP Spoofing Attack?
Spoofing is a type of attack in which hackers gain access to the victim's system by gaining the trust of the victim (target user) to spread the malicious code of the malware and steal data such as passwords and PINs stored in the system.In Spoofing, psychologically manipulating the victim is the main target of the hacker. Address Resolution Protoco
3 min read
DNS in Wireshark
DNS or Domain Name System abbreviated as DNS is a system used to resolve domain names, IP addresses, different servers for e.g., FTP servers, game servers, active directories, etc., and keep their records. Invented by Jon Postel and Paul Mockapetris in 1982, DNS has now become one of the most significant players in the modern-day web world. DNS act
4 min read
Direct Sequence Spread Spectrum in Wireless Networks
Direct-sequence spread spectrum in Wireless Networks is a technique that transmits a data signal over a range of frequencies, spreading it uniformly across the allocated spectrum. Direct-sequence spread spectrum is used to ensure that a particular frequency band (and its corresponding range of frequencies) is kept free from interference. This techn
7 min read
TCP Analysis using Wireshark
TCP or Transmission Control Protocol is one of the most important protocols or standards for enabling communication possible amongst devices present over a particular network. It has algorithms that solve complex errors arising in packet communications, i.e. corrupted packets, invalid packets, duplicates, etc. Since it is used with IP(Internet Prot
5 min read
What is Banner Grabbing?
Banner grabbing is a method used by attackers and security teams to obtain information about network computer systems and services running on open ports. A banner is a text displayed by a host that provides details such as the type and version of software running on the system or server. The screen displays the software version number on the networ
4 min read
Types of SQL Injection (SQLi)
SQL Injection is an attack that employs malicious SQL code to manipulate backend databases in order to obtain information that was not intended to be shown, The data may include sensitive corporate data, user lists, or confidential consumer details. This article contains types of SQL Injection with their examples. SQL Injections-LABS (a platform to
6 min read
What is Recursive DNS?
The Domain Name System (DNS) is one of the most important parts of our critical infrastructure that needs protection. The DNS is a system for naming computers, services, or networks on the Internet. There are many basic functions to any given domain name, but the recursive DNS service is an especially significant feature to understand in Ethical ha
5 min read
Top 50 Penetration Testing Interview Questions and Answers
Penetration testing stands for a process where the security of a computer system is tested by trying to gain access to its internal systems. In order to carry out penetration testing, an attacker must first identify which ports are open on the target machine and then use those ports in order to exploit security vulnerabilities. Once these vulnerabi
15+ min read
Frequency-Hopping Spread Spectrum in Wireless Networks
Frequency-hopping spread spectrum is designed for robust operation in noisy environments by transmitting short packets at different frequencies across wide portions of channel bandwidth. The receiver correlates these "near" signals against each other and selects the best signal for demodulation, which typically gives better performance compared wit
3 min read
Port Scanning Techniques By Using Nmap
Nmap is a security auditing tool used in the security field to actively enumerate a target system/network. It is one of the most extensively used tools by network administrators and conversely attackers for reconnaissance (enumeration), the first step in the 5 phases of hacking. Nmap is used to actively probe the target network for active hosts(hos
5 min read
Top 50 Ethical Hacking Interview Questions and Answers
In today’s digital age, cybersecurity has become a top priority for organizations worldwide, creating a high demand for skilled professionals in ethical hacking. Ethical hackers play a vital role in identifying and securing vulnerabilities in systems before malicious hackers can exploit them. If you're preparing for an ethical hacking interview, it
15+ min read
Orthogonal Frequency-Division Multiplexing (OFDM)
Orthogonal frequency-division multiplexing (OFDM) is a digital communication technique initially developed for use in cable television systems. OFDM is similar to the broadcasting technique known as frequency division multiplexing (also known as FDM), which uses a multitude of transmitters and receivers to send information on different frequencies
3 min read
Packet Switched Network (PSN) in Networking
A packet-switched network (PSN) is a kind of computer communications network that sends data in the form of small packets. It allows the sender to send data or network packets to the source and destination node over an internet network channel that is transferred between multiple users and/or applications. A packet-switched is also called a connect
2 min read
What is Burp Suite?
Burp or Burp Suite is a set of tools used for penetration testing of web applications. It is developed by the company named Portswigger, which is also the alias of its founder Dafydd Stuttard. BurpSuite aims to be an all in one set of tools and its capabilities can be enhanced by installing add-ons that are called BApps. It is the most popular tool
5 min read
What is Cross Site Scripting (XSS) ?
Cross Site Scripting (XSS) is a vulnerability in a web application that allows a third party to execute a script in the user's browser on behalf of the web application. Cross-site Scripting is one of the most prevalent vulnerabilities present on the web today. The exploitation of XSS against a user can lead to various consequences such as account c
4 min read
Information Security | Confidentiality
Confidentiality is the protection of information in the system so that an unauthorized person cannot access it. This type of protection is most important in military and government organizations that need to keep plans and capabilities secret from enemies. However, it can also be useful to businesses that need to protect their proprietary trade sec
5 min read
Information System and Security
Prerequisite - Information Security, Threats to Information Security INTRODUCTION: An information system (IS) is a collection of hardware, software, data, and people that work together to collect, process, store, and disseminate information. An IS can be used for a variety of purposes, such as supporting business operations, decision making, and co
5 min read
Article Tags :
three90RightbarBannerImg