Cross Site Scripting attack review

0.0(0)
Studied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/54

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:37 PM on 3/23/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

55 Terms

1
New cards

Explain the full XSS attack chain (attacker —> website —> victim). Include why the browser trusts the malicious code.

The attackers injects malicious JavaScript into a vulnerable website. The website stores or reflects that code and sends it to the victim’s browser. Since the code comes from a trusted website, the browser executes it with full privileges (cookies, DOM, session).

2
New cards

Why can injected JavaScript access cookies and session data?

Because the browser the same-origin policy, and the malicious scripts appears to come from the legitimate websites, so it inherits that site’s permissions.

3
New cards

What is the root cause of XSS?
A. Weak authentication
B. Unsanitized user input
C. Open ports
D. Poor encryption

B

4
New cards

List 2 types of damage XSS can cause

Steal cookies/session data
Modifying webpage content (defacing)
Sending requests as the user

5
New cards

Difference between reflected and stored XSS

Reflected: input is immediately returned in response (not stored)
Stored: input is saved and later served to victims

6
New cards

Which type is used in Porject 4? Reflected or Stored?

Stored XSS

7
New cards

Why is stored Xss more dangerous?

it persists on the server and affects every user who visits the page, making it scalable and harder to detect.

8
New cards

What is an attack surface?

any input field or location where user data is accepted and rendered without proper sanitization

9
New cards

Name 3 attack surfaces where XSS payloads can be injected

profile description fields, search bars, comment sections

10
New cards

why might your script appear as text instead of executing?

Because the application encoded or sanitized the input, preventing execution.

11
New cards

Why do we capture HTTP requests?

To understand how the website performs actions so we can replicate them programmatically using JavaScript

12
New cards

What are _elgg_token and _elgg_ts?

Security tokens used to prevent CSRF attacks; they must be included in valid requests.

13
New cards

Why can injected JavaScript access these tokens (referring to _elgg_token and _elgg_ts)?

Because the script runs in the same context as the webpage and can access its JavaScript

14
New cards

Why is dynamic token extraction required?

tokens change per session/request, so hardcoding them would fail.

15
New cards

Why does the server accept the malicious request?

Because it includes valid tokens and cookies, making it appear legitmate.

16
New cards

what actually performs the attack?
A. HTML
B. AJAX request
C. URL alone
D. cookie

B

17
New cards

Why avoid modifying attacker’s own profile?

it would overwrite the malicious script, stopping propagation

18
New cards

how does the attack affect multiple users?

Each visitor triggers the script, executing actions on their own account.

19
New cards

what makes an XSS worm?

it replicates itself by injecting its code into other users’ profiles.

20
New cards

why use encodeURIComponent()?

To safely include JavaScript in HTTP requests without breaking formatting

21
New cards

List 3 debugging steps if your attack fails.

check browser console for errors
Check network tab for request
verify tokens and payload execution

22
New cards

Why do you check if your request was sent?

Browser DexTools > Network tab

23
New cards

Explain the full attack chain of XSS in your own words:
Who are the 3 parties involved?
Why trusts whom incorrectly?

3 parties:
Attack (injects malicious code)
Target Website (stores/ reflect the code)
Victim (loads the page)
The victim’s browser trusts the website, so it also trusts the malicious code coming from that website. The browser cannot distinguish attacker code from legitimate code.

24
New cards

Why does malicious JavaScript gain access to: cookies, DOM, Session data?

Cookies: Same-origin policy allows scripts from the site to access cookies
DOM: Scripts can fully manipulate page structure
Session data: Stored in JavaScript variables accessible in the page

Because the script runs as if it belongs to the website

25
New cards

Given this URL: example.com/search?q=<script>alert(1)</script>
What type of XSS is this?

Reflected XSS because input is in URL and reflected immediately

26
New cards

Why is the “About Me” / Description field ideal for stored XSS?

Stored in database

Displayed to other users

Automatically executed when viewed

perfect for persistent attacks

27
New cards

Why does the attacker need to capture a request using tools like LineHTTPHeader / DevTools?

Understand request structure

Extract parameters

Replay the request programmatically

You are reverse-engineering the website

28
New cards

What would happen if you hardcoded tokens instead of dynamically retrieving them?

Attack will fail

Tokens expire or change per session

29
New cards

Why do we use elgg.security.token._elgg_token instead of manually typing the token?

  • Tokens are dynamic

  • Must match the current user/session

