window.pipedriveLeadboosterConfig = { base: 'leadbooster-chat.pipedrive.com', companyId: 11580370, playbookUuid: '22236db1-6d50-40c4-b48f-8b11262155be', version: 2, } ;(function () { var w = window if (w.LeadBooster) { console.warn('LeadBooster already exists') } else { w.LeadBooster = { q: [], on: function (n, h) { this.q.push({ t: 'o', n: n, h: h }) }, trigger: function (n) { this.q.push({ t: 't', n: n }) }, } } })() Web app security - XSS vulnerability - The Codest
The Codest
  • About us
  • Services
    • Software Development
      • Frontend Development
      • Backend Development
    • Staff Augmentation
      • Frontend Developers
      • Backend Developers
      • Data Engineers
      • Cloud Engineers
      • QA Engineers
      • Other
    • It Advisory
      • Audit & Consulting
  • Industries
    • Fintech & Banking
    • E-commerce
    • Adtech
    • Healthtech
    • Manufacturing
    • Logistics
    • Automotive
    • IOT
  • Value for
    • CEO
    • CTO
    • Delivery Manager
  • Our team
  • Case Studies
  • Know How
    • Blog
    • Meetups
    • Webinars
    • Resources
Careers Get in touch
  • About us
  • Services
    • Software Development
      • Frontend Development
      • Backend Development
    • Staff Augmentation
      • Frontend Developers
      • Backend Developers
      • Data Engineers
      • Cloud Engineers
      • QA Engineers
      • Other
    • It Advisory
      • Audit & Consulting
  • Value for
    • CEO
    • CTO
    • Delivery Manager
  • Our team
  • Case Studies
  • Know How
    • Blog
    • Meetups
    • Webinars
    • Resources
Careers Get in touch
Back arrow GO BACK
2021-04-16
Software Development

Web app security – XSS vulnerability

Lukasz Kolko

XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. The main effects of this vulnerability are the possibility of execution of any actions in the context of the logged-in user, and reading any data in the context of the logged-in user.

Attack scenario

  1. The attacker locates the XSS vulnerability on a website used by the victim, e.g., a bank’s website
  2. The victim is currently logged on to this page
  3. The attacker sends the victim a crafted URL
  4. The victim clicks on the URL
  5. On the victim’s bank website, JavaScript code starts executing to intercept the user’s data or execute a transfer on his behalf to the attacker’s account

It is worth noting that operations performed on behalf of the victim may be invisible to the victim, as they may take place in the background using the bank’s API, or the attacker may perform them later with the data needed for authentication, tokens, cookies, etc.

XSS types

1. Reflected XSS

This is one where HTML/JavaScript code contained in any parameter (e.g. GET, POST or cookie) is displayed in response.

A page with a text input to search for something that puts the parameter ?search=foo in the URL ending when querying the API. After entering any phrase, if it is not found, a return message is placed in HTML ex.

<div>No result found for <b>foo</b></div>

We can try to put in the URL ?search=<script>alert('XSS')</script>..

2.DOM XSS

This is when its execution is enabled by the use of dangerous functions in JavaScript, such as `eval` or `innerHtml`. The “Live example” below shows a DOM XSS attack based on the `innerHtml` function.

3. Stored XSS

This is one where the malicious code gets written on the server side. For example, we may send a comment with malicious code to a blog post that is uploaded to the server. Its task is, for example, to wait for the administrator’s moderation and then to steal his session data, etc.

Injection methods

1. In the tag content

`onerror=alert('XSS')`into

<img src onerror=alert('XSS') />

2. In the content of the attribute

`" onmouseover=alert('XSS')` into

<div class="" onmouseover=alert('XSS')"></div>

  1. In the content of the attribute without the quotes

x onclick=alert('XSS')into

<div class=x onclick=alert('XSS')></div>

  1. In the hrefef attribute

javascript:alert('XSS') into

<a href="javascript:alert('XSS')"></a>

  1. In the string inside JavaScript code

";alert('XSS')// into

<script>let username="";alert('XSS')//";</script>
  1. In the attribute with the JavaScript event

&#39;);alert('XSS')// where &#39; is a single quote, into

