Explaining XSS, CSRF And Session Hijacking | Website Vulnerability
loader image
Mobile App Development Tech News Web Development

Explaining XSS, CSRF And Session Hijacking


XSS, CSRF And Session Hijacking                    

XSS, CSRF and Session Hijacking are the web application vulnerabilities used to hack the user data by injecting malicious code or link or by using any other possible way. So let’s see the possibilities of hacking using each concept & will eventually reveal its security breaches one by one.

Cross Site Scripting (XSS) Attack:

An attacker injects the malicious code into the victim’s web application to hack the sensitive data like cookies, browser storage. As a result, they can hack the sensitive data when they found any loophole where their query reflects as HTML in the web application instead of HTML entities.

NOTE: Hackers commonly use the JAVASCRIPT language for XSS but it is possible to inject any language that will execute in browsers and injecting server-side language is not possible in XSS.

Here’s the link for you to experiment with XSS attacks:

Types of XSS


  1. Persistent (Stored) XSS
  2. Non Persistent (Reflected) XSS


Persistent (Stored) XSS :

Persistent XSS will have strong affluence & will be permanently available until the victim (targetted user) try to secure the web application with the techniques like Escape strings, HTML Encoding etc. Most of the cases, this might happen through the commonplace like “COMMENTS list, POSTS LIST of the web application.
NOTE: Comparatively, this attack will remain very critical than Non-Persistent XSS so even there is a chance to crash the website permanently.

Example For Persistent XSS :



In the above code “‘<blockquote>’ + posts[i].message + ‘</blockquote>'” you can see that the developer forgot to escape the post message. Also, there is no encoding done to escape the string. Thereby the attacker can execute the code in the post list.

So, this is how the attacker will try to hijack,,

i.e. attacker post like that “<h1><b><a href=””><font color=”#f00″>CLICK TO SEE YOUR GIFT</font></a></u></b></h1>” it will execute as the below image.


NOTE:  What I have shown here is a basic way of hacking but attackers can inject more dangerous code than this.

Non – Persistent (Reflected) XSS :

Non-persistent XSS is another way of hacking where the attacker will try to add the malicious code through the vulnerable link once they found any loophole. Parallely, they will send this link to a victim mail through any communication medium. This attack is not permanent but by chance, if the victim clicks the link then an attacker can easily able to hack the sensitive data. Usually, this attack can happen through “SEARCH, URL, etc”.



Example For Non – Persistent XSS



As you can see in the above code “<b>” + query + “</b>” that the developer forgot to escape the query so this type of cases can be easily hijacked by an attacker where they can attack by sending a link like below,<h1><b><a+href=””><font+color=”#f00″>CLICK+TO+SEE+YOUR+GIFT</font></a></u></b></h1>

Unfortunately, when the victim clicks the link then the code will execute & fetch all the sensitive data.

Cross-site request forgery (CSRF or XSRF):

Cross-site request forgery involves in the concept of finding a loophole in API Requests, where the intruder can send the desired data with victim id in order to target the API.

NOTE: This Type of vulnerability is hard to prevent and dangerous.
This can happen when any  ‘UPDATING AUTHENTICATED DATA OR TRANSMITTING DATA FROM AUTHENTICATED USER like change password, sending money, etc.


In the above API request, you can note that the user is trying to change the password which contains only userId, new password, confirm password. So it’s possible to change the password once we get the userId or can change the password by trying random ids.

Best To Read: 12 Extremely Useful JavaScript Hacks To Optimize Performance & Save Time


Session Hijacking:

Session hijacking is another web application vulnerability which involves in exploitation of web session, before getting into a deep analysis about Session Hijacking, we must know what is session first.

What is Session?
A session is the type of state to keep the user in an authenticated state by using browser storage like cookies, localStorage, etc.

What is Session Hijacking?
When any intruders try to hack the session ids or user data from the victim system. Once the succeeded hijacking your details, they will set the session data in the browser with the same website. Finally, when they try to refresh the browser then the browser will be automatically logged into a website.

Similarly, there are more ways to hack the user session data like XSS, Sniffing  Network packets, etc.

Example using Non-Persistent XSS:<h1><b><a+href=””><font+color=”#f00″>CLICK+TO+SEE+YOUR+GIFT</font></a></u></b></h1>

See the above example the hacker send this link to victim mail or any communication way. After the victim clicked the session data will send to hackers server. Thereby the hacker can easily login to their system.
XSS, CSRF, Session hijacking are dangerous vulnerabilities that need our attention, if you see any of the symptoms or unusual behavior in your web application then it should be fixed right before the production release. It’s not always necessary to learn building a secured application sometimes we must learn to find the loopholes of the application too which might lead to t0 security breaches. How to hack the web app. because it will help to know about to fix the loopholes.

Tools To Practise XSS, CSRF

Kali Linux ( ),
buggy web app ( )

Reference To Prevent From XSS, CSRF:

XSS Prevent:
( )

CSRF Prevent:
( )

Session Hijacking Prevent:
Attackers can use “Network Sniffing” to hijack your website data so to prevent from hijacking your session, you can use HTTPS  in your website.

Like What You're Reading ?

The following two tabs change content below.
Nagaraj Ravi

Nagaraj Ravi

A zealous full stack web developer with 3 years of professional experience. Hybrid application development and in developing Open-source projects are the best of my list. Out of passion ethical hacking is one of my hobbies. Yet, I am good at analyzing Web Security. And I teach machines with my expertise in Robotics and Machine learning.

Leave a Reply

Your email address will not be published. Required fields are marked *