30
New cards

Explain what this line does: Ajax.open(“GET”, sendurl, true);

Opens a request

GET method

Asynchronous true

31
New cards

What is the purpose of: window.onload = function() {…}

Ensures: Script runs after page loads

All variables are available

32
New cards

what happens if your script runs before the page loads?

Variables may be undefined

Script may fail or do nothing

33
New cards

What is the goal of the add-friend attack?

Add attacker as a friend without consent

34
New cards

What makes the request valid from the server’s perspective?

Valid token

Valid session cookie

Correct request format

35
New cards

What part of the attack is actually doing the damage?
A. HTML
B. JavaScript AJAX request
C. URL
D. Cookie alone

B

36
New cards

Why do we include: if (elgg.session.user.guid ≠ 47)

To avoid:

  • Overwriting attacker’s own profile

  • Breaking the attack

37
New cards

What would happen if we didn’t include that condition, context:
if (elgg.session.user.guid ≠ 47)

  • Infinite overwrite

  • Malicious code removed

38
New cards

How does the attack scale to multiple victims?

Each visitor: executes script, modifies their own profile

Attack spreads naturally

39
New cards

What would happen if we didn’t encode the payload?

request breaks
script malformed
attack fails

40
New cards

Explain the DOM approach for copying code.

Access script via DOM

Extract its own code

Reinsert into another profile

41
New cards

Why do we use:
document.getElementById(“worm”).innerHTML;

gets the script’s content from the page

42
New cards

What problem does this ( document.getElementById("worm").innerHTML; ) solve in the attack?

allows self-copying for automatic propagation

43
New cards

Difference between DOM and Link(src) approach?

DOM approach copies code from page while the link approach loads code from external file.

link = cleaner, shorter payload

44
New cards

Your script isn’t running. List 3 things you would check

Console errors
Network requests
Token correctness

45
New cards

Where in browser DevTools would you look to: See if your request was sent?

Network tab

46
New cards

Where would you check JavaScript errors?

Console tab

47
New cards

If your payload executes but doesn’t modify anything, what might be wrong?

Wrong parameters, Missing tokens, incorrect request method (get vs post), permissions/access level is wrong

48
New cards

Why is filtering input hard?

Many ways to inject JS, not just script tags

49
New cards

What does encoding do differently from filtering?

Filtering removes code while encoding makes code harmless (displayed, not executed)

50
New cards

What is the purpose of Content Security Policy (CSP)?

restricts where scripts can come from

51
New cards

Why does CSP block inline scripts?

inline scripts mix code and data and can be vulnerable

52
New cards

What is a nonce in CSP?

Nonce is a unique token that allows only approved inline scripts

53
New cards

Can you describe how to: Inject code, Capture request, Recreate request in JavaScript, Execute automatically?

Inject script into input field

Capture valid request

Extract parameters (tokens, cookies)

Recreate request using AJAX

Execute automatically via XSS

54
New cards

if given a new website (not Elgg), could you: Find attack surfaces? Identify tokens? Replicate a request?

Yes, if you can:

identify inputs

Inspect requests

Extract tokens

Rebuild requests

55
New cards

Explain the full attack in plain English like you’re teaching someone else.

An attacker puts malicious JavaScript into a website field.
When another user visits that page, their browser runs the script because it trusts the site.
The script secretly sends requests (like adding friends or editing profiles) using the victim’s account, without them knowing.

Explore top flashcards

flashcards
Skeletal system II / Joints
175
Updated 410d ago
0.0(0)
flashcards
Business Quiz #1
34
Updated 1104d ago
0.0(0)
flashcards
100 questions.
100
Updated 296d ago
0.0(0)
flashcards
Chapter 8
41
Updated 1029d ago
0.0(0)
flashcards
Hamlet (Acts III-V) 76 words
76
Updated 1236d ago
0.0(0)
flashcards
Year 3 EMIs
309
Updated 383d ago
0.0(0)
flashcards
Skeletal system II / Joints
175
Updated 410d ago
0.0(0)
flashcards
Business Quiz #1
34
Updated 1104d ago
0.0(0)
flashcards
100 questions.
100
Updated 296d ago
0.0(0)
flashcards
Chapter 8
41
Updated 1029d ago
0.0(0)
flashcards
Hamlet (Acts III-V) 76 words
76
Updated 1236d ago
0.0(0)
flashcards
Year 3 EMIs
309
Updated 383d ago
0.0(0)