<div onclick="change('&#39;);alert('XSS')//')">John</div>

  1. In the href attribute inside the JavaScript protocol

%27);alert(1)// where %27 is a single quote, into

<a href="javascript:change('%27);alert(1)//')">click</a>


Live example

Defense methods

  1. Data encoding using built-in functions found in many programming languages.
  2. Using template systems with automatic encoding. Most of the popular frameworks that use such systems protect us from XSS injection (Django, Templates, Vue, React etc.).
  3. Do not use functions like eval or Function with untrusted user data.
  4. Do not use functions and properties that assign HTML code directly to the DOM tree elements, e.g., innerHTML, outerHTML, insertAdjacentHTML, ocument.write. Instead, you can use functions that assign text directly to these elements, such as textContent or innerText.
  5. Be careful when you redirect the user to a URL that is under his control. Risk of injection location = 'javascript('XSS')'.
  6. Filter HTML using libraries such as DOMPurify.
  7. Be careful about uploading .html or .svg files. You can create a separate domain from which the uploaded files will be served.
  8. Use the Content-Security-Policy mechanism.
  9. Take a look at the anti-XSS filters built into most popular browsers.

    If you find this article interesting, follow Lukasz on Github: https://github.com/twistezo

Read more:

Data fetching strategies in NextJS

Rails API & CORS. A dash of consciousness

Why you should (probably) use Typescript?

Related articles

Software Development

Build Future-Proof Web Apps: Insights from The Codest’s Expert Team

Discover how The Codest excels in creating scalable, interactive web applications with cutting-edge technologies, delivering seamless user experiences across all platforms. Learn how our expertise drives digital transformation and business...

THECODEST
Software Development

Top 10 Latvia-Based Software Development Companies

Learn about Latvia's top software development companies and their innovative solutions in our latest article. Discover how these tech leaders can help elevate your business.

thecodest
Enterprise & Scaleups Solutions

Java Software Development Essentials: A Guide to Outsourcing Successfully

Explore this essential guide on successfully outsourcing Java software development to enhance efficiency, access expertise, and drive project success with The Codest.

thecodest
Software Development

The Ultimate Guide to Outsourcing in Poland

The surge in outsourcing in Poland is driven by economic, educational, and technological advancements, fostering IT growth and a business-friendly climate.

TheCodest
Enterprise & Scaleups Solutions

The Complete Guide to IT Audit Tools and Techniques

IT audits ensure secure, efficient, and compliant systems. Learn more about their importance by reading the full article.

The Codest
Jakub Jakubowicz CTO & Co-Founder

Subscribe to our knowledge base and stay up to date on the expertise from the IT sector.

    About us

    The Codest – International software development company with tech hubs in Poland.

    United Kingdom - Headquarters

    • Office 303B, 182-184 High Street North E6 2JA
      London, England

    Poland - Local Tech Hubs

    • Fabryczna Office Park, Aleja
      Pokoju 18, 31-564 Kraków
    • Brain Embassy, Konstruktorska
      11, 02-673 Warsaw, Poland

      The Codest

    • Home
    • About us
    • Services
    • Case Studies
    • Know How
    • Careers
    • Dictionary

      Services

    • It Advisory
    • Software Development
    • Backend Development
    • Frontend Development
    • Staff Augmentation
    • Backend Developers
    • Cloud Engineers
    • Data Engineers
    • Other
    • QA Engineers

      Resources

    • Facts and Myths about Cooperating with External Software Development Partner
    • From the USA to Europe: Why do American startups decide to relocate to Europe
    • Tech Offshore Development Hubs Comparison: Tech Offshore Europe (Poland), ASEAN (Philippines), Eurasia (Turkey)
    • What are the top CTOs and CIOs Challenges?
    • The Codest
    • The Codest
    • The Codest
    • Privacy policy
    • Website terms of use

    Copyright © 2025 by The Codest. All rights reserved.

    en_USEnglish
    de_DEGerman sv_SESwedish da_DKDanish nb_NONorwegian fiFinnish fr_FRFrench pl_PLPolish arArabic it_ITItalian jaJapanese ko_KRKorean es_ESSpanish nl_NLDutch etEstonian elGreek en_USEnglish