Lecture 6 - Web and Browser Security
Lecture 6 - Web and Browser Security
Security
Computer Security | Lecture Six
Lecture Outline
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Introduction
▪ A lot can go wrong on the Web Executable Content (if any),
through Browser-server ▪ The browser can be redirected to
Interactions other sites.
▪ As web resources are transferred ▪ Much of this occurs without User
and displayed to users. Involvement or Understanding
▪ When a Browser visits a website, ▪ Pages may recursively pull in
the browser is sent a page (HTML content from multiple sites
document). ▪ Including scripts (active content)
▪ The Browser renders the document ▪ e.g., in support of the Internet’s
by first assembling the specified underlying advertising model
pieces and executing embedded
Introduction
5
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Web Review:
Domains, URLs, HTML, Scripts
7
Web Review:
Domains, URLs, HTML, Scripts
▪ Uniform Resource Locators ▪ i.e., a computing device that has
a corresponding IP address;
(URLs)
▪ User-friendly domain names can
▪ Specifies the Source Locations
be used (vs. IP addresses)
of files and web pages.
based on DNS utilities that
▪ As shown in the Address Bar translate (resolve) an FQDN to
▪ A URL is the most-used type of an IP address
uniform resource identifier (URI) ▪ FQDN: Fully Qualified Domain
▪ Hostname refers to an Name is the complete domain
addressable machine name for a specific computer,
or host, on the internet
8
9
Web Review:
Domains, URLs, HTML, Scripts
▪ Hypertext Markup Language (HTML) is a system for annotating
content in text-based documents, e.g., web pages.
▪ Uses Markup Tags to format for display on Web Browsers
▪ Tags come in pairs to identify structures such as Paragraphs and
Headings.
▪ Text appearing between Tags is the actual content to be formatted.
▪ A hyperlink specifies a URL identifying a web page from a
separate location
▪ An anchor tag associates such a URL with a string to be displayed
<a href="url">textstring-for-display</a>
10
Web Review:
Domains, URLs, HTML, Scripts
14
15
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
HTTP and Web Forms
▪ HTML documents may include ▪ Entered data is concatenated into a
Web Forms String as a sequence of
“fieldname=value” pairs
▪ Forms solicits user input into
specified fields ▪ If the POST method is used
▪ String is Put into an HTTP request
▪ “Submit” button signals that data
body
entry is complete
▪ If the GET method is used
▪ Specifies a URL to which an HTTP
▪ Recall GET has no body
request will be sent as the action
resulting from the button press ▪ String is appended as query data at
the end of the request-URI in the
▪ On clicking the Button request-line
17
HTTP | Referer Header
▪ The Referer Header is designed to parameters),
hold the URL of the page from ▪ some Browsers remove the Referer
which the request was made data if it would reveal, e.g., a local
filename.
▪ Informs the host of the newly
requested resource the originating ▪ It’s safer to submit Forms using
URL, and potentially ending up in the POST
logs of both servers. ▪ GET-method append user-entered
▪ Some Browsers allow users to data into query field arguments
disable use of this header ▪ Since, Referer Header propagate
▪ For privacy reasons (e.g., browsing sensitive data
history, leaking URL query
18
HTTP Proxies
▪ An HTTP proxy or proxy server is modifications or translations
an intermediary service between a needed for interoperability,
Client and an Endpoint Server ▪ keeps audit logs,
▪ Negotiates access to endpoint ▪ Inspecting content and performing
server resources and relays other firewall functions.
responses ▪ Provides Caching efficiency
▪ Acts as a server to the client, and as ▪ Identical content requested multiple
a client to the endpoint server. times, including by different clients,
can be retrieved from a locally
▪ HTTP Proxies stored copy
▪ Handle any header/content
19
20
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Browser (URL) Redirection
22
Browser (URL) Redirection
23
Browser (URL) Redirection
▪ JavaScript Redirect (within ▪ Refresh meta tag (within HTML)
HTML) ▪ The current page is replaced on
▪ The location property of the window executing:
object (DOM) can be set by <meta http-equiv="refresh"
JavaScript content="N; URL=new-url">
[Link]="url" or ▪ This redirects to new-url after N
[Link]="url" seconds (immediately if N = 0).
▪ Assigning a new value in this way ▪ If URL= is omitted, the current
allows a different document to be document is refreshed.
displayed. ▪ This tag works even if JavaScript is
disabled
24
Browser (URL) Redirection
▪ Refresh header (in HTTP ▪ HTTP redirection (in HTTP
response) response, status code 3xx)
▪ On encountering the HTTP ▪ Here, an HTTP header: specifies
header: the redirect target.
Refresh: N; url=new-url ▪ A web server may arrange to
▪ The browser will, after N create such headers by various
seconds, load the document means
from new-url into the current ▪ By a server file with line entries
window that specify:
▪ Immediately if N = 0 ▪ (requested-URI, redirect-status-
code-3xx, URI-to-redirect-to).
25
Browser (URL) Redirection
26
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Transport Layer Security (TLS) and HTTPS
HTTP over TLS
▪ HTTPS (Secure), is the main A. Key Exchange (authenticated
key establishment; finalizes
protocol that secures web all crypto parameters)
traffic B. Server Parameters (all other
options and parameters are
▪ Client sets up a TLS channel to finalized by the server)
a server over an TCP connection C. Integrity and Authentication
to transmits HTTP data. (of server to client, and
▪ A TLS client-server Channel optionally client to server)
involves 2 Stages 2. Record Layer: This protects
application data, using
1. Handshake Layer (parameter
parameters as negotiated.
set-up). The handshake
involves 3 functional parts: ▪ TLS succeeds the SSL
28
Transport Layer Security (TLS) and HTTPS
HTTP over TLS
29
30
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
HTTP Cookies and Session IDs
▪ HTTP itself is a Stateless protocol ▪ Server passes size-limited data
▪ State is not retained across strings to the Browser
successive HTTP requests ▪ Browser returns the Strings on later
requests to the same Server
▪ Not consistent with how websites
▪ These are Short-lived Session
functions - hyperlinked Cookies stored in browser memory;
▪ Most Successive page loads are ▪ Server-set attributes can extend
typically related Cookie lifetime into Persistent
▪ State retention enables Cookies
Convenience and Functionality ▪ Subdomains, as logically distinct
▪ HTTP cookies provides the from higher-level domains, have
experience of Browsing Sessions their own cookies.
32
HTTP Cookies and Session IDs
33
HTTP Cookies and Session IDs
▪ Server may specify a session Browser has not Disabled
persistent cookies
expiration time shorter than
the cookie lifetime. ▪ Such Cookies are an attractive
targets suppose there are
▪ After expiration, re- authenticated session benefits
authentication will be needed
▪ Such as link to an account with
▪ Authentication Cookie may a permanently stored credit
extend the authenticated card number or other sensitive
session beyond the lifetime of resources.
the browsing window, to days or ▪ Cookie Theft thus allows HTTP
weeks later. session hijacking
▪ If the cookie is Persistent and
34
Cookie Theft | Client-side Security Risks
▪ Authentication cookies may be ▪ The Secure cookie attribute
mandates HTTPS or similar
stolen by means including protection.
▪ Malicious JavaScript in HTML ▪ Non-script client-side malware
documents, e.g., sending cookies to
▪ Such malware defeats most client-
a malicious site side defenses
▪ Setting the HttpOnly cookie
▪ Physical or other unauthorized
attribute stops script access to
cookies.
access
▪ to the Filesystem or Memory of the
▪ Untrustworthy HTTP Proxies,
client device on which Cookies are
Middle-persons and Middleboxes stored
▪ If cookies are sent over HTTP
35
Cookie DOM API
36
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Same-Origin Policy (DOM SOP)
38
Motivation for SOP
▪ If a browser loads pages from application security model
distinct domains host1 and host2, ▪ The Browser permits scripts in a
without rules to prevent mixing of Page to access data in a second
their content page, only if both web pages have
the same Origin
▪ The JS from host1 in one Page
▪ Origin: a combination of URI
might access or alter data
scheme, host name, and Port
associated with host2 in another. Number (aka Origin Triplet)
▪ Problematic: if host1 is malicious
▪ SOP protects against reusing
and host2 is a banking site.
Authenticated Sessions across
▪ SOP is an Important web origins
39
Same-Origin Policy | Rules
▪ Some Rules are thus ▪ A base HTML document is
needed. assigned an origin, derived
from the URI that retrieved it;
▪ Overly strict host isolation
policies might rule out ▪ Scripts and images are
desirable interaction between assigned the origins of the
cooperating subdomains HTML documents that cause
them to be loaded
▪ E.g., catalog and purchasing
divisions of an online store ▪ Scripts may access content
whose assigned Origin
▪ The Basic SOP Rules matches their own.
40
41
Can you Explain?
42
43
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Cross-Site Request Forgery Attacks
45
46
47
48
Cross-Site Request Forgery Attacks
49
Mitigating CSRF Attacks
50
Mitigating CSRF Attacks | Best Practices
51
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Cross-site Scripting (XSS) Attacks
53
Types of XSS
▪ Reflected XSS:
▪ Malicious script comes from the current HTTP request
▪ Stored XSS
▪ Persistent or Second-order XSS
▪ Malicious script comes from the website's database
▪ DOM-based XSS
▪ Vulnerability exists in client-side code rather than server-side code
54
Reflected XSS
▪ It arises when an application receives data in an HTTP request
and includes that data within the immediate response in an
unsafe way
▪ Simplest variety of XSS
▪ Example: Suppose a user is redirected to, or lands on, an
attacker-controlled site [Link], and legitimate site
[Link] responds to common file-not-found errors with
an error page generated by a parameterized script
File-not-found: filepath-requested
55
56
Example | Stored XSS
▪ General Form
harmless-text <script> arbitrary-malicious-JavaScript </script>
57
58
XSS | Potential Impacts
59
Mitigating XSS Attacks
▪ Input sanitization is the process of removing potentially
malicious elements from data input, including
▪ Input filtering by use of allowlists, denylists
▪ Removing tags and event attributes such as <script>, <embed>,
<object>, onmouseover; and output escaping.
▪ Server-side Filtering may stop simple XSS attacks but leads to
filter evasion tactics.
▪ To defuse malicious injection of HTML markup tags, filters replace <
and > by < and >
▪ Therefore, the Browser parsers process <script> as regular text
60
61
Mitigating XSS | Evading Filtering
▪ To evade filters seeking the string “<script>”, an injected code
may use alternate encodings for the functionally equivalent string
“<script>”
▪ First 12 characters encode ASCII “<s”
▪ To address such evasive encodings
▪ A Canonicalization step can be used to map input (including URIs) to a
common character encoding.
▪ Another standard evasion injects code to dynamically construct
that string, e.g., by JavaScript string concatenation.
62
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
SQL Injection Attacks
64
SQL Injection Attacks
65
SQL Injection Attacks
▪ A common case involves scripts using String
Concatenation to embed user-input data into dynamically
constructed SQL query strings.
▪ The resulting strings, sent to an SQL server are processed based on
specific syntax and structure
66
Example | SQL Injection
▪ Suppose a user logging into a web site is presented a
browser form and enters a username and password.
▪ An HTTP request conveys the values to a webpage, where a server-
side script assigns them to string variables (un, pw).
▪ The values are built into an SQL query string, to be sent to a back-
end SQL database for verification.
▪ The script constructs a string variable for the SQL query as follows:
query = "SELECT * FROM pswdtab WHERE username='" + un +
"’ AND password='" + pw + "’"
67
Example | SQL Injection
▪ Let’s see what query string results if for un, the user types in
“root’ --” | Query becomes:
SELECT * FROM pswdtab WHERE username='root' -- AND
password='" + pw + "'"
▪ Since “- -” denotes a line-ending comment, what follows it is ignored.
▪ This eliminates the condition requiring a password match, and the
record for the root account is returned
▪ The app server assumes a successful check, and grants user
access as root
68
Example | SQL Injection
'OR 1=1 -–
▪ The Query becomes
SELECT * FROM pswdtab WHERE username='' OR 1=1 –-
▪ Depending on the database, this may return every record in the table!
69
Mitigating SQL Injection Attacks
▪ Escaping unexpected keywords
▪ Adjust received input to remove a ▪ e.g drop, shutdown, insert
subset of clearly identified problems ▪ Drawback: Always incomplete, and
▪ Drawback: Prone to errors; requiring update as each new attack
becomes known
▪ Output escaping of special
characters is a good start ▪ Positive Validations
▪ Ad hoc solutions are subject to ▪ Allow only known-good input, i.e.,
endless move-countermove games use Allowlists
with attackers
▪ Drawback: Requires precise (and
▪ Input filtering by Denylists correct) specification of allowed
▪ Reject known-bad input or inputs, or predefined query formats
70
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Phishing Attack
▪ Phishing is the act of impersonating a legitimate website in order
to obtain information without authorization
▪ Info: Passwords, Credit card numbers, etc.
▪ Phishing attack is carried out by
▪ A link (e.g., in an email, messaging service, web search result, or on
another web site)
▪ Browser redirection
▪ The site may connect to and mirror info from the legitimate site to
convince users
72
Phishing Attack
74
Mitigating Phishing Attacks
▪ Remove the sources of links to sites.
phishing sites ▪ There exist a shared lists of
▪ By Spam Filtering of phishing malicious websites
emails by service providers; ▪ These techniques have
▪ Large email providers have substantially reduced Phishing
become proficient at this. ▪ But still do not provide full and
▪ Filtering of phishing sites by immediate protection;
Browsers ▪ Transient Phishing sites that
▪ Users are warned, or prevented exist for just a few hours or a
from following, links to flagged day, remain problematic.
75
Mitigating Phishing Attacks
77
Mitigating Phishing Attacks
Security Indicators
78
79
Mitigating Phishing Attacks
Certificate Grades
▪ Certificate Authorities classify ▪ Organization Validation (OV)
digital certificates based on 3 ▪ Extra information on the
Organization associated with a
validation levels:
certificate Subject
▪ Domain Validation (DV)
▪ Extended validation (EV)
▪ Entirely automated (server-side)
▪ Sparsely used; Undergo Greater
and free from some providers
Scrutiny before issuance
▪ Acquisition is easy for Phishing
▪ Provide little benefit to end-
and other malicious sites
users, due to the inability of
▪ Has https but does not signal a browsers to convey to users
legitimate site differences from OV
80
Lecture Outline | Progress
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security
Usable Security
82
83
📝 To Study
84
Lecture Outline | End
▪ Introduction HTTPS
▪ Web Review: Domains, URLs, ▪ HTTP Cookies and Session IDs
HTML, Scripts ▪ Same-Origin Policy
▪ Hypertext Transfer Protocol ▪ Web Security Attacks
▪ HTTP and Web Forms ▪ Cross-Site Request Forgery Attacks
▪ HTTP Referer Header ▪ Cross-site Scripting Attacks
▪ HTTP Proxies ▪ SQL Injection Attacks
▪ Browser (URL) Redirection ▪ Phishing Attacks
▪ Transport Layer Security and ▪ Usable Security