Code Injection Vulnerabilities in Web Applications
Code Injection Vulnerabilities in Web Applications
net/publication/220622661
CITATIONS READS
26 7,814
1 author:
Martin Johns
SAP Research
77 PUBLICATIONS 1,037 CITATIONS
SEE PROFILE
All content following this page was uploaded by Martin Johns on 24 December 2014.
Eingereicht an der Fakultät für Informatik und Mathematik der Universität Passau
3
4
Acknowledgments
This thesis would not exist without the help, advice, inspiration, dialogue, and encour-
agement of many, many people. I would like to thank (in no particular order): Joachim
Posegga, Dieter Gollmann, Daniel Schreckling, Jan Meier, Jan Seedorf, Christopher
Alm, Henrich C. Pöhls, Bastian Braun, Hannah Lee, Rosemaria Giesecke, Tom Schroer,
Thilo Zieschang, Stefan Fünfrocken, Boris Hemkemeier, Kai Buchholz-Stepputiz, Sashar
Paulus, Moritz Jodeit, Justus Winter, Christian Beyerlein, Björn Engelmann, Jeremias
Reith, Christian Weitendorf, Roland Illig, Mieke Hildenbrandt, Christopher Schward,
Daniel Kreischer, the CInsects & SecToolers, Siglinde Böck, Erika Langer, Marita Ward,
Melanie Volkamer, Michael Schrank, Andreas Günther, Ingo Desombre, Tim Scharfen-
berg, Andre Lürssen, Andrei Sabelfeld, Frank Piessens, Yves Younan, Ulfar Erlingsson,
Helen Wang, Erik Meijer, fukami, Alex Kouzemtchenko, Dragos Ruiu, Wolfgang Koeppl,
Martin Wimmer, Hoko Onshi,
5
6
Contents
Introduction 12
Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Thesis overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Thesis outline and contributions . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1. Technical Background 23
1.1. The web application paradigm . . . . . . . . . . . . . . . . . . . . . . . . 23
1.1.1. The web browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.1.2. Uniform Resource Locators . . . . . . . . . . . . . . . . . . . . . . 25
1.2. Web application session management and authentication tracking . . . . . 26
1.2.1. Browser-level authentication tracking . . . . . . . . . . . . . . . . 29
1.2.2. Application-level authentication tracking . . . . . . . . . . . . . . 30
1.3. JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.3.1. The Same Origin Policy (SOP) . . . . . . . . . . . . . . . . . . . . 31
1.3.2. JavaScript networking capabilities . . . . . . . . . . . . . . . . . . 33
1.3.3. Encapsulation and information hiding . . . . . . . . . . . . . . . . 34
7
Contents
8
Contents
9
Contents
10
Contents
14.Conclusion 215
14.1. Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
14.2. Future work and open problems . . . . . . . . . . . . . . . . . . . . . . . . 218
14.2.1. Shortcomings of the Same Origin Policy (SOP) . . . . . . . . . . . 218
14.2.2. Authentication tracking . . . . . . . . . . . . . . . . . . . . . . . . 219
14.2.3. Illegitimate external access to intranet resources . . . . . . . . . . 219
14.2.4. XSS Payloads in the internet execution-context . . . . . . . . . . . 220
14.2.5. Next steps for the Foreign Language Encapsulation Type . . . . . 220
14.3. Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
11
Contents
V. Appendix 223
12
Introduction
One click on an anchor might take you anywhere
from the next sentence to somewhere in New Zealand.
Dan Connolly, 19921
Motivation
The foundation of all web applications was laid in the first proposal of the World Wide
Web by CERN’s Sir Tim Berners-Lee in 1990 [18]. Initially, Berners-Lee envisioned the
WWW to serve as a powerful replacement for earlier document distribution systems, such
as Gopher or WAIS. However, the WWW has evolved since then from a delivery-system
of static hypertext documents to a full-fledged run-time environment for distributed
applications. Nowadays, web applications are ubiquitous: They are used for almost any
conceivable purpose, ranging from implementing the configuration interface of hardware
devices such as routers, over providing rich application functionality for word processing,
to implementing the graphical user interface of large scale enterprise applications.
The Web’s evolution was driven by continuous innovations, both on the server- and
on the client-side and was fostered by the ease of extending HTML and HTTP. Also,
CERN’s open policy in respect to handling the unfolding standards and the lively ex-
change of the early adaptors on the www-talk [189] mailing list aided this process. The
rapid development of the web application paradigm was driven by many heterogeneous
parties and can be, at best, described as “unplanned” and “chaotic”. In hindsight, the
process can be characterised by three independent key-developments:
For one, HTML-documents were quickly outfitted with the capability to contain in-
lined multi-media content, such as images via the img-tag2 . This content can be retrieved
from external web servers and is displayed as integral part of the hosting documents.
Thus, since then, a single document can combine elements from multiple origins. Fur-
ther HTML tags, such as iframe, object, or script, extended this capability with
additional types of external resources.
Furthermore, in the beginning, a web server only delivered static HTML pages which
were retrieved from the server’s filesystem. This behaviour was soon extended with
the ability to access WAIS-like directory services by adding simple query strings to
1
Dan Connolly, ”Re: The spec evolves...”, www-talk, 1992, http://1997.webhistory.org/www.lists/
www-talk.1992/0418.html
2
Marc Andreessen, ”proposed new tag: IMG”, www-talk, 1993, http://1997.webhistory.org/www.
lists/www-talk.1993q1/0182.html
13
Contents
the HTTP request3 . From this querying mechanism, it was only a short step towards
sophisticated HTML forms that could post complex information to the server. This in
turn resulted in an evolution of server-side methods to dynamically produce the delivered
HTML code. Such technologies advanced from simple shell scripts encapsulated in CGI-
wrappers [267], over special purpose programming languages like PHP [254], to complex
application-server frameworks, such as J2EE [252].
Finally, methods to include executable elements in HTML documents have been added
to the mix. Notably in this context was the introduction of JavaScript by Netscape in
its browser Netscape Navigator version 2.0B3 in December 1995 [34]. JavaScript allows
the creation of scripts which are tightly interwoven with the HTML document’s markup.
These scripts are executed while the document is displayed by the browser and enable
the programmer to script dynamic interaction with the document’s elements. Via this
step, the web browser grew from a simple HTML-viewer to an execution platform for
complex user-interfaces and non-trivial application logic.
This evolution of the web application paradigm has created several potential security
pitfalls (which we will explore in depth in this thesis): For example, originally HTTP
was never meant to carry authentication or session information, as it was conceived as
a simple request-response information delivery protocol. However, the extended usage
of web sites for application-like purposes demanded such features. For this reason, they
have been added on to the existing specification without being fully integrated into the
protocol.
Furthermore, the security policy that was adopted for JavaScript-code is origin based:
The policy mechanism derives its decisions solely from the origin of the hosting HTML
page. This seems ill fitted for a hypertext system which was designed to work trans-
parently over location-boundaries and which allowes the composition of documents from
elements which were retrieved from multiple origins.
And most significantly, the dominant method to dynamically create HTML content
from incoming data still has its roots in the wrapping of shell-scripts: The web-server
passes the request information to an executable which in turn utilizes string-operations to
create the response’s HTML code. This ad-hoc approach towards dynamically creating
HTML code from string-data is highly susceptible to code-injection vulnerabilities.
Consequently, the number of security vulnerabilities reported in connection with web
applications has increased steadily in parallel to the growing significance of the web
application paradigm (see Fig. 1). Especially, the type of string-based code injection
vulnerabilities in web applications4 account for approximately 50% of all reported issues
of the year 2006 [39].
Furthermore, the specific subclass of Cross-Site Scripting (XSS) vulnerabilities consti-
tutes the most wide spread vulnerability type of 2006 with 18.5% of all reported issues.
XSS allows the adversary to include arbitrary JavaScript code in the attacked web ap-
plication’s pages. In combination which the other security pitfalls of HTTP/HTML
3
Tim Berners-Lee, “Re: Is there a paper which describes the www protocol?”, www-talk, 1992, http:
//1997.webhistory.org/www.lists/www-talk.1992/0000.html
4
Consisting of subclasses such as Cross-Site Scripting, SQL Injection, or Directory Traversal; for details
concerning this vulnerability class please refer to Chapter 10.
14
2.6. XSS 15 Contents
1400
XSS
SQL injection
1200 PHP file inclusion
Buffer overflow
Directory traversal
800
600
400
200
0
20
20
20
20
20
20
01
02
03
04
05
06
Year
15
Contents
16
Contents
Contributions of Part I:
As reasoned above and in Section 3.5, based on the results of part I, we can deduce
two general directions towards solving the discussed issues: Designing dedicated counter-
measures to disarm specific payload classes and introducing methods towards removing
the underlying XSS issues by changing the process of developing web applications. The
following two parts of the thesis present our approaches in respect to these two general
areas.
As soon as the attacker is able to execute his script, his activities are unrestricted in
respect to the malicious actions identified in Part I. The methods proposed in this part
aim to disarm XSS Payloads by selectively depriving the adversary of certain capabilities.
This way the consequences of active exploitation of the vulnerability can be limited,
while the actual XSS issue still remains. As long as the process of web application
development has not reached a state in which XSS problems are only rarely encountered,
this general approach is valid to establish a second line of defense. This is achieved by
transparently modifying the execution environment of the web application. Hence, the
actual applications remain unchanged.
In Chapter 7 we closely examine the distinct methods of session hijacking which have
been isolated in Section 4.1. Based on this analysis, we propose three countermeasures,
each tailored to disarm one of the possible session hijacking attacks. A combination of
our three methods prevents all session hijacking attempts despite existing XSS prob-
lems. In Chapter 8 we utilize the same general methodology to handle Cross-Site
Request Forgery (CSRF): We closely analyse the underlying mechanisms that enable
CSRF attacks in the first place. Then, we introduce changes in the vulnerable authen-
tication tracking mechanisms which devoid the adversary from successfully launching
CSRF attacks. Finally, in Chapter 9 we attend the class of JSDAs that target intranet
resources. Due to an initial examination of the attack class, we deduct three potential
countermeasures (in addition to the practise of disabling JavaScript completely). We
discuss the advantages and drawbacks of each method and conduct a comparison of the
four methods. Based on this discussion, the most promising approach is implemented
and practically evaluated.
17
Contents
18
Contents
FLET-based interface for secure code-communication. To verify the usability of our ap-
proach, we show how to practically implement our concepts for a selected application
server.
• A systematical classification of language elements into the general classes data and
code (see Sec. 10.4).
We conclude the thesis in Part IV with an overview of related work, a summary of the
thesis’ results and a discussion of open problems.
Associated publications: Parts of, and ideas underlying this thesis have been previ-
ously published in the following forms:
• Martin Johns and Justus Winter. RequestRodeo: Client side Protection Against
Session Riding. In Frank Piessens, editor, Proceedings of the OWASP Europe
2006 Conference, refereed papers track, Report CW448, pages 5 – 17. Departement
Computerwetenschappen, Katholieke Universiteit Leuven, May 2006. [133]
19
Contents
• Martin Johns and Justus Winter. Protecting the Intranet Against ”JavaScript
Malware” and Related Attacks. In Bernhard Hämmerli and Robin Sommer, ed-
itors, Detection of Intrusions and Malware & Vulnerability Assessment (DIMVA
2007), volume 4579 of LNCS, pages 40 – 59, Springer, July 2007. [134]
• Martin Johns. On JavaScript Malware and Related Threats - Web Page Based
Attacks Revisited. Journal in Computer Virology, Springer Paris, 4(3):161–178,
December 2007. [128]
• Martin Johns, Bjoern Engelmann, and Joachim Posegga. XSSDS: Server-side De-
tection of Cross-Site Scripting Attacks. In Annual Computer Security Applications
Conference (ACSAC’08), pages 335 – 344. IEEE Computer Society, December
2008. [130]
20
Part I.
21
1. Technical Background
The World Wide Web is the only thing I know of whose shortened form
takes three times longer to say than what it’s short for.
Douglas Adams, 1999
This chapter explores selected technical topics in the field of web applications. As the
general technical background concerning web applications is very extensive, we specifi-
cally focus on aspects that have a direct relationship with the content of this thesis.
• and the web browser that provides the application’s user interface. This interface
is composed with HTML [117], CSS [266], and JavaScript [57]1 .
These two components communicate over the network via the HTTP protocol [74]. Fur-
ther, optional components of the application may be located
• or on the server-side, providing services to the web server, e.g., database systems.
A web application is completely defined by the specifics of how a given HTTP request
is used to compute the corresponding HTTP response. Therefore, as a potential first
formal approximation, a web application P could be regarded as a function which maps
1
Additional browser-based technologies, such as Flash [3] or Java Applets [251], are omitted for brevity.
23
1. Technical Background
an HTTP request Req to an HTTP responses Res, as suggested by the formal definition
approaches in [248] and [269]:
P : f (Req) → Res
However, the relationship between the incoming HTTP request and outgoing HTTP
response is not purely functional. Both, the web server as well as the web browser are
state-full entities and their specific states influence the result of a given computation and
the behaviour of the application: The browser state directly affects the outgoing HTTP
request, e.g., by setting HTTP headers. In addition, might also passively influence
the server-side processing, e.g., due to specific treatment based on the request’s source
IP address. Furthermore, the browser state can affect active client-side code, such as
JavaScripts, and thus, directly influence the application’s behaviour.
The server state consists of the data stored in the application’s persistent data store
(e.g., a database) and the values kept in the current usage session (see Sec. 1.2). The
server state determines the specifics of the HTTP response’s composition process. In
turn, the computation of incoming requests might alter the server state and the inter-
pretation of the response might change the browser state (e.g., by setting additional
cookies).
Hyper Text Markup Language (HTML): HTML [117] is a SGML-based markup lan-
guage which provides means for structuring and displaying hypertext, such as
links, tables, paragraphs, or lists. Furthermore, HTML is capable to supplement
the hypertext with interactive forms, embedded images, and other objects.
JavaScript: JavaScript [57] is a programming language most often used for client-side
web development. See Section 1.3 for further details.
Cascading Style Sheets (CSS): The Cascading Style Sheet (CSS) [266] standard was
introduced to allow the separation of the presentation of an HTML hypertext and
its structure. With CSS a web designer can specify display-classes which can be
assigned to individual HTML-elements. Such display-classes determine how these
elements are presented by the browser (e.g., by specifying font-size, position, or
margins).
HTTP Cookies: Cookies [158] provides persistent data storage on the client’s web browser.
A cookie is a data set consisting at least of the cookie’s name, value and its domain
property. It is sent by the web server as part of an HTTP response message using
the Set-Cookie header field.
The cookie’s domain property is implicitly controlled by the URL of its HTTP
response: The property’s value must be a valid domain suffix of the response’s full
domain and contain at least the top level domain and second-level domain.
24
1.1. The web application paradigm
After receiving a cookie the web browser stores this information at a dedicated
location in the client’s file system. Whenever the web browser accesses a URL
that matches the cookie’s domain (the domain value of the cookie is a valid domain
suffix of the URL), the cookie is automatically included in the HTTP request using
the Cookie-header.
For example, a cookie stored with the domain example.org would be included in
every HTTP request to resources that reside on www.example.org or subdomain.
example.org.
URL schemes
In current web browser implementations, the URL’s protocol property is not limited
to http and https. Instead a broad range of protocol identifier (the so-called URL
schemes) are understood. With such schemes both remote and local resources can be
addressed.
URL schemes can target, for instance remote network entities, which are reachable
by network protocols such as ftp, the local file-system using the file-scheme, browser
specific resources via schemes such as chrome, or other local applications.
In this context Zalewski differentiates in [283] between true schemes, custom schemes
and pseudo schemes:
25
1. Technical Background
• True schemes are natively supported and handled by the browser. Furthermore,
the browser’s rendering engine respects and processes such URLs when they are
encountered in the context of inline-HTML tags, such as img, or script.
Zalewski list the following schemes under this category: http (RFC 2616 [74]),
https (RFC 2818 [217]), shttp (RFC 2660 [218]), ftp (RFC 1738 [19]), file
(RFC 1738 [19]), gopher (RFC 4266 [107]), and news (Draft RFC [59]).
• Custom schemes are not standardized schemes which are used to initiate data-
transfer to locally installed applications. Such schemes are not handled by the
browser. Instead, local applications which expect to receive data via URLs, register
their set of understood URL schemes at the operating system. Whenever the web
browser encounters an unknown URL scheme, it queries the operating system to
obtain the application which registered the scheme. If such a program exists, it
will be launched as needed.
For example, the activation of mailto-URLs causes the opening of the composing
dialogue in the default mail client.
This set of protocols is not honored within the renderer when referencing document
elements such as images, script or applet sources, and so forth; they do work,
however, as iframe and link targets.
Definition 1.2 (Session Identifier (SID)) With the term Session Identifier (SID)
we denote all identifier tokens which are
26
1.2. Web application session management and authentication tracking
27
1. Technical Background
28
!"##$%&'()&)*"("&+',$+-'.%%/$"#
Both HTTP authentication and TLS/SSL are implemented and enforced by the web
server (opposed to the actual web application). This complicates the implementation of
an application-level user- and authorization-management, as the web server and the web
application are often separate, loosely coupled entities. Doing so, would require a web
application to implement web server specific configuration management which is unde-
sirable for a series of reasons2 . Consequently, the first option – coupling authentication
handling with the application’s session management – is the preferred technique.
In respect to security issues discussed in Section 5.1 it is important to differentiate
between two distinct types of authentication tracking: browser-level and application-level
authentication tracking3 :
29
1. Technical Background
• HTTP authentication: After the first manual authentication step, the browser
remembers the user’s authentication credentials (i.e., username and password). All
following HTTP requests to URLs which target the same resource are outfitted
with a suiting Authorization-header automatically.
As motivated above, all these methods have in common, that after a successful ini-
tial authentication, the web browser either includes the authentication tokens (the SID
cookie, or the http authentication credentials) automatically or uses the authenticated
TLS/SSL channel in further requests without user interaction.
The specifics how individual web browsers implement these authentication tracking
mechanisms can differ slightly. [68] documents how the browsers Firefox 2.0 and Mi-
crosoft Internet Explorer 7.0 implement the processes.
30
1.3. JavaScript
1.3. JavaScript
Before describing security relevant topics in connection with JavaScript, we give a brief
overview of the language: JavaScript was developed by Brendan Eich of Netscape Com-
munications Corporation and was first introduced and deployed in the Netscape browser
version 2.0B3 in 1995. Since then it has become the de facto standard scripting language
for web browsers and it is widely supported. JavaScript 1.5 has been standardized by
ECMA as “ECMAScript” [57] in 1999. Even though the name JavaScript and the lan-
guage’s syntax hint a resemblance to Sun’s Java programming language, JavaScript is a
programming language with its very own characteristics. JavaScript contains semantics
of object oriented programming as well as aspects that are usually found in functional
languages. In this thesis, we describe JavaScript from an object orientated point of view.
JavaScript is not limited to webpages. It is also used, e.g., for server side program-
ming on application servers [213], the user interface of the Mozilla applications [24, 69],
scripting in files using the Adobe PDF [2] format, or programming the Widgets of the
Mac Os X Dashboard [10].
If embedded in web pages, JavaScript provides rich capabilities to read and write
the hosting web page’s elements. These capabilities to manipulate the appearance and
semantics of a webpage are provided through the global object document which is a
reference to the root element of the page’s DOM tree [102]. A script can create, delete
or alter most of the tree’s elements.
31
1. Technical Background
1. No direct access to the local file system. Within JavaScript/HTML local files can
only be referenced through the file:// meta-protocol. An attempt by a script
delivered through HTTP to directly access the target of such a reference would be
a violation of the “protocol”-rule of the SOP.
2. No direct access to other hosts but the one that served the web page in which the
script was included, due to the “domain”-rule of the SOP.
3. No direct access to other applications on the same host that are not hosted by the
same web server, due to the “port”-rule of the SOP.
The SOP’s access restrictions apply to accessing remote resources (see Sec. 1.3.2) as
well as to accessing elements which are displayed by the browser. In the latter case, the
SOP applies on a document-level. This means, all elements that are displayed by the
browser inherit the origin of their enclosing document.
Thus, if a JavaScript and a document share a common origin, the SOP allows the
script to access all elements that are embedded in this document. Such elements could
be, e.g., images, stylesheets, or other scripts. These granted access rights hold even if
the elements themselves where obtained from a different origin.
32
1.3. JavaScript
Furthermore, in order to use this capability to access a second document (e.g., which
is displayed in an Iframe or in a different browser window), it is required that both
documents actively assign a value to their document.domain property [191].
Security zones
To selectively soften the SOP, web browser respect so-called “security zones” [186]. Such
zones classify resource-location (signified through URLs) according to their correspond-
ing trust-level. For instance, resources that are hosted on the browser’s computer are
more trusted than resources hosted on the intranet which, in turn, are considered to be
more trustworthy than general intranet resources.
For example, most browsers grant additional privileges that exceed the SOP’s restric-
tions to JavaScript which was retrieved from the local computer via file://-URLS. The
specifics how these security zones are implemented differ between the existing browser
implementations.
Direct communication
With the term direct communication we denote the capabilities of a JavaScript to initiate
a direct read/write HTTP connection to a remote host. For this purpose, modern
JavaScript implementation provide the XMLHTTPRequest-API which was originally
developed by Microsoft as part of Outlook Web Access 2000 and is currently being
standardized by the W3C [258].
XMLHTTPRequest allows the creation of synchronous and asynchronous HTTP GET
and POST requests. The XML part of the name is misleading. The API supports
requests for arbitrary, character-based data. The target URL of the request is subject to
the SOP, i.e., only URLs that satisfy the SOP in respect to the web page that contains the
initiating script are permitted. This effectively limits a script to direct communication
with the web application’s origin host.
Alternatively, direct communication can be accomplished by combining iframes with
dynamically submitted HTML forms [163]: The JavaScript creates an HTML form in-
side an iframe and submits it, thus creating a GET or POST HTTP request. The
server includes the requested data inside the HTTP request’s response which replaces
the iframe’s content. As long as the SOP is satisfied in respect to the containing web
page and the iframe’s URL, the JavaScript can access the iframe’s DOM tree to retrieve
the response’s data. Again, for a read/write communication the URL of the target host
is restricted by the SOP.
33
1. Technical Background
Indirect communication
Furthermore, a JavaScript is able to initiate network communication indirectly via DOM
tree manipulation. Some HTML elements employ URLs to reference remote data which
is meant to be included in the web page, such as images, or scripts. If a web browser en-
counters such an element during the rendering process, it initiates a network connection
in order to retrieve the referenced data. In this case, the URL of the remote entity is not
restricted and can, therefore, point to cross-domain or cross-protocol targets. JavaScript
is able to add elements to the DOM tree [102] of its containing page dynamically. By
including elements that reference remote data, the JavaScript indirectly creates a net-
work connection to the host that serves this data. Outgoing data can be included in the
request by adding GET parameters to the elements URL.
In most cases indirect communication can only be used to send but not to receive
data. An exception to this rule, besides the side-effect based channels that will be
discussed in Sections 3.3, can be created with the script-elements. By providing a
remote-script with a local callback-function, the remote script can communicate data
back to the calling script (see [185] for details). For instance, so called “web APIs” that
export certain functionality of a web application and “web mashups” [1], that employ
such APIs to include cross-domain content dynamically into web pages, are often created
this way.
34
2. Cross-Site Scripting (XSS)
In the context of web applications, the term Cross-Site Scripting (XSS) denotes a class of
attacks in which the adversary is able to inject HTML or Script-code into the application
[255, 151, 60, 90, 95]. The first public advisory on XSS was published in 2000 [33]. In
this chapter we discuss all relevant aspects of this attack class and document which
circumstances can lead to XSS vulnerabilities.
Motivation: Before we explore the full set of potential causes, we start with an wide-
spread example of a vulnerable case [72]. Take an internet search-engine that utilizes an
HTML form to obtain the targeted search-term:
1 < form action =" search . php " method =" GET " >
2 Please enter your query :
3 < input name =" q " type =" text " size ="30" >
4 < input type =" submit " >
5 </ form >
35
2. Cross-Site Scripting (XSS)
1 [...]
2 You have searched for <b > < h1 > hallo </ h1 >ß </ b >.
3 [...]
Therefore, by submitting a script-tag pair, JavaScript can be injected into the web
application:
1 [...]
2 You have searched for <b > < script > alert ( ’ xss ! ’); </ script > </ b >.
3 [...]
Within the general class of XSS vulnerabilities one can differentiate between the two
sub-classes HTML Injection and Script Injection:
Definition 2.1 (HTML Injection) The term HTML Injection Vulnerability denotes
XSS issues in which an attacker is able to inject HTML code into one or more of a
web application’s pages. However, he is not able to insert active scripting content, like
JavaScript into the page.
Using HTML injection the adversary is able to alter the content of a specific web page.
This action is occasionally also known under the term web graffiti [229].
Definition 2.2 (Script Injection) The class of Script Injection vulnerabilities denotes
all XSS issues which allows the attacker to inject active scripting code, like JavaScript,
into one or more of the application’s web page.
A situation in which script injection is prevented but HTML injection attack is possible
may occur in the case of incomplete input-filtering (see Sec. 2.4). In such cases the
application succeeds in prohibiting the injection of script code, but still unintentionally
allows certain HTML tags. In the related literature the two names of the two sub-
classes are often used interchangeably. As the countermeasures that we discuss in Part II
specifically deal with script injection attacks, a precise distinction is of significance.
Note: For the remainder of this document, whenever we use the term Cross-Site Script-
ing (or XSS) we implicitly assume that the adversary is capable of script injection, as this
inherently enables him to also execute HTML injection. Furthermore, we will concen-
trate on the malicious inclusion of JavaScript (see Sec. 1.3). While other browser-based
scripting languages, such as VBScript, exist, concentrating on JavaScript does not affect
the generality of the respective content in this thesis: Both, the methods to include the
scripting code in the web page, and the capabilities of the included scripts, do not differ
significantly between the available scripting-technologies. Therefore, all obtained results
for JavaScript also apply to similar browser-based scripting techniques. An exception to
this rule are active technologies that rely on interpreters that are added to the browser
in the form of plug-ins, such as Java [250], Flash [3], or Silverlight [187]. Whenever
necessary, we discuss these technologies separately.
36
2.1. Types of XSS
Cross-Zone Scripting
A specific sub-type within the class of XSS vulnerabilities is called Cross-Zone Scripting.
A Cross-Zone Scripting vulnerability occurs when two circumstances exist in combina-
tion:
2. and this issue is exploitable by a resource which is hosted within a less trustworthy
security zone (e.g., the internet).
As JavaScript which is loaded from trusted security zones is not restricted by the SOP,
the exploitation of Cross-Zone Scripting outfits the attacker with powerful capabilities.
1. Reflected XSS: The term reflected XSS denotes all non-persistent XSS issues,
which occur when the web application echos parts of the HTTP request in the
respective HTTP response’s HTML (see Figure 2.1 and Listing 2.6). In order to
successfully exploit a reflected XSS vulnerability, the adversary has to trick the
victim into sending a fabricated HTTP request. This can be done by, for instance,
sending the victim a malicious link, or including a hidden iframe into an attacker
controlled page.
1 $name = $_GET [ ’ name ’];
2 echo " Hallo " + $name + "!";
2. Stored XSS The term stored XSS refers to all XSS vulnerabilities, where the
adversary is able to persisently inject the malicious script in the vulnerable ap-
plication’s storage (see Figure 2.2). This way the malicious script remains in the
application even when the usage session which initially caused the exploitation has
ended. Hence, every user that accesses the poisoned web page receives the injected
script without further actions by the adversary. Therefore, unlike reflected XSS,
37
Concept String Matcher
reflected XSS
after successfully embedding the malicious script into the application, the actual
exploitation does not rely on any means outside the vulnerable application.
Stored XSS issues are the foundations of self-replicating XSS worms [168, 65, 140,
257, 85]. Such worms replicate within the pages of a given web application, spread-
ing the script on multiple pages. The first large-scale XSS worm was the so-called
“Samy is my hero” worm [140] (also known as JS.Spacehero [244]) that infected
the social networking site myspace.com in 2005. The worm was injected by its
author Samy Kamar into his myspace.com profile page. The script caused every
logged-in user of the site to add a copy of the script to their own profile, causing
an exponential propagation rate. Within less than 24 hours more than one million
profile pages got infected with the script [140]. The first documented cross-domain
XSS worm that spread on more than one domain was created by Rosario Valotta
[257] in 2007.
3. DOM-based XSS [153] is a special variant of reflected XSS in which logic er-
rors in legitimate JavaScript cause XSS conditions by careless usage of client-side
data. More precisely, DOM-based issues may occur if a JavaScript uses attacker-
controlled values (e.g., the document’s full URL) to alter the HTML content of its
web page.
38
2.1. Types of XSS
1. Server induced: This type of XSS vulnerabilities occurs when a defective web
server is utilized to deliver the application’s HTML. In such a case XSS issues are
introduced in all applications that are served from this server, regardless of the
respective application’s source code.
A common server induced XSS problem may occur with server-wide error pages
[165, 278]. E.g., in 2007 a large number of web applications that were hosted by
the internet provider 1&1 suffered from XSS issues because of vulnerable default
404-error-pages [278]. Besides erroneous configuration, as it is the case with such
vulnerable default template files, server induced XSS can also be caused by pro-
gramming errors in the actual server. E.g., in 2006 most web applications that
were served by the Apache web server [167] were susceptible to XSS due to wrong
handling of the Expect-HTTP-header by the server [284].
39
2. Cross-Site Scripting (XSS)
• Injection position: Where is the attacker controlled syntax injected within the
resulting HTML code? Possible injection positions are either:
40
2.2. Selected XSS techniques
In certain cases, the attacker can change the injection position by injecting addi-
tional meta-characters at the beginning of his attack string. This way he is able to
“break out” of the current context. For instance, if the injection position is located
within an HTML tag, he can use the ’>’ character to close the HTML tag and move
the injection position into the non-markup context of the document. Accordingly,
he can inject additional quotes or double-quotes to terminate HTML-attributes.
• Injection size: In certain cases the length of the injected data is limited by the web
application.
Script code encapsulation: Depending on the exact situation, the adversary may uti-
lize one of the following techniques to insert the actual script code into the web page:
41
2. Cross-Site Scripting (XSS)
1 [ The submitted name value was set to : ’ foo "; alert ( ’ xss ! ’); // ’ ]
2 < script >
3 [...]
4 var name = " foo "; alert ( ’ xss ! ’); //";
5 [...]
6 </ script >
42
2.3. XSS outside the browser
43
2. Cross-Site Scripting (XSS)
If output sanitation [90] is employed, certain characters, such as <, ", or ’, are HTML
encoded before user supplied data is inserted into the outgoing HTML. As long as all
untrusted data is disarmed this way, XSS is prevented.
Both protection approaches fail frequently [39], either through erroneous implemen-
tation, or because they are not applied to the complete set of user supplied data. Sev-
eral information-flow approaches for static source code analysis have been discussed
[239, 109, 170, 269, 136] in order to aid developers to identify source code-based XSS.
However, due to the undecidable nature of the underlying problem [164, 219] such ap-
proaches suffer from false positives and/or false negatives.
44
3. Exploiting XSS Issues
We’re entering a time when XSS has become the new Buffer Overflow
and JavaScript Malware is the new shellcode.
Jeremiah Grossman [88]
Definition 3.1 (JavaScript Driven Attack (JSDA)) With the term JavaScript Driven
Attack (JSDA) we subsume all attacks that are carried out by executing malicious JavaScript
within the victim’s web browser.
Note: We are aware that the interpretation of the term malicious is subjective. Within
the context of this thesis, we define a malicious script according to its actions: If the
script is performing actions that either undermine the victim’s privacy (confidentiality
attacks), carry out a denial-of-service attack (availability attacks), or execute unwant-
ed/unintended state changing actions against the victim’s consent (integrity attacks),
we classify the script as malicious (for a further discussion of these attack-types please
refer to Section 3.4.3).
45
3. Exploiting XSS Issues
A defining property of JSDAs is that such attacks solely employ “legitimate” means
which are either properly defined in the language specification, provided by the web
browser’s public interface, or constitute characteristics of the associated protocols, such
as HTTP. This distinguishes this class of attacks from browser based exploits which rely
on security vulnerabilities within the browser’s source code [215].
1. Deactivate JavaScript.
2. Only visit web applications which are trusted by the user to not carry out malicious
actions. From here on, we denote such web applications as trusted web applications.
With the birth of the “Web 2.0” phenomena [205] and the trend towards rich web
applications which mimic the behaviour of their desktop counterparts, the usage of
JavaScript became ubiquitous and in most cases mandatory. Thus, the advice to gener-
ally deactivate JavaScript is only of very limited applicability. Furthermore, restricting
potential web destinations to only explicitly trusted web pages is incompatible to most
user’s usage patterns. However, weaker variants of the two strategies can be combined
to form an effective policy:
Browser extensions, such as NoScript [175] can aid this approach in a semi-automated
fashion. By utilizing this defensive practice, a user can effectively prevent all attacks
which are hosted on malicious pages.
By following the described defensive policy, a web user implicitly partitions the set of
all web applications into two classes: Trusted, which are permitted to execute JavaScript,
and untrusted, for which JavaScript execution is prohibited.
46
3.2. XSS Payloads
Definition 3.2 (XSS Payload) A JSDA which is injected into a trusted web applica-
tion context by exploiting an XSS vulnerability is called XSS Payload.
By injecting the JSDA into a trusted web application via XSS an adversary creates a
situation in which the injected script is indistinguishable from the application’s legit-
imate JavaScripts. Therefore, by granting the right to execute scripts to the trusted
application, the injected script is also permitted to run. Therefore, the defensive policy
is defeated and the attack can take place. Hence, in conclusion, we state the following
observation:
For this reason, the remainder of this thesis will focus on the capabilities of XSS Payloads
(the rest of this chapter, as well as Chapters 4 – 6), payload-specific countermeasures
(Part II), and language-based XSS avoidance methods (Part III).
Note: An XSS exploit can also utilize non-JavaScript payloads, such as malicious Flash
or Java applets. However, active content delivered this way is cleanly separated from the
web page’s HTML and the location of such applets is easily identified by their respective
applet-, embed- or object-tags. Furthermore, unlike JavaScript, these technologies were
not specifically designed to interact with the web page’s HTML layer. For this reason,
their execution is not crucial in respect to general interaction with a web application’s
user interface. Therefore, it is feasible to block such content even in the context of
trusted web applications. Browser add-ons, such as FlashBlock [42], or filtering web
proxies can enforce a mandatory opt-in policy, in which every execution of an embedded
applet has to be explicitly initiated by the application’s user.
On the other hand, JavaScript is closely interweaved with the hosting web page’s
HTML content and in many cases provides crucial UI functionality which is necessary
for basic interaction with the web application. Thus, an according opt-in approach on a
per-script basis is not feasible.
47
3. Exploiting XSS Issues
execution within the web application, comparable as exploiting a Buffer Overflow allows
the adversary to execution code within a vulnerable application.
• The script can create HTTP requests to arbitrary URLs of arbitrary external
locations by including remote elements into the page’s DOM tree.
• The script can receive and intercept events that might be triggered by the inclusion
process.
• After the inclusion process has ended, the remote element is part of the same
document as the script. Due to the document-level nature of the SOP, the script
now has access to properties of the element (see [273] and Table 3.1) that are
readable through JavaScript calls.
In the next sections we explain how this loophole can be exploited for malicious purposes.
48
3.3. Frequently used attacks techniques
1. The script constructs an URL pointing to the remote entity of which the existence
should be examined.
2. Then the script includes a suiting, network-aware element in the webpage that
employs the constructed URL to reference the remote entity. Such elements can
be e.g., images, iframes or remote scripts.
49
3. Exploiting XSS Issues
0. Preparation: The attacker aims to subvert the SOP in respect to the domain
target.com.
The adversary is in full control over a given DNS entry, e.g. attacker.org. He con-
figures the respective DNS server to let attacker.org resolve into the IP address of
an internet host which is also owned by the adversary, e.g. 200.200.200.200. The
DNS answers for attacker.org are supplied with a minimal time-to-live (TTL)
value causing them to expire immediately.
1. The adversary causes the victim’s browser to load an HTML page from the ad-
versary’s server using a URL that starts with http://attacker.org. Before cre-
1
The HTTP 1.1 specification [74] allows an optional host-header which was introduced for situations
in which a given web server hosts more than one domain (so-called “virtual hosts”). However, in
cases where no further virtual hosts have been configured, the host-header is ignored.
50
3.4. Systematic overview of JSDAs / XSS Payloads
ating the HTTP request, the web browser executes a DNS lookup, thus, receiv-
ing the IP 200.200.200.200 to be used for the request’s target location. The
browser requests, receives and renders the response’s HTML content. The con-
tained JavaScript payload is parsed and executed.
2. Immediately after the victim’s initial HTTP request was received, the adversary
changes the DNS mapping of attacker.org to the IP address of the targeted
server target.com, e.g. 1.2.3.4.
3. The malicious JavaScript initiates further direct HTTP communication (see Sec. 1.3.2)
with attacker.org, e.g. by utilizing an iframe, a pop-up window, or the XMLHTTP-
Request-object.
4. As the DNS entry for attacker.org has expired, the browser conducts a second
DNS lookup for the domain. As the adversary has changed the IP mapping, the
domain now resolves to target.com’s server IP (1.2.3.4).
5. The browser creates the HTTP request and sends it to 1.2.3.4, while assigning
the response’s content to the domain attacker.org. As the browser considers
both the adversary’s JavaScript as well as the target’s HTML to belong to the
same domain, the malicious JavaScript has full read/write access to all resources
that are hosted on target.com.
See Section 6.2.1 and Figures 6.3.A to 6.3.C for an exemplified attack scenario.
DNS pinning: To counter this attack most modern browsers implement “DNS pinning”:
The mapping between a URL and an IP-address is kept by the web browser for the entire
lifetime of the browser process even if the DNS answer has already expired.
The practise of DNS pinning is not undisputed: DNS pinning introduces problems
with dynamic DNS services and DNS based redundancy solutions. Furthermore, DNS
pinning is unable to protect against multi-session attacks as they have been described
by Soref [245] and Rios [220]. Finally, DNS pinning is a direct violation of RFC 2616
[74] which states “HTTP clients [...] MUST observe the TTL information reported by
DNS” (Section 15.3).
51
3. Exploiting XSS Issues
(A) Application
(B) Browser
(C) Computer
(D) Intranet
(E) Internet
3.4.1. Execution-contexts
The actual capabilities and potential attack-targets of a given JavaScript are defined by
the specific characteristics of the environment in which it is executed (e.g., the hosting
application or the type of web browser that interprets the script) - the script’s exe-
cution environment. A closer examination of such execution environments yields the
following observation: A given JavaScript is executed in a cascade of growing, inclusive
contexts. The script is embedded in a web application. This application is accessed using
an instance of a web browser. This browser instance is executed on a computer. This
computer is part of an intranet and has access to the internet. Thus, within a given exe-
cution environment we can differentiate between several, disjunctive execution-contexts,
which are derived from on a series of inclusive boundaries (see Figure 3.1). Each of these
contexts represents a specific set of potential attack-targets and -capabilities.
Based on the observations stated above, in the context of this thesis we differentiate
between the following five execution-contexts: application, browser, computer, intranet,
internet. The transition between a inner to the next outer context boundary is defined
by two characteristics:
• The set of applicable attack-targets increases (e.g., all internet hosts instead of
only the intranet hosts).
• The script’s capabilities decrease (e.g., within the hosting application the script is
not restricted by the SOP, however, outside of the application execution-context
the SOP takes effect).
For a better understanding of these two characteristics please refer to the detailed
discussion of all execution-contexts given in Section 3.4.4.
3.4.2. Attack-targets
To determine a script’s capabilities in a given execution-context, it is necessary to es-
tablish all its potential attack-targets within this execution-context. As discussed in
Section 1.3.1, every JavaScript is subject to the execution sandbox which is enforced
52
3.4. Systematic overview of JSDAs / XSS Payloads
by the SOP. Therefore, all malicious actions of a given script that target resources out-
side of its hosting web application are limited to the cross-application communication
methods documented in Sections 1.3.2. As shown, all of these communication methods
rely on addressing the communication target via an URL. More precisely, a necessary
characteristic of a potential application-external attack-target is that a script can use
an URL to address the target.
Therefore, a script’s attack-targets and -capabilities are completely defined by the set
of URLs that a script can address. For this reason, it is sufficient to examine the set
of available URL schemes (see Sec. 1.1.2) in combination with the scheme’s respective
targets and their potential effects on such targets.
Definition 3.3 (State attack) An state attack aims to undermine the target’s in-
tegrity by committing a state-changing action which exceeds the attacker’s legitimate
authorisation.
While a real-world XSS Payload may contain more than one attack-type in combina-
tion, it is always possible to partition a composite attack into sub-attacks which fit in
one of the defined attack-types.
We will use these attack-types as a mean to categorise documented attacks in our
attack classification which we present in Section 3.4.4. However, unlike state and confi-
dentiality attacks, the details of web-based denial-of-service attacks are not specific for
53
3. Exploiting XSS Issues
54
3.4. Systematic overview of JSDAs / XSS Payloads
Leaking
Attack-capability application CSRF
state
1. Execution-context
2. Attack-target
3. Attack-type
4. Attack-capability
55
3. Exploiting XSS Issues
• TypeID: Either the letter s for state attacks or the letter c for confidentiality
attacks.
• Confidentiality:
– A.1.c.1: Leaking of session data (see [148] and Sec. 4.1.1)
– A.1.c.2: Leaking of password data (see [105] and Sec. 4.2)
– A.1.c.3: Leaking of other sensitive values obtained from the application’s
web pages (see [261])
• State:
– A.1.s.1: Session hijacking (see [123] and Sec. 4.1)
(B) Browser-context: The script is executed in a specific, currently running browser in-
stance. While the script is executed, the user might concurrently maintain further
state-full relationships with other web applications which are accessed with the
56
3.4. Systematic overview of JSDAs / XSS Payloads
same browser instance. Such state-full relationships could be, for instance, current
active usage sessions or valid authentication contexts. All cross-domain interaction
of the script with these applications are executed in the user’s state-full execution
context.
Furthermore, the browser itself also is a state-full entity defined by its static and
dynamic properties. Static browser properties are, for instance, vendor, version,
or installed plug-ins. With dynamic browser proprieties we denote all attributes
and value sets that change during a given usage session, such as browser cache
or history. Depending on the specifics of a given property, a malicious script
may read or alter it. The adversary’s actual capabilities in respect to the listed
properties depend heavily on the type and version of the used browser program.
In this context, the adversary can attempt to employ pseudo URL schemes (see
Sec. 1.1.2) which by definition only target browser-internal resources.
B.1 State-full web applications reachable through the schemes http and https
[70, 23, 180, 86, 37, 207, 27, 234]
B.2 Dynamic browser properties reachable through the schemes http and https
[41, 87, 161]
B.3 Static browser properties reachable through pseudo schemes, such as chrome,
resource, or res [96, 179, 265]
• Confidentiality:
– B.1.c.1: Leaking application-state (see [86, 37], and Sec. 5.2.3)
– B.2.c.1: CSS-based privacy attacks (see [41, 87, 161] and Sec. 5.2.1)
– B.2.c.2: Timing-based privacy attacks (see [70, 23, 180] and Sec. 5.2.2)
– B.3.c.1: Browser fingerprinting (see [96, 179, 265] and Sec. 5.2.3)
• State:
– B.1.s.1: Cross-Site Request Forgery attacks (see [207, 27, 15, 137, 234,
133] and Sec. 5.1)
57
3. Exploiting XSS Issues
(C) Computer-context: The browser instance which hosts the malicious script is ex-
ecuted on a given computer. For this reason, the malicious script may interact
with resources, such as files, applications, and local network services, which are
only accessible on this computer. Specifically, local HTTP servers, which pro-
vide interfaces to local services [92] or applications [32] are potential targets. In
this execution-context, the effects of custom URL schemes (see Sec. 1.1.2) are
subsumed, as such schemes serve the purpose to implement the interaction with
browser-external, locally installed applications.
C.1 Computer local HTTP server reachable through the URL schemes http and
https [32, 92]
C.2 Local ASCII based network services reachable through the URL schemes http
and ftp [256, 5, 4]
C.3 The computer’s filesystem reachable through the URL scheme file [238, 108,
78]
C.4 Installed applications reachable through custom URL schemes, such as picassa
[179, 220, 171]
• Confidentiality:
– C.{1,2,3}.c.1: Computer fingerprinting (see [238, 264] and Sec. 5.2.3)
– C.1.c.2: Leaking the content of local HTTP servers via DNS rebinding
(see [124, 90, 29] and Sec. 6.2)
• State:
– C.{1,2}.s.1: Exploiting low-level issues by accessing vulnerable, local
servers [92]
58
3.4. Systematic overview of JSDAs / XSS Payloads
(D) Intranet-context: The victimized web browser is in most cases located within an
intranet which is shielded from the outer internet by network devices like fire-
walls. Therefore, the adversary may use the browser’s cross-domain networking
capabilities to access internal hosts which are otherwise inaccessible to him.
Furthermore, we include into this context all network locations which are not
part of the victimized computer’s intranet but derive access rights based on the
requesting IP address.
D.1 HTTP servers located in the intranet reachable through the URL schemes
http and https [160]
D.2 ASCII based intranet services reachable through the URL schemes http and
ftp [256, 5, 4]
D.3 Network hosts located in the intranet reachable through various URL schemes
(e.g., http and https) [160, 91]
• Confidentiality:
– D.{1,2,3}.c.1: Enumerating and fingerprinting existing intranet hosts and
services (see [160, 91] and Sec. 6.1.2)
– D.1.c.2: Leaking the content of intranet HTTP servers via DNS rebinding
(see [124, 90, 29] and Sec. 6.2)
• State:
– D.1.s.1: Exploiting further XSS problems in intranet HTTP servers to
escalate attack-capabilities into the application context [90]
– D.1.s.2: Exploiting low-level issues by accessing vulnerable, local servers [92]
– D.2.s.1: Exploiting low-level issues in vulnerable, ASCII-based intranet
network services [4]
59
3. Exploiting XSS Issues
(E) Internet-context: Finally, the malicious script may use its cross-domain abilities to
access arbitrary hosts and services on the public internet. This context contains all
internet hosts and services for which the browser does not maintain any state-full
relationship (such attack-targets are already contained in the browser-context).
Per se, using the compromised browser for the attacks listed in this context does
not provide the attacker with expanded capabilities as all attack-targets are al-
ready accessibly to him. However, the adversary may use the victimized browser
as an attack proxy, hence, effectively hiding his own network location. Further-
more, in scenarios where the malicious JavaScript is executed by many independent
browsers simultaneously, for example as part of an XSS worm’s payload, the ad-
versary might gain botnet like power [162, 89].
E.1 HTTP servers located in the internet reachable through the URL schemes
http and https [89, 162, 106]
E.2 ASCII based internet services reachable through the URL schemes http and
ftp [256, 5, 4]
E.3 Public network hosts reachable through various URL schemes (e.g., http and
https) [162, 106]
• Confidentiality:
– E.{1,2,3}.c.1: Vulnerability scans of internet hosts (see [162, 106], Sec. 6.3.1,
and Sec. 6.3.2)
• State:
– E.1.s.1: Exploiting low-level issues by accessing vulnerable HTTP servers [92]
– E.1.s.2: Committing click-fraud (see [113] and Sec. 6.3.3)
– E.2.s.1: Exploiting low-level issues in vulnerable, ASCII-based internet
network services [4]
60
3.5. Thesis scope: Countering XSS Payloads
These two general approaches closely mirror the strategies that were utilized in respect
to memory corruption vulnerabilities: For one, approaches to find such problems (e.g.,
[260, 239, 56, 35, 12]) and to secure the C programming language (e.g., [196, 120, 166])
were proposed, in order to secure applications fundamentally. In parallel, researchers
designed methods to counter the exploitation of vulnerabilities, in order to provide pro-
tection in case of an existing issue (e.g., [45, 226, 64, 282, 281, 47, 38, 14, 46]).
61
3. Exploiting XSS Issues
62
4. XSS Payloads: Application Context
In this chapter we discuss notable, previously disclosed XSS Payloads which are located
within the application execution-context. Such attacks directly target the web applica-
tion in which they have been injected through the XSS exploit. Therefore, the malicious
script is not restricted by the SOP and has full control over all client-side features of the
application that are exposed to running JavaScript. This chapter focuses on two attack
classes which directly target the web application’s authentication mechanisms. Section
4.1 discusses the adversaries capabilities to overtake the user’s authenticated session for
impersonation purposes. Section 4.2 documents methods which allow the attacker to
obtain the user’s password in clear-text for future use.
Definition 4.1 (Session hijacking) With the term session hijacking we denote all
JSDAs that enable the adversary to commit arbitrary state-changing actions within the
attacked web application in the victim’s authentication context.
From the application’s point of view, all actions by the adversary executed through a
session hijacking attack are indistinguishable from legitimate actions by the attack’s
victim (i.e., by the authenticated user which accesses the exploited application). Thus,
a session hijacking attack empowers the attacker to temporary overtake the victim’s
identity in respect to the exploited application. Session hijacking attacks may either
require real-time interaction by the adversary, or be fully pre-scripted for automatic
execution. The latter case is, for instance, used by XSS worms [168].
All currently known XSS session hijacking attack methods can be assigned to one of
the following different classes: “Session ID theft”, “browser hijacking” and “background
XSS propagation”. In the following sections we define and discuss each of these attack
classes.
63
4. XSS Payloads: Application Context
Web Server
SID
XSS
It does not matter which of the methods described in Section 1.2 of SID storage is
used by the application - in all these cases the attacking script is able to obtain the SID.
However, if the application implements non-SID-based authentication tracking mech-
anisms, such as HTTP authentication or client-side SSL, this attack fails, as in this cases
the SID alone is not sufficient. Also, a subset of modern web browsers provide “http-
only” cookies which allow SID storage which is not accessible by JavaScript [193]. In
such cases the adversary is forced to create the full hijacking attack within the victim’s
browser. See Sections 4.1.2 and 4.1.3 for details.
64
4.1. Session hijacking
Web Server
XMLHttpRequest
Web Browser Attacker
Website
<html><body>
.... SID
XSS
are placed by the script. Thus, the malicious script is capable of acting under the identity
of the user and commit arbitrary actions on the web application.
In 2005 the so called “Samy is my hero” worm employed this technique to create a
self replicating JavaScript worm that infected approximately one million profiles on the
website myspace.com [140] (see also Section 2.1.1).
Please note: This attack does not depend on the availability of the XMLHttpRequest
object. It can also be executed using hidden iframes [163].
65
4. XSS Payloads: Application Context
Attacker
Web Server
Web Browser
main window
control
Script
pop under
window
Website C
Website B
Website A
<html><body>
....
create
XSS
66
4.2. Password theft
do not exhibit characteristics that would make them a potential attack target (such
as sensitive date, or financial information). This section discusses several documented
methods which can be used as part of an application-context XSS payload.
Note: In the remainder of this section we assume that HTML forms are used to
communicate the user’s password to the application (a practise which is used by the
majority of all current web applications).
In the case that the adversary is able to inject a malicious script into the page which
displays the original authentication dialogue (i.e., the web page that contains the HTML
form in which the username and password are initially entered), the attacker has several
options to obtain the user’s password in clear text.
From a technical point of view, the HTML password field is nothing else but an ordinary
text input field which does not echo the entered characters back to the screen. The
entered values are kept in clear-text and can be read by JavaScript via the page’s DOM
tree. Therefore, if an adversary is able to insert a JavaScript into the login-page, this
script can intercept the form submission (using an onsubmit-eventhandler) in order to
read the password before it is submitted [232, 105] (see Listing 4.2).
1 < script >
2 function leakData (){
3
4 var data = document . ge tEl em en tBy Id ( ’ username ’). value +
5 ’: ’ + document . get El em ent By Id ( ’ password ’). value ;
6 var url = ’ http :// attacker . org / log ? data = ’ + escape ( data );
7 var img = document . createElement ( ’ img ’);
8 img . setAttribute ( ’ src ’ , url );
9 img . style . height = ’0 ’;
10 img . style . width = ’0 ’;
11 document . g e t E l e m e n t s B y T a g N a m e ( ’ body ’)[0]. appendChild ( img );
12
13 /*
14 ** Delay the submit () for so that the leaking HTTP request succeeds reliably
15 */
16 window . setTimeout ( function (){
17 document . g et Ele me nt By Id ( ’ loginform ’). submit ();
18 } , 100);
19
20 return false ;
21 }
22
23 document . g et El eme nt By Id ( ’ loginform ’). onsubmit = leakData ;
24 </ script >
67
4. XSS Payloads: Application Context
Instead of retrieving the password via JavaScript methods as discussed above, the ad-
versary could alternatively create a man-in-the-middle situation by altering the tar-
get address of the authentication form [105]. To do so, only the action-value of the
respective form-tag has to be changed to an attacker-controlled location (e.g., http:
//attacker.org/logpasswd.cgi). When the victim submits the authentication from,
the resulting HTTP request, containing the authentication information in clear-text, is
sent to this manipulated URL. After logging the data, the attacker is able to redirect
the browser back to the original target of the authentication form using a 30x HTTP
response. On sufficient fast connections, this redirection step is fast enough to happen
unnoticed by the user.
In situations where the original authentication form was delivered using SSL via an
https-URL, some browsers display a warning that the secure connection is left. However,
[230] indicates that users are quick to dismiss such a warning.
68
4.2. Password theft
Phishing [52, 159, 197, 276] is a related threat which aims to obtain passwords from
users by spoofing the complete user interface of the targeted web application. Phishing
is a class of attacks which is independent from JSDAs and XSS, and therefore, out of
the scope of this thesis.
69
4. XSS Payloads: Application Context
70
5. XSS Payloads: Browser and Computer
Context
This chapter discusses notable, previously disclosed XSS Payloads which are located
within the browser and computer execution-context.
We discuss these two execution-contexts (browser and computer) jointly in one chapter
because most of the applicable attacks in these contexts share an important character-
istic: They allow targeted attacks which aim at one specific user. A given browser runs
on one specific computer and is used by one specific user. Thus, both the mappings,
user-to-computer and user-to-browser, are static (i.e., a given browser/computer is only
used by one specific person). Especially, the privacy attacks discussed in Section 5.2
are closely related in both execution-contexts. Opposed to this, the attacks discussed
in Chapter 4 are more narrowly focused on one specific application, while the attacks
discussed in Chapter 6 target whole network segments.
71
5. XSS Payloads: Browser and Computer Context
Furthermore, besides the creation of such cross-domain request a script also can obtain
certain information concerning the outcome of this action using the BRA-technique (see
Sec. 3.3.3 for details).
As motivated above, Cross-Site Request Forgery (CSRF / XSRF) [27, 68] a.k.a. Ses-
sion Riding [234, 133] a.k.a Sea Surf [207] is a client-side attack on web applications
that uses indirect communication to exploit browser-level authentication tracking mech-
anisms (see Sec. 1.2.1). More precisely, CSRF uses the cross-domain, cross-application
and cross-protocol capabilities provided by indirect communication to trigger authenti-
cated, state-changing actions on the attacked web application.
The actual attack is executed by causing the victim’s web browser to create HTTP
requests to restricted resources. As introduced above, this can be achieved e.g., by
including hidden images in harmless appearing webpages. The image itself references a
state changing URL of a remote web application.
As the targeted web application employs an browser-level authentication tracking
mechanism, the browser provides such requests with authentication information auto-
matically without any user interaction. Therefore, the target of the request is accessed
with the privileges of the person that is currently using the attacked browser. See [234],
[27], [133] and [68] for further details.
Example: A (rather careless) site for online banking provides an HTML form to place
credit transfers. This form uses the GET method and has the action URL http://bank.
com/transfer.ext. The form is only accessible by properly authenticated users, employ-
ing one of the techniques described above. If an attacker is able to trick a victim’s browser
to request the URL http://bank.com/transfer.cgi?amount=10&an=007, while the
victim’s browser maintains an authenticated state for the banking site, the owner of the
account with the number 007 might gain e 10. To execute the attack the attacker manu-
factures a harmless appearing webpage. In this webpage the attacker includes HTML or
Javascript elements, that cause the victims web browser to request the malicious URL.
This can be done for example with a hidden image:
1 < img src =" http :// bank . com / transfer . cgi ? amount =10& an =007" >
If the attacker successfully lures the victim to visit the malicious website, the attack can
succeed (see Figure 5.1).
72
5.1. Cross-Site Request Forgery
XSRF / Session Riding (II)
www.bank.com www.attacker.org
GET transfer.cgi?am=10000&an=3422421
Cookie: auth_ok
to the attack and the workflow does not employ a separate mechanism to track the
workflow’s progress (i.e. a request ID) but uses the implicitly communicated session
identifier. If these conditions are satisfied an attacker can create in most cases a series of
hidden iframes that host malicious web forms. These forms are automatically submitted
sequentially via JavaScript using the iframe’s onload-events, thus simulating a user that
fills in the forms in their proper order.
73
5. XSS Payloads: Browser and Computer Context
arbitrary digg.com-stories in the name of the attacked user. This was discovered by an
anonymous person [54] who calls himself “Digger”. “Digger” created a web-page which
contained an introduction to CSRF. Furthermore, the web-page also contained a small
JavaScript which exploited the digg.com-CSRF vulnerability. This script voted for a
story submitted by “Digger” which contained a back-link to the exploit-page.
Every digg.com user that read the story and followed the link to “Digger”’s page
involuntarily voted for the story, thus, promoting it further up in the digg.com hierarchy,
which in turn generated more interest and visits by digg.com users. The story reached
digg.com’s frontpage within a day.
Netflix
Wordpress
Wordpress [177] is a blogging software written in PHP. The look and feel of a Wordpress
weblog is determined by the ”theme” of the blog. Such a theme itself consists of several
template files which in turn are either HTML- or PHP-files. To edit these templates
Wordpress provides an web interface.
Some versions of Wordpress were susceptible to CSRF targeting the software’s theme-
editor [126] allowing the adversary to alter the weblog’s template files. As Wordpress
themes may contain executable PHP code, using this attack the adversary was able
add arbitrary PHP code to the weblog’s theme. Consequently, this injected code was
executed every time the weblog was accessed. Hence, the vulnerability enabled the
adversary to execute arbitrary commands on the blog’s server with the privileges of the
web-server process.
74
5.2. Fingerprinting and privacy attacks
While in some cases such attacks are targeted directly at the user’s privacy, the ad-
versary might also use his findings to identify existing vulnerabilities in order to decide
on the next step in his attack.
75
5. XSS Payloads: Browser and Computer Context
Usage of JavaScript to execute this attack provides several advantages for the adver-
sary: The malicious JavaScript can construct the list of hyperlinks dynamically. This
allows more targeted, incremental attacks. Furthermore, only a rather simple style-sheet
defining two separate styles is required. This eliminates the need for a list of unique se-
lectors, thus reducing the attack-code significantly.
1 < style >
2 a : visited { color : rgb (0 ,0 ,255) }
3 </ style >
4
5 <a id =" ebay " href =" http :// www . ebay . com " > </a >
6
7 < script >
8 var link = document . ge tEl em en tBy Id ( ’ ebay ’);
9 var color = document . defaultView . g e t C o m p u t e d S t y l e ( link , null )
10 . g e t P r o p e r t y V a l u e (" color ");
11 if ( color == " rgb (0 , 0 , 255)") {
12 // found
13 }
14 </ script >
Felten et al. [70] documented in 2000 how attackers can initiate timing attacks to
determine if a given web browser has visited a certain web page in the recent past. For
this purpose, the adversary employs cacheable web-objects such as static images and
measures the time it takes to retrieve a given object.
For example the attacker wants to know whether the victim has been to http://
company.com recently. For this purpose, the malicious script stealthily embeds the logo
of the targeted site (http://company.com/logo.jpg) into its DOM tree, causing the
web browser to request the image. Before its actual inclusion in the web page, the
image-element is outfitted with an onload-eventhandler to measure the time that the
inclusion process takes. If the victim has been to the respective site in the last days, the
image is still in the browser’s cache, resulting in a very short loading time. If not, the
image has to be retrieved over the internet, causing a significant longer loading process.
76
5.2. Fingerprinting and privacy attacks
By measuring and matching the loading time against a certain threshold the attacker
can conclude if the image is in the browser’s cache and, thus, whether the victim has
been to the targeted web site.
77
5. XSS Payloads: Browser and Computer Context
Using a variation of the BRA, Grossman [86] discussed a method to disclose whether the
web browser possesses valid authentication credentials (for instance session cookies or
http-authentication information) for a given web application: The basis of the attack is
to test a browser’s capability to load a web page that is only accessible to authenticated
users.
The attack utilises advanced error-handling which is provided by modern JavaScript
interpreters. In the case of an error within a JavaScript, the window.onerror-event
provides limited access to the JavaScript error-console by communicating a short error-
message, the URL of the triggering script, and a numeric error code. This additional
information can be employed for fingerprinting purposes. By attempting to load an
HTML page into a script-tag by using the page’s URL in the tag’s src-attribute,
inevitably a JavaScript parsing error is triggered, as the included data is HTML-code
and cannot be parsed by the JavaScript interpreter. Furthermore, depending on the
authenticated state of the requesting entity, a web application responds to a request for
a restricted resource with different HTML content (either with the requested page or
alternatively with an error page / a login form). In many cases different HTML code
leads to distinct parsing errors. Therefore, a malicious script can, by intercepting the
error-code and messages, differentiate between parse errors triggered by either response
and, thus, determining whether the browser’s user is currently logged into the application
(see Listing 5.3).
1 < script >
2 function err ( msg , url , code ) {
3 if (( msg == " missing } in XML expression " ) && ( code == 1)) {
4 // logged in
5 } else if (( msg == " syntax error " ) && ( code == 3)) {
6 // not logged in
7 }
8 }
9 window . onerror = err ;
10 </ script >
11
12 < script src =" http :// webapp . org " > </ script >
In addition, Robert Hansen discussed accessing restricted images for the same purpose
[97]. Some web applications grant or deny access to resources like images depending on
the user’s authenticated state. By employing the BRA to verify whether the images are
accessible or not, the malicious script can conclude if the user is currently logged into
the application.
78
5.2. Fingerprinting and privacy attacks
Finally, Chess et al. documented in [37] how the responses of cross-domain requests
for JSON-data [48] which were generated using the script-tag can be obtained by
overwriting global JavaScript prototypes.
• establish which software is installed on the local machine using res-URLs [179],
• and check the existence of local files using the file-handler [238]
79
5. XSS Payloads: Browser and Computer Context
80
6. XSS Payloads: Intranet and Internet
Context
This chapter documents JSDAs which are located within the intranet and internet
execution-contexts. We combine the two contexts in one chapter as the adversary’s
capabilities and limitations are very similar in both execution-contexts (see Sec. 3.4).
81
6. XSS Payloads: Intranet and Internet Context
plications often remain unpatched even though well known security problems may exist
and home-grown applications are often not audited for security problems thoroughly.
1. The script constructs a local HTTP URL that contains the IP-address and the
port that shall be scanned.
2. Then the script includes an element in the webpage that is addressed by this URL.
Such elements can be e.g., images, iframes or remote scripts.
82
6.1. Intranet reconnaissance and exploitation
Limitation: Some browsers like Firefox enforce a blacklist of forbidden ports [214]
that are not allowed in URLs. In this case JavaScript’s port scanning abilities are limited
to ports that are not on this list. Other browsers like Safari allow access to all ports.
• DNS brute-forcing:
In the case that the execution of Java content is disabled in the attacked web
browser, the adversary can resort to brute-forcing internal DNS names. Robert
Hansen documented in [98] that many companies employ the same DNS server
to resolve both their external and their internal hostnames (see Listing 6.2). The
attacker can either try to obtain the full list of DNS entries using a zone transfer or
83
6. XSS Payloads: Intranet and Internet Context
<img src=“http://10.10.10.10”>
onload()/onerror()/timeout()-events,
Firewall
Possible attacks:
- Ping Sweep
- Port Scan
- Server Fingerprinting
- URL based exploits
Malicious host
1 ...
2 10.0.1.10 intranet . godaddy . com
3 10.210.136.22 internal . iask . com
4 10.25.0.31 intranet . joyo . com
5 10.30.100.238 intranet . shopping . com
6 10.50.11.131 intranet . monster . com ...
7 ...
If the respective company does not leak the internal IP-range through misconfig-
ured DNS servers, the attacker can use the list of known DNS names to test if
the targeted intranet contains hosts that are assigned to one of these names. To
do so, the malicious JavaScript has two options: It can either employ a series of
BRAs using the guessed internal domain names as part of the URL (i.e., testing
if a host assigned to http://intranet exists). Alternatively the script can check
if any of the domain names is contained in the browser’s history using any of the
techniques discussed in Sections 5.2.1, 5.2.1, or 5.2.2. Both methods do not suffice
to directly leak the actual IP-range to the attacker. However, using these meth-
ods the attacker might identify possible targets for further attacks in the intranet.
Furthermore, in certain cases the existence of certain internal domain names pro-
vides strong indications for the employed IP-range. For instance, the home router
“Fritz Box” [13] introduces the domain name fritz.box to the intranet pointing
to the router’s admin interface. By using the BRA to test for http://fritz.box
the attacker is able to learn that a Fritz Box is used in the examined intranet and
based on the knowledge can guess the used IP-range to be equal or close to the
default range used by this specific router (e.g., 192.168.172.0/24).
84
6.1. Intranet reconnaissance and exploitation
After determining available hosts and their open ports, a malicious script can try to use
fingerprinting techniques to get more information about the offered services. Again, the
script has to work around the limitations that are posed by the SOP. Consequently, the
fingerprinting method resembles closely the port-scanning method that was described
above [160, 91].
The basic idea of this technique is to request URLs that are characteristic for a specific
device, server, or application. If such a URL exists, i.e., the request for this URL
succeeds, the script has a strong indication about the technology that is hosted on the
fingerprinted host. For example, the default installation of the Apache web server creates
a directory called “icons” in the document root of the web server. This directory contains
image files that are used by the server’s directory listing functionality. If a script is able
to successfully access such an image for a given IP-address, it can conclude that the
scanned host runs an Apache web server. The same method can be used to identify web
applications, web interfaces of network devices or installed scripting languages (e.g., by
accessing PHP eastereggs).
If during the reconnaissance step the malicious JavaScript encounters a resource that is
protected by HTTP authentication to which the browser not currently possesses valid
credentials, the web browser displays an authentication dialogue. This discloses the
ongoing attack and alarms the victimised browser’s user that something unusual is going
on.
In [63] Esser documented a method that can be employed by the attacker to suppress
such authentication pop-ups. Esser’s technique is based on the creation of malformed
HTTP URLs. If such an URL is sent to the web server, the server identifies the error in
the URL before determining the addressed resource. Therefore, the server does not map
the URL to a hosted resource and does not recognise that a HTTP authentication dia-
logue should have been trigger: Instead of replying with a “401 Authorization Required”
status code, the server responds with “400 Bad Request”. Esser documented two ways to
create such URLs that work with most web servers: Either incomplete URL entities (e.g.,
http://10.10.10.10/%) or overly long URLs (e.g., http://10.10.10.1/AAA...AAA)
that exceed the server’s restrictions on URL size. Using Esser’s method, the adversary
is still able to determine whether the host in question exists. However, determining if
the examined IP hosts a web server and using the fingerprinting technique detailed in
Section 6.1.2 do not work in combination with this evading method, as these techniques
require valid HTTP responses.
Additionally, Esser demonstrated [62] how Firefox’s link-tag can be abused to exe-
cute brute-force attacks on URLs that are protected by HTTP authentication. As the
content that is requested through link-tags is regarded as optional by the browser, the
tag does not initiate authentication pop-ups if it encounters a 401 response. Further-
more, the rendering process of the page halts until the request that was initiated by the
85
6. XSS Payloads: Intranet and Internet Context
86
6.2. DNS rebinding attacks on intranet hosts
Windows 98 box in the cellar is suddenly reachable from the internet. Thus, using
this method the attacker can create conditions for further attacks that are not
limited to the web browser any longer [91].
87
6. XSS Payloads: Intranet and Internet Context
2. After the script has been downloaded, the attacker modifies the DNS answer for
www.attacker.org to 10.10.10.10
3. The malicious script requests a web page from www.attacker.org (e.g via loading
it into an iframe)
4. The web browser again does a DNS lookup request for www.attacker.org, now
resolving to the intranet host at 10.10.10.10
5. The web browser assumes that the domain values of the malicious script and the
intranet server match. Thus, the SOP is satisfied and browser grants the script
unlimited access to the intranet server. (see Figure 6.3.B)
Using this attack, the script can access the server’s content (see Figure 6.3.C). With
this ability the script can execute refined fingerprinting, leak the content to the outside
or locally analyze the content in order to find further security problems.
88
6.2. DNS rebinding attacks on intranet hosts
h*p://a*acker.org/foo.html
10.10.10.10
Firewall
200.200.200.200 = attacker.org
A. Payload delivery
h*p://a*acker.org/index.html
10.10.10.10 = attacker.org
Firewall
a*acker.org == a*acker.org
⇒ The SOP is safisfied
200.200.200.200
10.10.10.10 = attacker.org
Contents of the server
Firewall
a1acker.org == a1acker.org
⇒ The SOP is safisfied
200.200.200.200
C. Information leakage
89
6. XSS Payloads: Intranet and Internet Context
• Java applets and proxies: David Byrne [28] documented that in cases where
the browser and the JVM are configured to use an outbound HTTP proxy, the
JVM can be tricked into pinning the internal IP address:
1. The victim’s web browser tells the proxy to load a web page using the URL
http://attacker.org/index.html.
2. The proxy queries the adversary’s DNS server for the IP address of attacker.
org.
3. The DNS server replies with the server’s address (e.g., 200.200.200.200).
4. The proxy retrieved the web page and passes it on to the browser.
5. The web page contains an embedded Java applet which is hosted at http:
//attacker.org/bad.class.
6. The browser’s rendering engine encounters the applet-element and instanti-
ates the JVM with the applet’s URL.
7. The JVM queries the attacker’s DNS server for attacker.org’s IP address,
bypassing the proxy.
8. The DNS servers replies to this second request with the internal IP address
(e.g., 10.10.10.10), which is pinned by the JVM.
90
6.2. DNS rebinding attacks on intranet hosts
9. Then, the JVM initiates the retrieval of the applet’s code. However, as the
JVM is configured to use the HTTP proxy, the applet itself is requested by
the proxy which still uses the server’s original IP address.
The result of this series of events is that the applet which was retrieved by the proxy
from 200.200.200.200 is pinned by the JVM to 10.10.10.10, thus enabling the
attacker to use it as part of his rebinding attack.
• Cached Java applets: To minimise loading times, the JVM maintains a cache
of previously loaded applets. In this cache the applets are stored accordingly to
the respective HTTP expires-header. In addition to the applet itself, the cache
also contains the applet’s original URL. Only if an applet is requested from the
exact same URL, the cached version of the applet will be used.
Billy K. Rios has documented how this behaviour can be exploited in a multi
session attack [220]: For this method to work, the victim has to be tricked twice
into executing the malicious code. The first time the code solely loads the applet
from attacker.org using the server’s real IP address. This process only serves
the purpose to store the applet in the JVM’s cache. After the applet has been
delivered, the attacker changes the DNS mapping of attacker.org to point to the
targeted internal address. If, in a new browser session, the victim visits again a
page that is controlled by the attacker, the malicious code dynamically includes the
applet in the page using the exact same URL as in the attack’s first step. As the
URL matched the cache entry, the applet is retrieved from the cache. However, as
the cache only contains the URL but not the actual IP address, the JVM queries
the attacker’s DNS server for the IP of attacker.org and consequently pins the
applet to the internal address.
In addition, Rios discussed that the same behaviour might be triggered either
by loading new JVM instances through URL handlers (like picassa://) or by
enforcing the execution of the applet using a different Java version (a capability
that Sun intends to disable in the future) [220].
Attack capabilities provided by Java Java provides full TCP and UDP socket con-
nections to the targeted host. This can be used for, e.g., port-scanning, fingerprinting
of non-HTTP services, or communication using arbitrary protocols. In cases where the
network services of the targeted intranet host are not fully patched, the adversary could
use arbitrary, well known exploits to, e.g., trigger buffer overflow vulnerabilities.
Furthermore, as Rios pointed out [220], the availability of mature Java libraries for
virtually every purpose enables the adversary to easily and quickly create attack code
that targets non-trivial or obscure network services.
91
6. XSS Payloads: Intranet and Internet Context
implements DNS pinning itself. Like Java applets, the Flash player’s scripting language
ActionScript supports low level socket communication, thus extending the adversary’s
capabilities towards binary protocols. Using this capability non-HTTP attacks like full
portscans on the intranet or accessing binary protocols are possible. Using the capa-
bilities, Thai N. Duong [55] demonstrated how to uses a malicious Flash file to run a
TCP socket relay in the victim’s browser. Using a similar approach, Kaminsky [138] was
able to tunnel arbitrary TCP protocols into the internal network. He exemplified this
capability by running Nessus-scans on intranet hosts.
In order to evaluate the attack surface, Jackson et al. ran a Flash 9 advertisement
on a minor advertising network. Within three days they temporarily compromised more
than 25.000 internal networks while paying less than 50 USD [113].
92
6.3. Selected XSS Payloads in the internet context
translation of a page that contains his malicious JavaScript. This way the script runs
on a webpage that belongs to the translation service’s domain. Then the script itself
requests the translation of a page belonging to the target site. As the result of this
translation again is hosted on the service’s domain, the malicious script gains complete
read access to the foreign page. This way, the adversary’s script can spider and analyse
complete web applications. The translation step does not interfere with the scripts pur-
pose, as the adversary is mainly interested in the web site’s structure which is defined
by its HTML markup. This way the script is able to identify potential insertion points
for XSS attacks and evaluate if these points indeed represent vulnerabilities.
As the adversary only uses a hijacked browser and a public available internet service
in his scan, the real source of the vulnerability scan is hidden effectively.
93
6. XSS Payloads: Intranet and Internet Context
94
Part II.
95
Outline
As motivated in Section 3.5, as long as XSS vulnerabilities occur frequently, a second line
of defense is required. Such defensive techniques can be provided by countermeasures
that specifically aim to mitigate the actions of a targeted XSS Payload type.
In this part, we propose novel countermeasures for three selected XSS Payloads types:
Session Hijacking (see Chapter 7), Cross-Site Request Forgery (see Chapter 8), and
attacks against intranet resources (see Chapter 9).
The content of this part pursues several objectives: For one, we aim to advance the
state of the art in respect to mitigating the selected XSS Payload types. Furthermore,
we target to gain insight about the potential shortcomings of the current web applica-
tion paradigm which enable the existence of the examined payload type. Finally, we
demonstrate the usage of our general methodology for systematical design of payload
specific mitigation strategies (see below).
Methodology
All countermeasures which are proposed in this part have been designed by utilizing
variants of the same general methodology:
97
98
7. Protection Against Session Hijacking
Methodology
The following methodology was utilized to design and implement our countermeasures:
1. First the targeted attacks were analysed systematically to isolate at least one nec-
essary technical requirement for the attack to function as wanted by the attacker.
Such a requirement is characterized by the fact that if the attacker is deprived
of the requirement’s corresponding capability, he cannot successfully execute the
attack any longer. See Table 7.1 for a brief overview of the respective isolated
requirements and Sections 7.2.1 to 7.2.3 for further details.
99
7. Protection Against Session Hijacking
• For one, we store the SID in such a way that malicious JavaScript code bound by
the SOP is not able to access it any longer.
To successfully protect the SID, it has to be kept out of reach for any JavaScript that is
embedded into the webpage. For this reason, we store the SID in a cookie that does not
belong to the webpage’s domain. Instead, the cookie is stored for a different (sub-)domain
that is also under the control of the web application. In the following paragraphs the
main web application will reside on www.example.org, while the cookies will be set for
secure.example.org. The domain secure.example.org is hosted on the same server
as the main web application. Server scripts of the main web application have to be able
to share data and/or communicate with the server scripts on secure.example.org for
this technique to work. On the secure domain only two simple server scripts exist:
getCookie.ext and setCookie.ext. Both are only used to transport the cookie data.
The data that they respond is irrelevant - in the following description they return a
1-by-1 pixel image.
To carry out the deferred loading process we introduce the PageLoader. The PageLoader
is a JavaScript that has the purpose to manage the cookie transport and to load the web-
page’s content. To transport the cookie data from the client to the server it includes an
image with the getCookie.ext script as URL. For setting a cookie it does the same with
100
7.2. Practical session hijacking countermeasures
the setCookie.ext script. To display the webpage’s body the PageLoader requests the
body data using the XMLHttpRequest object. Alternatively iframe or script inclusion
can be employed on older browsers (see Sec. 1.3).
In the following specifications the abbreviations “RQ” and “RP” denote respectively
“HTTP request” and “HTTP response”.
2. The web server replies with a small HTML page that only contains the PageLoader
(RP1).
3. The PageLoader includes the getCookie.ext image in the DOM tree of the web-
page. This causes the client’s web browser to request the image from the server
(RQ2). The cookie containing the SID that is stored for secure.example.org is
included in this request automatically.
4. The PageLoader also requests the webpage’s body using the XMLHttpRequest
object (RQ3). This HTTP request happens parallel to the HTTP request for the
getCookie.ext image.
5. The web server waits with the answer to RQ3 until it has received and processed
the request for the getCookie.ext image. According to the cookie data that this
request contains, the web server is able to compute and send the webpage’s body
(RP2).
6. The PageLoader receives the body of the webpage and uses the document.write
method to display the data.
The web server has to be able to identify that the last two HTTP requests (RQ2 and
RQ3) where initiated by the same PageLoader and therefore came from the same client.
For this reason the PageLoader uses a request ID (RID) that is included in the URLs
of the request RQ2 and RQ3. The RID is used by the web server to synchronize the
request data between the domains www and secure.
Setting a cookie
The usually preceding process of transferring existing cookie data from the client to the
server, as described above, is left out for brevity. With this simplification the setting of
a cookie consists of the following steps (see figure 1.b):
101
7. Protection Against Session Hijacking
2. The web server replies with the PageLoader (RP1) and the PageLoader subse-
quently requests the body data (RQ2).
3. The web server computes the request RQ2. Because of the outcome of the compu-
tation the server decides to place a cookie. The server replies with “SETCOOKIE”
to the PageLoader’s request for the body data (RP2).
4. The PageLoader receives the “SETCOOKIE” token and includes the setCookie.ext
image in the DOM tree of the webpage. This causes the client’s web browser to
request the image from the server (RQ3).
5. The PageLoader also requests the webpage’s body once more (RQ4). This HTTP
request happens parallel to the HTTP request for the setCookie.ext image.
6. The web server receives the request for the image and includes the cookie data in
the response (RP3). The web server marks the RID as “used” (see below).
7. The web server waits with the answer to RQ4 until it successfully delivered the
setCookie.ext image to the client. After the image request has been processed
the body data gets sent (RP4).
102
7.2. Practical session hijacking countermeasures
• It has to be unguessable.
• It must not be stored in an HTML element, e.g. a hidden form field. JavaScript
can access the DOM tree and therefore is able to obtain any information that is
included in the HTML code.
103
7. Protection Against Session Hijacking
• It must not be stored in public JavaScript variables. All JavaScript code in one
webpage exists in the same namespace. Therefore, a malicious script is able to
execute any existing JavaScript function and read any available public variable.
• It must not be hard coded in JavaScript. Every JavaScript element (i.e. object,
function or variable) natively supports the function toString() which per default
returns the source code of the element. Malicious script could use this function to
parse code for embedded information.
• It has to be valid only once. Otherwise, the attacker’s script could use the value
of document.location to emulate the loading process of the displayed page.
Thus, the only place to keep data protected from malicious JavaScript is a private
variable of a JavaScript object (see Sec. 1.3.3). In the following paragraphs we show how
this approach can be implemented. We only describe this implementation in respect of
randomizing hyperlink URLs. The randomization of HTML forms is left out for brevity
- the applicable technique is equivalent.
The go() method uses the function parameter and the object’s private randomization
data to generate a URL that includes a valid rnonce. This URL is immediately assigned
to the global attribute document.location causing the client’s web browser to navigate
to that URL. Listing 1 shows a sketch of the URLRandomizer’s go() function. In this
code “validNonces” is a private hashtable containing the valid randomization data.
1 this . go = function ( path ){
2 var nonce = validNonces [ path ];
3 document . location =
4 " http :// www . example . org /"+ path +"? rnonce ="+ nonce ;
5 }
104
7.2. Practical session hijacking countermeasures
Timing aspects
As mentioned above, the URLRandomizer obtains the valid randomization data from
the server by requesting it via HTTP. This leads to the following requirement: The URL
that is used to get this data also has to be randomized and limited to one time use. It
is furthermore important, that the URLRandomizer object is created early during the
HTML parsing process and that the randomization data is requested on object creation.
Otherwise, malicious JavaScript could examine the source code of the URLRandomizer
to obtain the URL for the randomization data and request it before the legitimate object
does. As long as the definition and creation of the URLRandomizer object is the first
JavaScript code that is encountered in the parsing process, this kind of timing attack
cannot happen.
It has to be ensured that the first webpage, which contains the URLRandomizer object,
was not requested by a potential malicious JavaScript, but by a proper user of the web
application. Therefore, an interactive process that cannot be imitated by a program
is required for the transition. The natural solution for this problem is combining the
changeover to one-time URLs with the web application’s authentication process. In sit-
uations where no authentication takes place CAPTCHA (Completely Automated Public
Turing-Test to Tell Computers and Humans Apart) technology [263] can be employed
for the transition. If no interactive boundary exists between the realms of static and
one-time URLs, a malicious JavaScript would be able to request the URL of the entry
point to the web application and parse its HTML source code. This way the script is
able to acquire the URL that is used by the URLRandomizer to get the randomization
data.
The proposed method poses some restrictions that break common web browser func-
tionality: Because it is forbidden to use a random nonce more than once, the web server
regards every HTTP request that includes an invalidated nonce as a potential security
breach. Depending on the security policy such a request may result in the termina-
tion of the authenticated session. Therefore, every usage of the web browser’s “Back”
or “Reload” buttons pose a problem because these buttons cause the web browser to
reload pages with invalid nonces in their URLs. A web application using one-time URLs
should be verbose about these restrictions and provide appropriate custom “Back” and
“Reload” buttons as part of the application’s GUI. It is also impossible to set bookmarks
for URLs that lie in the randomized area of the web application, as the URL of such
a bookmark would contain an invalid random nonce. Other issues, e.g. the opening of
new browser windows, can be solved using DHTML techniques. Because of the described
restrictions, a limitation on the usage of one-time URLs for only security sensitive parts
of the web application may be recommendable.
105
7. Protection Against Session Hijacking
Alternative solutions
Some of the limitations mentioned above exist because the proposed URLRandomizer
object is implemented in JavaScript. As described above the separation of two different
JavaScript objects running in the same security context is a complex and limited task.
Especially the constraint that a random nonce can be used only once is due to the
described problems. An alternative approach would be using a technology that can be
separated cleanly from potential malicious JavaScript. There are two technologies that
might be suitable candidates: Java applets [250] and Adobe Flash [3]. Both technologies
have characteristics that suggest that they might be suitable for implementing the URL
randomizing functionality: They provide a runtime in the web browser for client side
code which is separated from the JavaScript runtime, they possess interfaces to the web
browser’s controls, they are able to export functionality to JavaScript routines and they
are widely deployed in today’s web browsers. Before implementing such a solution, the
security properties of the two technologies have to be examined closely, especially in
respect of the attacker’s capability to include a malicious Java or Flash object in the
attacked web page.
The underlying fact which is exploited by the attacks described in Section 4.1.3 is,
that webpages with the same origin implicitly trust each other and, thus, can read and
write each others content. Because of this circumstance rogue iframes or background
windows are capable of inserting malicious scripts in pages that would not be vulnerable
otherwise. As years of security research have taught us, implicit trust is seldom a good
idea - instead explicit trust should be the default policy.
Consequently, according to the methodology outlined in Section 7.1, our proposed
countermeasure is to revoke the inter-page read/write capabilities which are inherently
granted to the JavaScript through the implicit trust relationship between the applica-
tion’s individual pages.
To remove this implicit trust between individual webpages that belong to the same web
application, we have to ensure that no trust relationship between these pages induced
by the Same Origin Policy exists: As long as the document.domain property for every
page differs, background XSS propagation attacks are impossible.
To achieve this trust removal, we introduce additional subdomains to the web applica-
tion. These subdomains are all mapped to the same server scripts. Every link included
into a webpage directs to a URL with a subdomain that differs from the domain of the
containing webpage. For example a webpage loaded from http://s1.www.example.org
only contains links to http://s2.www.example.org. Links from s2.www.example.org
would go to s3.www... and so on. As a result every single page possesses a different
document.domain value. In cases where a page A explicitly wants to create a trust rela-
tionship to a second page B, pages A and B can change their document.domain setting
to exclude the additional subdomain.
106
7.3. Discussion
Implementation aspects
The implementation of the subdomains is highly dependent on the application server
used. For our implementation we used the Apache web server [167] which allows the us-
age of wildcards in the definition of subdomain names. Consequently, we had unlimited
supply of applicable subdomain names. This allows the choice between random subdo-
main names or incrementing the subdomain identifier (s0001.www links to s0002.www
which links to s0003.www and so on). On application servers that do not offer such an
option and where, therefore, the number of available subdomain names is limited, the
web application has to be examined closely. It has to be determined how many sub-
domains are required and how the mapping between URLs and subdomains should be
implemented. These decisions are specific for each respective web application.
7.3. Discussion
7.3.1. Combination of the methods
Before implementing the countermeasures described in Section 7.2, the web application’s
security requirements and environment limitations have to be examined. A combination
of all three proposed methods provides complete protection against all known session
hijacking attacks:
• The Deferred Loading Process prevents the unauthorized transmission of SID in-
formation, thus, reliably stops SID theft attacks.
• Subdomain Switching limits the impact of XSS vulnerabilities to only the vulner-
able pages. Therefore, the propagation of a malicious script from one web page to
the next is impossible.
Furthermore Browser Hijacking attacks that rely on the attacker’s capability to
access the content of the attack’s HTTP responses are also prevented as the XML-
HttpRequest object is bound by the Same Origin Policy: With Subdomain Switch-
ing in effect the attacking script would have to employ iframe or image inclusion
to create the attack’s HTTP request.
107
7. Protection Against Session Hijacking
• Finally, One-Time URLs prevent all browser hijacking attacks as the adversary’s
script is not able to address valid URL-based resources of the application anymore.
7.3.2. Limitations
As shown above, a combination of the countermeasures protects against the session hi-
jacking attacks described in Section 4.1. However, on the actual vulnerable page in which
the XSS code is included, the script still has some capabilities, e.g altering the page’s
appearance or redirecting form actions. Thus, especially webpages that include HTML
forms should be inspected thoroughly for potential weaknesses even if the described
techniques were implemented.
The described techniques are not meant to replace input checking and output sanita-
tion completely. They rather provide an additional layer of protection to mitigate the
consequences of occurring XSS vulnerabilities.
Deferred Loading
There are no dependencies between the deferred loading process and the content of
the application’s webpages. Therefore, a transparent implementation of this method is
feasible. It can be realized using an HTTP proxy positioned before the server scripts:
The proxy intercepts all incoming and outgoing HTTP messages. Prior to transferring
the request to the actual server scripts, the “get cookie” process is executed (see figure
7.2). Before sending the HTTP response to the client, all included cookies are stripped
from the response and send to the client via the “set cookie” process.
108
7.3. Discussion
pose no special challenge, prior existing JavaScript may be harder to deal with. All
JavaScript functions that assign values to document.location or open new windows
have to be located and modified. Also all existing onclick and onsubmit events have
to be rewritten. Furthermore, HTML code might include external referenced JavaScript
libraries, which have to be processed as well. Because of these problems, a web appli-
cation that is protected by such a solution has to be examined and tested thoroughly.
Therefore, an implementation of the proposed methods as a library for hyperlink and
form creation is preferable.
109
7. Protection Against Session Hijacking
C = d(Ce , Ka )
Within the browser only the encrypted cookie is known, therefore only the en-
crypted data is accessible to the attacker via JavaScript. As the attacker does not
possess Ke , he cannot obtain a valid SID.
• Within the Browser: If the countermeasure is implemented directly within the
web browser, the actual JavaScript engine can be modified to surpress access to
cookie values, as it is enforced by HTTP-only cookies1 [193].
7.4. Conclusion
In this chapter we presented three complementary protection techniques against XSS
session hijacking attacks. A combination of the three methods successfully prevents all
currently known attacks of this specific attack class.
To achieve this, we classified currently known methods for session hijacking (see
Sec. 4.1). Through a systematic examination of the resulting attack classes, we identified
the basic requirements for each of these attack methodologies: SID accessibility in the
case of Session ID Theft, prior knowledge of URLs in the case of Browser Hijacking and
implicit trust between webpages in the case of Background XSS Propagation.
Based on our analysis of the JavaScript language and the web application paradigm
(see Chapter 1) we isolated the two instruments provided by the web browser architecture
that can be used to enforce access restrictions in connection with JavaScript: The SOP
(see Sec. 1.3.1) and private members in JavaScript objects (see Sec. 1.3.3).
Using the knowledge gained by the attack classification, we were able to apply these
security mechanisms to remove the attack classes’ foundations: To undermine the SID
accessibility, the SID is kept in a cookie which belongs to a different subdomain than
the main web application. To achieve this, we developed a deferred loading process
which allows to execute the cookie transport while the web page is still in a trustworthy
state. To undermine the pre-knowledge of the application’s URLs, valid One-Time
URLs are hidden inside private members of the URLRandomizer JavaScript object.
Finally, additional subdomains are introduced by Subdomain Switching, in order to
create a separate security domain for every single webpage. This measure employs the
SOP to limit the impact of XSS attacks to the vulnerable pages only. Consequently,
each proposed countermeasure removes the fundamental necessities of one of the attack
classes, hence disabling it reliably. By preventing session hijacking, a large slice of the
attack surface of XSS can be removed.
The proposed countermeasures do not pose limitations on the development of web
applications and only moderate restrictions on web GUI functionality. They can be
1
Please note: At the time of the original publication of the proposed countermeasures in [123], HTTP-
only cookies where supported only by a fraction of available web browsers and practical evasion
techniques existed [84, 154]. Even at the time of writing this thesis, coverage of HTTP-only is
incomplete.
110
7.4. Conclusion
implemented as an integral component of the application server and thus easily be inte-
grated in the development or deployment process.
Protection evaluation: To conclude this chapter, we briefly map the proposed coun-
termeasure’s protection capabilities against our threat classification (see Sec. 3.4). Im-
plementing our countermeasures provides complete protection against the threats
Furthermore, the severity of the threats A.1.c.2 and A.1.c.3 (leaking of passwords and
sensitive information) is reduced significantly because the XSS attack is limited to only
the vulnerable pages which not necessarily contain the targeted information.
111
7. Protection Against Session Hijacking
112
8. Protection Against Cross-Site Request
Forgery
8.1. Motivation
As discussed in Section 5.1, CSRF is a JSDA located within the browser execution-
context. For a CSRF attack to succeed, the targeted web site has to expose a common
flaw in its authentication tracking mechanism: The failure to discard or detect unso-
licited, cross-domain requests which possess elevated access rights due to browser-level
authentication tracking mechanisms (see Sec. 1.2.1 and 5.1.1).
In this chapter, we propose a client-side solution to enable security conscious users
to protect themselves against such CSRF attacks. The proposed countermeasure was
originally published in [133].
• Accepting only HTTP POST requests: A frequent assumption is, that a web
application which only accepts form data from HTTP POST request is protected
against CSRF, as the popular attack method of using img-tags only creates HTTP
GET requests.
This is not true: To create hidden POST requests, invisible frames or iframes can
be employed: In a hidden frame, which is included in the malicious site, a webpage
containing an HTML form is loaded. This form’s method is set to “POST” and its
action-attribute targets a resource of the attacked web application. The form’s
elements are set to default values which enable the intended attack. Furthermore,
113
8. Protection Against Cross-Site Request Forgery
the frame contains a JavaScript which automatically submits the form after the
frame has been loaded, thus initiating a hidden HTTP POST request.
This method requires JavaScript to be enabled for the attacked site within the
victim’s web browser. In situations where JavaScript is not enabled, the attacker
might try to convince the victim to click on a certain area of the malicious page,
thus submitting the form. This attack variant might be rather brute and de-
tectable, as now the attacking frame has to be visible.
• Referrer checking: An HTTP request’s referrer [74] indicates the URL of the
webpage that contained the HTML link or form that was responsible for the re-
quest’s creation. The referrer is communicated via the HTTP Referer-header
field.
Therefore, in theory, to protect against CSRF, a web application could check if a
request’s referrer matches the web application’s domain. If this is not the case, the
request could be rejected.
However, some users prohibit their web browsers to send referrer information be-
cause of privacy concerns. For this reason, web applications have to accept re-
quests, that do not carry referrer information. Otherwise they would exclude a
certain percentage of potential users from their services. It is possible for an at-
tacker to reliably create referrerless requests (see below). Consequently, any web
application that accepts requests without referrers cannot rely on referrer checking
as protection against CSRF.
In the course of our research, we conducted an investigation on the different possi-
bilities to create HTTP requests without referrers in a victim’s browser. We found
three different methods to create hidden request that do not produce referrers.
Depending on the web browser the victim uses, one or more of these methods are
applicable by the attacker.
1. Page refresh via meta-tag: This method employs the “HTTP-EQUIV = Re-
fresh” meta-tag. The tag specifies an URL and a timeout value. If such a tag
is found in the head-section of an HTML document, the browser loads the
URL after the given time. Example:
1 < META HTTP - EQUIV = Refresh CONTENT ="0; URL = http :// path \ _to \ _victim " >
On some web browsers the HTTP GET request, which is generated to retrieve
the specified URL, does not include a referrer. It is not possible to create a
POST request this way.
2. Dynamically filled frame: To generate hidden POST requests, the attacker
can use an HTML form with proper default values and submit it automati-
cally with JavaScript. To hide the form’s submission the form is created in
an invisible frame. As long as the src-attribute of the frame has not been
assigned a value, the referring domain value stays empty. Therefore, the form
114
8.2. Current defence
To examine the effectiveness of the described methods, we tested them with com-
mon web browsers. See Table 8.1 for the results of our investigation. The only
web browser that was resistant to our attempts was Opera.
• Using random form tokens: To prevent CSRF attacks, a web application has to
make sure that incoming form data originated from a valid HTML form. “Valid”
in this context denotes the fact that the submitted HTML form was generated by
the actual web application in the first place. It also has to be ensured that the
HTML form was generated especially for the submitting client. To enforce these
requirements, hidden form elements with random values can be employed. These
values are used as one-time tokens: The triplet consisting of the form’s action URL,
the ID of the client (e.g the session ID) and the random form token are stored by
the web application. Whenever form data is submitted, the web application checks
if this data contains a known form token which was stored for the submitting client.
If no such token can be found, the form data has been generated by a foreign form
and consequently the request will be denied. See [234] for a similar approach.
• Using application-level authentication: As discussed in Section 1.2.2, there
are methods to communicate the user’s authenticated state explicitly: Authenti-
cation tokens can be included into the web application’s URLs or transported via
115
8. Protection Against Cross-Site Request Forgery
hidden fields in HTML forms. These techniques are resistant to CSRF attacks,
because to create an authenticated, cross-domain request the adversary would be
required to know the authentication credential which has to be added explicitly
to the request. As the credential is kept secret by the application, the attacker
cannot create such a request.
However, as outlined in Section 1.2, the existing methods for application-level au-
thentication tracking have serious drawbacks, either in security or usability. Solely
relying on such mechanisms is therefore not advisable. But a combination of
browser-level and application-level authentication would be feasible and secure.
E.g., the authentication credential could be split in two parts, one part communi-
cated implicitly via the Cookie-header and the other part explicitly added as an
URL parameter.
Methodology
To design the countermeasure, we used a methodology similar to the one discussed in
Section 7.1. We analysed the class of CSRF attacks systematically to isolate at least one
necessary technical requirement for the attack to function as wanted by the attacker.
Then we investigated methods to withdraw this capability from the attacker without
disturbing the actual web application.
For CSRF-attacks to function, the adversary has to be able to create HTTP requests
within the attacked web browser which are automatically outfitted with authentication
credentials via browser-level authentication tracking. Therefore, if the countermeasure
successfully stops the automatic adding of authentication credentials to cross-domain
requests, the attack is not possible anymore.
Overview
As motivated above, our solution disables the automatism that causes the sending of
the authentication data. For this purpose, we introduce a client-side mechanism which
observes and modifies the HTTP traffic between browser and web sever. This mechanism
identifies HTTP requests which qualify as potential CSRF attacks and strips them from
all possible authentication credentials.
In the remainder of this chapter we describe our solution in form of a client-side proxy.
We chose to implement our solution in form of such a proxy instead of integrating it
directly into web browser technology, because this approach enables CSRF protection
116
8.3. Concept overview and methodology
for all common web browsers, thus, lowering the deployment effort and encouraging wide
usage.
• the URLs of the originating page and the requested page satisfy the SOP. This
means that the protocol, port and domain of the two URLs have to match.
Only requests that were identified to be entitled are permitted to carry browser-level
authentication tracking information.
This means, that only HTTP requests are trusted to carry browser-level authentication
tracking information which originated from a webpage that belongs to the same web
application as the target of the request.
To determine if a request can be classified as entitled, the proxy intercepts every HTTP
response and augments the response’s HTML content: Every HTML form, link and other
means of initiating HTTP requests is extended with a random URL token. Furthermore,
the tuple consisting of the token and the response’s URL is stored by the proxy for future
reference. From now on, this token allows the proxy to match outgoing HTTP requests
with prior HTTP responses. Every request is examined whether it contains a URL token.
If such a token can be found, the proxy compares the token value to the values which
have been used for augmenting prior HTTP responses. This way the proxy is able to
determine the URL of the originating HTML page. By comparing it with the request’s
URL, the proxy can decide if the criteria defined in Definition 8.1 are met. If this is not
the case, all browser-level authentication information is removed from the request.
117
8. Protection Against Cross-Site Request Forgery
either by removing the Cookie header field or by ignoring the Authorization field
and requesting a reauthentication before passing the request on to the server.
Following the triggered reauthentication process, all further requests will be entitled
as they originated from a page that belongs to the web application (beginning with
the webpage that executed the reauthentication).
• Client side SSL authentication: Our proxy-based solution is not yet able to
prevent CSRF attacks that exploit client-side SSL authentication. This is a gen-
eral shortcoming of proxy-based solutions, as the SSL was specifically designed
to prevent man-in-the-middle situations. This short coming can be solved by im-
plementing the countermeasure directly into the browser (as outlined in Section
8.4.2).
8.4. Implementation
8.4.1. Implementation as a client side proxy
We implemented a proof of concept of our approach using the Python programming
language with the Twisted [73] framework. Free Python interpreters exist for all major
operating systems. Thus, using our solution should be possible in most scenarios. Our
implementation is named “RequestRodeo”. In the next paragraphs we discuss special
issues that had to be addressed in order to enforce the solution outlined in Section 8.3.
The process of adding the random tokens to a webpage’s URLs is straight forward: The
proxy intercepts the server’s HTTP response and scans the HTML content for URLs.
Every URL receives an additional GET parameter called rrt (for “RequestRodeoTo-
ken”). Furthermore, JavaScript code that may initiate HTTP requests is altered: The
proxy appends a JavaScript function called addToken() to the webpage’s script code.
This function assumes that its parameter is an URL and adds the GET token to this
URL. Example: The JavaScript code
1 document . location = someVariable ;
is transformed to
1 document . location = addToken ( someVariable );
This alteration of URLs that are processed by JavaScript is done dynamically because
such URLs are often assembled on script execution and are therefore hard to identify
reliably otherwise.
118
8.4. Implementation
1. The proxy sends a “302 temporary moved” response message. As target URL
of this response the proxy sets the original request’s URL with an added
unique token.
2. The client receives the “temporary moved” response and consequently re-
quests the URL that was provided by the response.
3. The URL token enables the proxy to identify the request. The proxy ig-
nores the Authorization header and immediately replies with a “401 Unau-
thorized” message, causing the client browser to prompt the user for user-
name and password. Furthermore, the proxy assigns the status entitled to
the URL/token combination.
4. After receiving the authentication information from the user, the client re-
sends the request with the freshly entered credentials.
5. As the request now has the status entitled, the proxy passes it on to the server.
119
8. Protection Against Cross-Site Request Forgery
8.5. Discussion
As described above our solution identifies HTTP requests that pose potential CSRF at-
tacks. For these requests the browser-level authentication processes are disabled. With
120
8.5. Discussion
the exception of intercepting requests for intranet resources, the HTTP request them-
selves are not prevented, only the authentication information is removed. For this reason
our solution interferes as little as possible with the usage of web based applications.
For instance, if a web application provides additionally to the restricted resources
also pubic content, this public content can be referenced by outside webpages without
the interference of the proxy. The requests for these public items may initially contain
authentication credentials, which are subsequently removed by the proxy. But this
removal does not influence the server’s response, as no authentication was required in
the first place.
With the single exception of local attacks (see below), the in Section 5.1.1 described
CSRF attacks are prevented reliably, as all HTTP requests originating from an attacker’s
website or from outside the web browser (e.g. from an email application) are identified
as not being entitled
8.5.1. Limitations
We identified the following limitations in respect to our proposed solution:
”local” attacks: Our solution cannot protect from “local” CSRF attacks. With local
CSRF attacks we denote attacks that have their origin on the attacked web application.
If, for instance, an application allows its users to post images to one of the application’s
webpages, a malicious user may be able to use the image’s URL-attribute to launch a
CSRF attack. Our proxy would consider the image request as entitled as the image is
referenced by a webpage that belongs to the application.
False positives due to incorrect JavaScript parsing: Some webpages use JavaScript
to create parts of the page’s HTML code locally. As Javascript is a highly dynamic
language, our current implementation may fail in some cases to correctly classify all
included URLs as entitled.
As the proxy strips authentication credentials from such requests, the CSRF protec-
tion remains intact. However, depending on the significance of the request’s purpose,
malfunctions of the application may occur. This limitation is a purely technical one,
which could be solved with a source-to-source JavaScript translator such as Google’s
CAJA project [188].
Usability: We designed our solution to interfere as little as possible with a user’s brows-
ing. The most notably inconvenience that occurs by using the proxy is the absence of
auto login: Some web applications allow the setting of a long lived authentication cookie.
As long as such a cookie exists, the user is not required to authenticate. In almost every
case, the first request for a web application’s resource is not entitled, as it is caused either
by entering the URL manually, selecting a bookmark or via a web page that does not be-
long to the application’s domain. For this reason, the proxy removes the authentication
cookie from the request, thus preventing the automatic login process.
121
8. Protection Against Cross-Site Request Forgery
8.6. Conclusion
In this chapter we presented RequestRodeo, a client side solution against CSRF attacks.
Our solution works as a local HTTP proxy on the user’s computer. RequestRodeo iden-
tifies HTTP requests that are suspicious to be CSRF attacks. This is done by marking
all incoming and outgoing URLs. Only requests for which the origin and the target
match, are allowed to carry authentication credentials that were added by automatic
mechanisms. From suspicious requests all authentication information is removed, thus
preventing the potential attack. By implementing the described countermeasures Re-
questRodeo protects users of web applications reliably against almost all CSRF attack
vectors that are currently known.
A further result of this chapter is the conclusion that current browser technology
does not provide suitable means for tracking and communicating authentication infor-
mation during an application’s usage session. All browser-level authentication tracking
mechanisms (see Sec. 1.2.1) are susceptible to CSRF attacks and all application-level
authentication tracking techniques are either susceptible to SID-leakage, in the case of
URL parameters, or pose problems during implementation and usage, in the case of
hidden form fields (see Sec. 1.2.2).
122
8.6. Conclusion
Protection evaluation: To conclude this chapter, we briefly map the proposed counter-
measure’s protection capabilities against our threat classification (see Sec. 3.4). Usage
of our countermeasure results in full protection against the following threats:
123
8. Protection Against Cross-Site Request Forgery
124
9. Protecting the Intranet Against JSDAs
9.1. Introduction
As documented in Chapter 6, a whole class of JSDAs exist that target resources lo-
cated within the intranet. We discuss several approaches towards protection against the
specified threats.
This chapter focuses on JSDAs that target intranet resources. Therefore, we frequently
have to differentiate between locations that are either within or outside the intranet. For
this reason, in the remainder of the chapter we will use the following naming conventions:
The respective counterparts external IP-address and external URL are defined accord-
ingly.
9.2. Methodology
Analogous to the methodology used in Chapters 7 and 8, we extracted a set of minimal,
technical capabilities on which the attacks rely. Our analysis resulted in a set consisting
of four individual technical requirements:
3. Creation of HTTP requests within the intranet’s boundaries: All discussed attacks
utilize HTTP requests which are created in the victimized browser. As the browser
is within the local intranet, these requests are consequently created within the local
net’s boundaries.
125
9. Protecting the Intranet Against JSDAs
4. Interaction of external web pages with local resources: As in our regarded scenario
the attacker-controlled resources are located outside the intranet’s boundaries (oth-
erwise he would not require the victim’s browser as an attacking device), the initial
malicious payload has necessarily to be received from an external source. Thus, at
least at one point during the attack, an interaction of an external web page with
a local resource has to occur.
Based on this set, we designed and evaluated four specific countermeasures, each
revoking one of these capabilities.
Protection
This solution protects effectively against active content that is hosted on untrusted web
sites. However as discussed in Section 3.2, if an XSS weakness exists on a web page that
is trusted by the user, he is still at risk. Compared to e.g. Buffer Overflows, XSS is a
vulnerability class that is often regarded to be marginal. This is the case especially in
respect to websites that do not provide “serious” services, as an XSS hole in such a site
has only a limited attack surface in respect to causing “real world“ damage. For this
reason, such web sites are frequently not audited thoroughly for XSS problems. Any
XSS hole can be employed to execute the attacks that are subject of this section.
Drawbacks
In addition to the limited protection, an adoption of this protection strategy will result
in significant obstacles in the user’s web browsing. The majority of modern websites re-
quire active client-side technologies to function properly. With the birth of the so-called
126
9.3. Defense strategies
“Web 2.0” phenomenon this trend even increases. The outlined solution would require
a site-specific user-generated decision which client-side technologies should be permitted
whenever a user visits a website for the first time. For this reason the user will be con-
fronted with numerous and regularly occurring configuration dialogues. Furthermore, a
website’s requirements may change in the future. A site that does not employ JavaScript
today, might include mandatory scripts in the future. In the described protection sce-
nario such a change would only be noticeable due to the fact that the web application
silently stopped working correctly. The task to determine the reason for this loss of
functionality lies with the user.
• The document containing the element has the same origin as the JavaScript.
Only if these conditions are satisfied the JavaScript
• is allowed to access the element directly and
Jackson et. al describe in [114] a similar approach. In their work they extend the SOP
towards the browser’s history and cache. By doing so, they are able to counter some of
the privacy attacks which have been documented in Section 5.2.1.
Protection
Applying the SOP on an element level would successfully counter attacks that aim
to portscan the intranet or fingerprint internal HTTP-services (see Sec. 6.1.2). These
attacks rely on the fact that events like onerror that are triggered by the inclusion
of local URLs can be received by attacker-provided JavaScript. As the origin of this
JavaScript and the included elements differs, the refined SOP would not be satisfied and
therefore the malicious JavaScript would not be able to obtain any information from the
inclusion attempt. More general, all attacks that rely on the BRA (see Sec. 3.3.3) would
not be successful.
However, refined and targeted fingerprinting attacks may still be feasible. Even if
elements of a different origin are not directly accessible any longer, side effects that
127
9. Protecting the Intranet Against JSDAs
may have been caused by these elements are. E.g., the inclusion of an image causes a
certain shift in the absolute positions of adjacent elements, which in turn could be used
to determine that the image was indeed loaded successfully.
Furthermore, the attacks described in Sections 6.1.3 and 6.1.4 would still be possible.
Such attacks consist of creating a state-changing request to well known URLs, which
would still be allowed by the refined policy.
Also the DNS-rebinding based attack described in Section 6.2 would not be prevented.
The basis of the attack is tricking the browser to believe that the malicious script and
the attacked intranet server share the same origin.
Nonetheless, the feasibility of the remaining attacks depends on detailed knowledge of
the intranet’s internal layout. Due to the fact that obtaining such knowledge is prevented
successfully by the outlined countermeasure, the protection can still be regarded as
sufficient, as long as the attacker has no other information leak at hand.
Drawbacks
The main disadvantage of this approach is its incompatibility to current practices of
many websites. Modern websites provide so-called web APIs that allow the inclusion of
their services into other web applications. Such services are for example offered to enable
the inclusion of external cartography material into webpages. Web APIs are frequently
implemented using remote JavaScripts that are included in the targeted webpage by a
script-tag. If a given browser starts to apply the SOP on an element level, such services
will stop working.
A further obstacle in a potential adoption of this protection approach is the anticipated
development costs, as an implementation would require profound changes in the internals
of the web browser.
128
9.3. Defense strategies
Removal of implicit authentication: IP-based auth. Removal of implicit authentication: IP-based auth.
!
3
RequestRodeo RequestRodeo
1 1
Intranet webserver Intranet webserver
2
OK 2 DENY
Inner Firewall Inner Firewall
DMZ 3 Reflection server DMZ Reflection server
only if it was initiated because of the interaction with a web page and if the URLs of
the originating page and the requested page satisfy the SOP. Only requests that were
identified to be entitled are permitted to carry browser-level authentication information.
According to this definition, all unentitled requests are “cross site requests” and therefore
suspicious to be part of a CSRF attack and should be treated with caution.
Cross-site requests are fairly common and an integral part of the hyperlink-nature
of the WWW. Therefore, a protection measure that requires the cancellation of such
requests is not an option. Instead, we proposed to remove all authentication information
from these requests to counter potential attacks. However, in the given case the requests
do not carry any authentication information. They are implicitly authenticated as their
origin is inside the boundaries that are defined by the firewall. For this reason other
measures have to be taken to protect local servers.
Reflection service
Our proposed solution introduces a reflection service that is positioned on the outer side
of the firewall (see Figure 9.1). All unentitled requests are routed through this server. If
such a request succeeds, we can be sure that the target of the request is reachable from
the outside. Such a target is therefore not specifically protected by the firewall and the
request is therefore permissible.
The method that is used to do the actual classification is out of scope of this Chapter.
In Chapter 8 we introduced a client-side proxy mechanism for this purpose, though
ultimately we believe such a classification should be done within the web browser.
Example: As depict in figure 9.1.A a web browser requests a webpage from a server
that is positioned outside the local intranet. In our scenario the request is unentitled. It
is therefore routed through the reflection service. As the reflection service can access the
server unhindered, the browser is allowed to pose the request and receives the webpage’s
data. The delivered webpage contains a malicious script that tries to request a resource
129
9. Protecting the Intranet Against JSDAs
from an intranet web server (see figure 9.1.B). As this is a cross domain request, it also
is unentitled and therefore routed through the reflection service as well. The reflection
service is not able to successfully request the resource, as the target of the request lies
inside the intranet. The reflection service therefore returns a warning message which is
displayed by the web browser.
Protection
The attack methods described in Sections 6.1.2 to 6.1.4 rely on executing a JavaScript
that was obtained from a domain which is under (at least partial) control of the attacker.
In the course of the attack, the JavaScript creates HTTP requests that are targeted to
local resources. As the domain-value for local resources differs from the domain-value
of the website that contains the malicious script, all these requests are detected to be
cross-site request. For this reason, they are classified as unentiteld. Consequently, these
requests are routed through the reflection service and thus blocked by the firewall (see
Figure 9.1).
Therefore, the usage of a reflection service protects effectively against malicious JavaScript
that tries to either port-scan the intranet (see Sec. 6.1.2), fingerprint local servers (Sec-
tion 6.1.2) or exploit unpatched vulnerabilities by sending state changing requests (Sec-
tions 6.1.3 and 6.1.4).
The main problem with this approach is its incapability to protect against attacks
that exploit the breaking of the web browser’s DNS pinning feature (see Sec. 6.2). Such
attacks are based on tricking the browser to access local resources using an attacker pro-
vided domain-name (e.g., attacker.org). Because of this attack method, all malicious
requests exist within that domain and are not recognised to be suspicious. Thus, these
requests are not routed through the reflection service and can still execute the intended
attack. As long as web browsers are used which may be susceptible to DNS rebinding
attacks, the protection provided by this approach is not complete. However, executing
such an attack successfully requires detailed knowledge on the particular properties of the
attacked intranet. As obtaining knowledge about the intranet is successfully prevented
by the countermeasure, the feasibility of DNS rebinding based attacks is questionable.
Drawbacks
Setting up such a protection mechanism is comparatively complex. Two dedicated com-
ponents have to be introduced: The reflection service and an add-on to the web browser
that is responsible for classification and routing of the HTTP requests. Furthermore, a
130
9.3. Defense strategies
4. Restricted local network (local origin) 4. Restricted local network (remote origin)
Firewall Firewall
suitable network location for the reflection service has to exist. As small-scale and home
networks rarely contain a DMZ, the user either has the choice of creating one, which
requires certain amounts of networking knowledge, or to position the reflection service
outside the local network, which is objectionable.
The most appropriate deployment scenario for the proposed protection approach is as
follows: Many companies already require their employees to use an outbound proxy for
WWW-access. In such cases, the classification engine that is responsible for routing non-
trusted requests through the reflection service could be included in the existing central
proxy. This way all employees are transparently using the protection measure without
additional configuration effort.
Definition 9.2 (restricted local network) Hosts that are located inside a restricted
local network are only accessible by requests that have a local origin. Therefore, inside
such a network all HTTP requests with an external origin that target at a local resource
are forbidden.
With requests with an external origin we denote requests that were generated in the
execution context of a webpage that was received from an external host. Unlike the
proposed solution in Section 9.3.3 this classification does not take the domain-value of
the request’s origin or target into account. Only the actual IP-addresses are crucial for
a policy-based decision.
131
9. Protecting the Intranet Against JSDAs
Protection
All the attack methods specified in Sections 6.1 and 6.2 depend on the capability of
the malicious script to access local elements in the context of a webpage that is under
the control of the attacker: The portscanning attack uses elements with local URLs to
determine if a given host listens on the URL’s port, the fingerprinting and local CSRF
methods create local URLs based on prior application knowledge, breaking DNS-pinning
tries to let the browser believe that an attacker owned domain is mapped to a local IP-
address. Therefore, the attacker’s ability to successfully launch one of the specified
attacks depends on his capability to create local HTTP requests from within a webpage
under his control. By definition the attacker’s host is located outside the intranet.
Thus, the starting point of the attack is external. As the proposed countermeasure
cancels all requests from an external origin to local resources, the attacker is unable to
even bootstrap his attack.
Drawbacks
The configuration effort of the proposed solution grows linearly with the complexity of
the intranet. Simple networks that span over a single subnet or exclusively use private
IP-addresses can be entered fairly easy. However, fragmented networks, VPN setups, or
mixes of public and private address ranges may require extensive configuration work.
Furthermore, another potential obstacle emerges when deploying this protection ap-
proach to mobile devices like laptops or PDAs. Depending on the current location of
the device, the applicable configuration may differ. While a potential solution to this
problem might be auto-configuration based on the device’s current IP-address, overlap-
ping IP-ranges of different intranets can lead to ambiguities, which then consequently
may lead to holes in the protection.
9.4. Evaluation
9.4.1. Comparison of the proposed protection approaches
As the individual protection features and disadvantages of the proposed approaches have
already been discussed in the preceding sections, we concentrate in this section on aspects
that concern either potential protection, mobility or anticipated configuration effort (see
Table 9.1). The technique to selectively turn off active technologies (see Sec. 9.3.1) is
left out of this discussion, due to the approach’s inability to provide any protection in
the case of an exploited XSS vulnerability.
Protection
The only approach that protects against all presented attack vectors is introducing a
restricted local network, as this is the sole technique that counters effectively DNS re-
binding attacks. However, unlike the other attack methods that rely on inherent specifics
of HTTP/HTML, successfully executing DNS rebinding has to be regarded as a flaw in
132
9.4. Evaluation
Conclusion
As long as DNS rebinding may still possible under certain conditions, an evaluation ends
in favor of the restricted local network approach. As soon as this browser flaw has been
removed, rerouting cross-site request appears to be a viable alternative, especially in
the context of large-sized companies with non-trivial network setups. Before an element
level SOP based solution is deployed on a large scale, the approach has to be examined
further for the potential existence of covert channel (see Sec. 9.3.2).
9.4.2. Implementation
Based on the discussion above, we chose to implement a software to enforce a restricted
local network, in order to evaluate feasibility and potential practical problems of this
approach [275].
We implemented the approach in form of an extension to the Firefox web browser.
While being mostly used for GUI enhancements and additional functions, the Firefox
extension mechanism in fact provides a powerful framework to alter almost every aspect
of the web browser. In our case, the extension’s functionality is based mainly on an
133
9. Protecting the Intranet Against JSDAs
Our testing environment consisted of a PC running Ubuntu Linux version 6.04 which
was located inside a firewalled subnet employing the 192.168.1.0/24 private IP-address
range. Our testing machine ran an internal Apache webserver listening on port 80 of the
internal interface 127.0.0.1. Furthermore, in the same subnet an additional host existed
running a default installation of the Apache webserver also listening on port 80. The web
browser that was used to execute the tests was a Mozilla Firefox version 2.0.0.1. with
our extension installed. The extension itself was configured using the default options.
Besides internal testing scripts, we employed public available tools for the practical
evaluation of our implementation. To test the protection abilities against portscanning
and fingerprinting attacks, we used the JavaScript portscanner from SPI Dynamics that
is referenced in [160]. To evaluate the effectiveness against anti DNS-pinning attacks we
executed the online demonstration provided by [141] which tries to execute an attack
targeted at the address 127.0.0.1.
The results turned out as expected. The portscanning and fingerprinting attempts
were prevented successfully, as the firewall rejected the probing requests of the reflection
service. Also as expected, the anti DNS-pinning attack on the local web server was
prevented successfully. Furthermore, the extension was able to detect the attack, as it
correctly observed the change of the adversary’s domain (in this case 1170168987760.
jumperz.net) from being remote to local.
134
Limitation:
! A local/remote classification is not in all cases possible
! Example:
" DMZ resources that grant different access rights based on
source IP address 9.5. Conclusion
Inner Firewall
DMZ
Outer Firewall
9.4.4. Limitations
During our tests we encountered a possible network setup that may yield problems with
our approach. A company’s web-services are usually served from within a DMZ using
public IP-addresses. Unfortunately, the “local”/”external”-classification of hosts located
in a DMZ is not a straight-forward task. As the hosts’ services are world-reachable
the respective IPs should be classified as “external” to allow cross-domain interaction
between these services and third party web applications. However, in many networks
the firewall setup allows connections that origin from within the company’s network
additional access rights to the servers positioned in the DMZ. For example, internal IPs
could be permitted to access the restricted FTP-port of the webserver to update the
server’s content (see Figure 9.3). Thus, in such setups a malicious JavaScript executed
within the intranet also possesses these extended network capabilities.
9.5. Conclusion
We showed that carefully crafted script code embedded in webpages is capable to bypass
the SOP and thus can access intranet resources. For this reason, simply relying on the
firewall to protect intranet HTTP server against unauthorized access is not sufficient.
As it is not always possible to counter such attacks at the server side, we introduced
and discussed four distinct client-side countermeasures. Based on this discussion, we
implemented a Firefox extension to enforce a restricted local network.
While our implementation reliably provides protection against the specified threats,
this protection comes with a price, manifesting itself in additional configuration overhead
and potential problems concerning mobile clients. Furthermore, our solution fixes a
problem that occurs because of fundamental flaws in the underlying concepts - HTTP
and the current JavaScript security model. Therefore future research in this area should
specifically target these shortcomings to provide the basis for a future web browser
generation that is not susceptible any longer to the attacks that have been regarded in
this chapter.
135
9. Protecting the Intranet Against JSDAs
136
Part III.
137
Motivation
In Section 2.1 we discussed the existence of two distinct types of XSS flaws: XSS caused
by insecure programming (see Sec. 2.1.1) and XSS caused by insecure infrastructure (see
Sec. 2.1.2). In this part of the thesis we exclusively consider the former type – XSS
issues that occur due to coding mistakes made during application programming.
We explicitly concentrate on this type of XSS because of the following reasons:
• The XSS issues caused by insecure infrastructure as discussed in Section 2.1.2 are
rare. They always are based on individual flaws of single infrastructure elements,
such as web browsers or servers. Therefore, in most cases such an issue lies within
the responsibility of one single vendor and can be fixed centrally.
• Furthermore, the underlying problems of such issues are very heterogeneous. There-
fore, it is not likely that a generic strategy to prevent such issues exists.
• On the other hand, XSS caused by insecure programming is widespread and po-
tentially affects every single web application.
• Finally, as we will discuss in Chapter 10, code-level XSS is only one representative
of a larger class of vulnerabilities – the class of string-based code injection flaws.
Thus, general prevention mechanisms, which are positioned at the programming-
level of abstraction are not necessarily limited to preventing XSS but may also be
applicable for other members of the larger vulnerability class.
Based on an analysis of the foundations of string-based code injection flaws, this part
of the thesis will explore fundamental methods to solve the problem of this class of
vulnerabilities.
Outline
This part of the thesis is structured as follows: First in Chapter 10, we closely examine
the general class of string-based code injection flaws to which XSS belongs. For this pur-
pose, we discuss the method of string-based code assembly (Sec. 10.1) and deduct from
this discussion the fundamental mechanics of string-based code injection (Sec. 10.2).
Sections 10.3 and 10.4 introduce the results of our analysis regarding the examined
vulnerability class and provide fundamental definitions concerning the classification of
language elements into data and code. These essential definitions provide the underlying
reasoning for the proposed techniques of the following chapters.
In Chapter 11 we develop a method to identify code injection attacks on run-time.
For this purpose, we show how to approximate data and code separation during program
execution.
Finally, in Chapter 12 we propose a novel method for dynamic code assembly which
does not rely on string operations and provides strict separation between data and code.
We show how to extend a given language’s type system to conform to our method and
present a formal model of this type system extension. Furthermore, we demonstrate how
to practically design, implement and enforce our approach.
139
140
10. The Foundation of String-based Code
Injection Flaws
In this chapter we explore programming errors which in turn lead to string-based code
injection flaws. It is crucial to identify the underlying root causes of this class of security
issues in order to develop valid and principled countermeasures.
The chapter is structured as follows: First, we examine the common practice of string-
based code assembly (see Sec. 10.1). Then in Section 10.2, we define the term “string-
based code injection” and briefly discuss existing vulnerability sub-classes which match
this definition, such as XSS and SQL injection. In Section 10.3 we analyse the vulnera-
bility class further and identify one of its root causes: The confusion between data and
code during application development. Based on this observation, we propose in Section
10.4 a mapping of individual, syntactical language elements to the concepts data and
code. Such a mapping is essential for defensive concepts, which aim to prevent such
vulnerabilities through enforcing separation between data and code. For this purpose,
we propose a general, systematical method in Section 10.4.1 which allows developing a
data/code mapping for a given computer language. Furthermore, in Section 10.4.2 we
show how this method can be used, by applying it to three selected language classes.
Definition 10.1 (Native/foreign) For the remainder of this thesis we will use the
following naming convention:
• Native language: The language that was used to program the actual application
(e.g., Java).
• Foreign language: All other computer languages that are used within the appli-
cation.
In the context of this thesis, to be classified as a foreign language, it is sufficient
for a coding scheme to adhere to a predefined formal grammar.
141
10. The Foundation of String-based Code Injection Flaws
SQL
HTML
Database JavaScript
PHP
CSS
XML
142
10.2. String-based code injection vulnerabilities
from external data sources like databases or the filesystem, an example being prede-
fined HTML templates. In these cases the interpreter reads the foreign code into string
variables.
Definition 10.2 (String-based code injection) Under the term String-based Code
Injection we subsume all injection vulnerabilities which fulfill two criteria:
1. They occur due to dynamic assembly of foreign code using the native language’s
string type and
2. they allow the attacker to alter the semantics of the attacked foreign code state-
ment through alteration of syntactic content, such as language keywords or meta-
characters.
143
10. The Foundation of String-based Code Injection Flaws
• SQL injection (SQLi): In the case of SQL injection [8, 77], the attacker is able to
maliciously manipulate SQL queries that are passed to the application’s database
(see Figures 10.2.A to 10.2.C). By adding attacker-controlled SQL commands,
this flaw can lead to, e.g., unauthorized access, data manipulation, or information
disclosure.
• Command injection: Some applications dynamically create executable code in
either the native language (to be interpreted with commands like eval()) or as
input to a different server side interpreter (e.g., the shell, see Listing 10.2). In
such cases, carelessly included dynamic data might enable the attacker to execute
arbitrary commands on the attacked server with the privileges of the vulnerable
application.
This class of injection vulnerabilities is also known under domain specific names
such as “PHP injection”, “ASP injection”, or “shell injection”.
1 // the content of $email is controlled by the attacker
2 $handle = popen ("/ usr / bin / mail $email ");
3 fputs ( $handle , ...); # write the message
• Path traversal: Path traversal [272] is a special variant within the class of injec-
tion flaws. Instead injecting syntactic content consisting of language keywords, the
adversary injects meta-characters (such as ../) into file-system path information.
This enables the attacker to break out of the application’s allowed data directories,
so that he can access arbitrary files of the filesystem (see Listing 10.3).
This attack is also known as “dot-dot-slash”, “directory traversal”, “directory
climbing”, and “backtracking”.
1 <? php
2 // Exploitable by accessing
3 // http :// vic . org / vul . php ? template =../../../../ etc / passwd
4
5 $template = ’ blue . php ’;
6 if ( is_set ( $_GET [ ’ template ’] ) )
7 $template = $_GET [ ’ template ’];
8 include ( "/ home / users / victim / templates /" . $template );
9 ?>
144
10.3. Analysis of the vulnerability class
1. The data/code confusion due to ad-hoc foreign code assembly using the string
datatype (see Sec. 10.3.1) and
2. the direct, unmediated interfaces between the native language’s runtime and the
foreign interpreters (see Sec. 10.3.2).
Please note: Throughout this chapter we occasionally use SQL syntax because of
SQL’s comparatively expressive syntax which allows the construction of short meaningful
code. However, the discussed topics are applicable for any given computer language.
145
Code injection attacks (V): The DB’s view
$pass = $_GET[“password”];
Code injection
Code attacks (V): The DB’s view Data
A. The programmer’s view on code assembly
$pass = $_GET[“password”];
Code injection
Code attacks (V): The Data
DB’s view Data
B. The DB’s view
$pass = $_GET[“password”];
Code injection
Code attacks (V): The Data
DB’s view Code
C. The DB’s view (code injection)
$pass = $_GET[“password”];
The second fundamental reason for the existence of string-based code injection vulnera-
bilities is the common practice of coupling heterogeneous systems using direct, “dumb”
interfaces. Such interfaces act as a simple pass-through device which transmits all infor-
mation from the native to the foreign context without further processing or mediation.
To interact with the foreign entity via such an interface, the instructions regarding the
targeted action is encoded in the foreign syntax which in turn is sent to the receiving
146
10.4. Towards mapping data/code to string-based code assembly
Vision
HTML / JS
Abstraction Layer
SQL
e.g., bash
(Application Server)
XML
Web Web
Database Database
Browser Browser
system (see Fig. 10.3). Then, the foreign entity parses and interprets the received foreign
code.
Such interfaces can be realized for instance through: Call level interfaces, such as
Open Database Connectivity (ODBC) [110] which provides the native language’s run-
time with a SQL-based communication channel to the database, network protocols, such
as HTTP and SMTP, or, raw I/O streams, e.g. provided by functions such as open().
Alternative approaches to such interfaces for coupling heterogeneous systems are for
instance CORBA [199] or Java RMI [249], both providing an interface on the API-level
of abstraction. This means, that in such systems all messages and actions which are
directed at the foreign entity are created via native API calls. Such interfaces are less
flexible, as every single action/message has to be implemented explicitly, but they are
not susceptible to data/code confusion.
However, compared to direct interfaces, these approaches failed to achieve wide adop-
tion in practise, mainly due to their inherent inflexibility and inability to model the
specifics of the targeted foreign entity. For instance, the composition of mark-up doc-
uments, such as HTML, using an API-level method (e.g., by utilizing the DOM API
[102]) is cumbersome, error-prone, and hard to maintain.
147
10. The Foundation of String-based Code Injection Flaws
The outcome of both tasks depend heavily on the specifics of a given foreign language.
Furthermore, as our initial definition of the term foreign language (see Definition 10.1)
is broad and inclusive, it is necessary to differentiate between different sub-classes of
languages.
The elements of the statement which represent static language keywords, such as
SELECT or WHERE, can be clearly identified to account for code-elements. Also, the clas-
sification of the integer-literal 001 as data is straight forward. Furthermore, the state-
ment’s punctuator-elements (*, =, and ’) fulfill the same syntactical purpose as static
language keywords. Hence, they also should be classified as code.
However, the assignments of the remaining elements is not as obvious. The table-name
users and the row-name id are not static properties of the foreign language. Instead they
are identifier-elements with dynamic values. Therefore, this dynamic nature suggests a
classification as data-elements. On the other hand, during the execution of the native
application, the database-layout is constant. Thus, within a given native application’s
source code, the table-names are static. Furthermore, the ability to alter such identifier-
elements might enable the attacker towards elevating his privileges. For example, if he
would be able to control the table-name in a vulnerable statement assembly, he might
be able to exchange users with admins. For this reason, to prevent string-based code
injection attacks on this language class, database identifiers have to be classifies as code-
elements.
148
10.4. Towards mapping data/code to string-based code assembly
For this purpose, we have to refine the definitions of the terms data and code in respect
to foreign language syntax. The here proposed mapping was constructed exclusively
in respect to the capabilities of an adversary to maliciously alter the semantics of a
dynamically assembled foreign code statement via code injection attacks. Therefore, we
followed four basic premises:
First, we introduce two basic notions: Syntactic structure and basic semantic pattern.
Both concepts have the purpose to provide a systematic rationale for dividing the set of
language elements into the data/code classes.
When a foreign code statement is parsed, a direct result of the parsing process is the
statement’s abstract syntax tree (AST). An AST is a a tree-like data-structure which
is built by recognising and aligning the statement’s tokens according to the language’s
formal grammar. Su and Wasserman observed in [248] that a successful injection of
language elements alters the attacked statement’s AST. In the same context Pietraszek
and Berghe talk about injection of “syntactic content [...which...] influences the form or
structure of an expression” [210]. Based on these observations, we define:
Definition 10.3 (Syntactic structure) Two foreign code statements that produce the
same AST if processed by the same parser are said to share the same syntactic structure.
Su and Wasserman’s concept is well fitted for most string-based injection scenarios
which rely on adding additional syntactic elements, thus altering the attacked state-
ment’s syntactic structure. However, malicious alteration of a statement has does not
necessarily change the statement’s syntactic structure: E.g., if the attacker is able to
exchange the name of identifiers which are used in the statement, such as variable- or
function-names, the statement’s actions can be redirected without changing the state-
ment’s syntactic structure.
Consequently, we have to introduce a second concept that abstracts semantic aspects of
the statement: the basic semantic pattern (BSP). A foreign code statement’s BSP defines
the specifics of the statement’s actions without considering the statement’s actual values.
Such actions are defined by two distinct characteristics – the set of possible control-flows
that may result from the statement’s code and the corresponding data-flows.
Definition 10.4 (Basic semantic pattern (BSP)) The set of all value-independent
control- and data-flows which are directly connected to a code statement’s targeted actions
constitute the statement’s basic semantic pattern (BSP).
149
10. The Foundation of String-based Code Injection Flaws
A statement’s BSP can be regarded as a blueprint: It defines the “how” and “where”
of the actions that are targeted at the statement’s values (which in turn determine the
“what”). Depending on the specific foreign language, such actions can be for instance
compute (general purpose or query languages), structure (mark-up or query languages),
display (mark-up languages), or reference (query languages, mark-up languages, or gen-
eral coding schemes).
Example: Take the statement var x = 2 + 4;. While the statement’s specific seman-
tic is add the numbers 2 and 4 and store the result in x, the statement’s BSP is only
add two numbers and store the result in x. Therefore, the statement var x = 200 +
123; has the same BSP. However the BSP of the statement var y = 2 + 4; differs
as the targeted location of the computation’s result is different. To further clarify this
notion, here are some additional examples: The BSP of a given foreign code statement
determines for instance: In which variable a result should be written (data-flow), which
function should be used for the computation (control-flow), which display-class a certain
HTML element belongs to (control-flow of the corresponding rendering process), or from
which table a given SQL statement should obtain the requested values (data-flow).
Using the above stated premises and the given definitions, we are now able to formulate
our definitions of data and code. We start with the definition of code-elements:
A data-element may influence a specific control-flow, for instance because of its usage
in a conditional clause. However, according to Definition 10.4 the statement’s BSP
consists of all potential, value-independent control-flows which include both forks of the
conditional.
150
10.4. Towards mapping data/code to string-based code assembly
These language elements can be assigned to the date/code classes as follows: For
one, we classify all token-types which are part of the language’s grammar in the form of
static syntactic elements, namely the keyword-tokens and the symbol-tokens, to be code.
Modification of such a token within a statement will result in changes in the statements
151
10. The Foundation of String-based Code Injection Flaws
syntactic structure. Also, such an alteration will change in most cases the BSP of the
statement.
Furthermore, we classify the set of identifier-tokens to be code. While changing an
identifier will not necessarily change a statement’s syntactic structure, it will in any case
affect the statement’s BSP.
The remaining token-type, the literal-tokens, account for the respective language’s
data-elements.
Mark-up languages
In this thesis, we focus on mark-up languages that belong to the SGML-family, such as
HTML and XML-based languages. Such languages were initially exclusively specified
using Document Type Definitions (DTD) [26]. The specifics of SGML and XML DTDs
differ slightly. This thesis utilizes the XML variant.
As stated in Definition 10.1, we assume that a foreign language’s syntax is completely
defined by a formal grammar. For this reason, we briefly examine the corresponding
properties of DTDs: A DTD is specified using a formal syntax closely related to the
extended Backus-Naur form (the “DTD language”). Unlike the extended Backus-Naur
form, DTDs allow exceptions within the right-hand side of production rules. However,
Kilpeläinen and Wood have proven in [146] that such exceptions do not increase the
expressiveness of the specification language over DTDs without exceptions and, thus,
a structurally equivalent extended context-free grammar can be obtained. In turn, Ex-
tended context-free grammars are context-free grammars which allow regular expressions
over terminals and non-terminals on the right-hand sides of production rules using the
operators ∪, ∗ and concatenation. Madsen and Kristensen have proven in [174] that
every extended context-free grammar can be translated in an equivalent context-free
variant. Consequently, the family of languages definable with DTDs is a subset of the
class of context-free languages [20] and for a given DTD a corresponding context-free
grammar exists.
Following the introduction of DTDs, several alternative specification languages for
defining XML languages have been proposed, such as XML Schema [66] or Relax NG [40].
While being more expressive and powerful as DTDs, the class of languages that can be
defined by these specification languages remains within the class of context-free languages
[195]. Furthermore, as these specification schemes do not add new basic language-
elements, it is sufficient to concentrate on DTDs in the context of this thesis.
A given DTD specification consists of the following basic language-elements [26]:
152
10.4. Towards mapping data/code to string-based code assembly
that occur in many documents, especially if there is a need to allow such text to
be changed in one place only.
Example [26]:
1 <! ENTITY Pub - Status " This is a pre - release of the specification ." >
• Tags: Tags are the basic building blocks of XML/SGML documents. The individ-
ual tag-types are specified in the DTD by Element-definitions . For each tag-type
the following properties are determined by the element definition:
Example [117]:
1 <! ELEMENT SCRIPT - - % Script ; -- script statements -->
For a given language, the list of allowed elements is predefined and static.
• Attributes: For a given tag-type a list of permitted attributes is given. For each
attribute the following properties are determined by the definition:
Each element of this list is composed of two sub-elements:
Example [117]:
1 <! ATTLIST SCRIPT
2 charset % Charset ; # IMPLIED -- char encoding of linked resource --
3 type % ContentType ; # REQUIRED -- content type of script language --
4 src % URI ; # IMPLIED -- URI for an external script --
5 defer ( defer ) # IMPLIED -- UA may defer execution of script --
6 event CDATA # IMPLIED -- reserved for possible future use --
7 for % URI ; # IMPLIED -- reserved for possible future use --
8 >
For a given language, the set of allowed attributes for the individual elements is
predefined and static.
153
10. The Foundation of String-based Code Injection Flaws
Resource-locators
As specified in Definition 10.1 we include general coding-schemes, such as UNIX path-
specifications or URLs, into the class of foreign languages as long as they adhere to
a predefined formal grammar and are utilized on run-time through string-based code
assembly.
Resource-locators are composed of two basic element types:
• Identifiers: Values that represent the names of the actual entities or specifications
that are utilized to determine the location of the referenced resource.
The values of identifiers can either be:
154
10.4. Towards mapping data/code to string-based code assembly
155
10. The Foundation of String-based Code Injection Flaws
156
11. Identification of Data/Code Confusion
In the last chapter we showed how to divide the syntactic elements of computer languages
into the classes of data- or code-elements. Based on this element-classification, in this
chapter we explore a methodology to transparently identify such data- and code-elements
in dynamically assembled foreign code in order to detect code injection attempts. This
is done by applying string masks to all legitimate foreign code-elements before potential
hostile input is processed.
We discus our approach and show how to implement it for the foreign languages HTML
and JavaScript in order to counter XSS attacks. Using a practical implementation for a
PHP-based application server, we evaluate our approach’s protection capabilities. The
proposed methodology and the evaluation were originally published in [129].
11.1. Motivation
As described in Sections 10.2 to 10.4 many insecurities in today’s applications are rooted
in confusing data and code during foreign code assembly. The solution proposed in this
chapter addresses this problem by detecting code-elements in dynamically assembled
foreign syntax which have been injected by the attacker.
We we aim to implement our approach in a way that changes neither the syntax
or semantics of the native language nor the practice of string-based code assembly.
This objective enables an implementation which is backwards-compatible with existing
applications.
Please note: In this chapter, we utilize the terminology and scenarios from the web
application paradigm because our implementation and evaluation targets (the PHP ap-
plication server and the class of XSS flaws) are both specific for web applications. How-
ever, the proposed approach is not limited to web applications but can be employed for
general applications which assemble foreign code through strings.
157
11. Identification of Data/Code Confusion
Consequently, our approach works as follows. Before program execution, all foreign
code-elements which are contained in the applications static strings are identified and
uniquely marked. After this step, the application is executed as usual. Whenever foreign
syntax is sent to an external interpreter, this sending-process is intercepted. Before
passing the syntax to the external entity, we verify that all encountered code-elements
have been identified and marked in the pre-execution step. All code-elements that cannot
be recognised to be static part of the application are considered to be injected and
neutralized.
P (I) = {
string s = ’rm -rf /’
if (A(I, I) == false)
execute(s);
else
print(s);
}
If we now run P (P ), a call to P with its own source code as input, a contradiction is
triggered: If A decides that P will not execute s, s gets executed by P and if A decides
that s will be executed by P , P merely prints s and exits.
As the general problem to decide if a given string constant will be executed in a given
situation (and therefore contains code) is undecidable, we have to approximate a solution.
We choose an over-approximation approach. In this context over-approximation results
in an algorithm that identifies all strings that will be executed. However such an over-
approximating algorithm may also falsely classify some general data as foreign code.
158
11.2. Concept overview
means to differentiate between these two classes during program execution. For this
reason, we propose string masking, a method that enables our technique to syntactically
mark foreign code-elements in strings without changing the native language’s string type.
As already motivated, our proposed approach is based on the general assumption that
all foreign code is static part of the application. Thus, foreign language elements that are
dynamically received during execution represent exclusively foreign data. This assump-
tion leads us to the following definition: All foreign code-elements that are part of the
application before the processing of an HTTP request are legal. More precisely: Legal
foreign code is either part of the application’s source code or contained in specific trusted
data sources like database tables or files. Only this foreign code is allowed to be exe-
cuted or included in the application’s web pages. Accordingly, all foreign code-elements
that are added dynamically to the application in the course of program execution are
potentially malicious and should be neutralized. These code-elements are from here on
denoted as illegal code. Please note an important distinction in this matter: This defini-
tion does solely apply to actual code-elements and not to data-elements that have been
added to preexisting legal code.
Example 1 (illegal code): An application contains the following predefined SQL in-
struction:
1 $sql = " SELECT * FROM USERS WHERE ID = $id and PASS = ’$pw ’";
The variables $id and $pw are placeholders for dynamic data-elements representing
the ID and password of a user. If the application uses the values 42 and foo to complete
the SQL statement, the resulting code looks like this:
1 " SELECT * FROM USERS WHERE ID = 42 and PASS = ’ foo ’"
The statement still solely contains legal code, as only data-elements have been added
on runtime. But if an attacker can figure out a way to pass arbitrary values to ei-
ther variable, the application is vulnerable to SQL-injection. In this case the attacker
can pass the string “bar’ OR ’1’ = ’1” as value for $pw to bypass the application’s
authentication mechanism. Then the resulting SQL string would look like the following:
1 " SELECT * FROM USERS WHERE ID = 42 and PASS = ’ bar ’ OR ’1 ’ = ’1 ’"
The signifiers “OR” and “=” represent code-elements. As these code-elements have en-
tered the application on runtime, they are classified as illegal.
Note: In the following paragraphs we describe our technique solely in respect to
JavaScript and countering XSS attacks. This is done to avoid unnecessary complex
descriptions. The technique itself is not limited to XSS but applicable to counter various
injection attacks. See Section 11.3.4 for details on that matter.
159
11. Identification of Data/Code Confusion
As shown in Section 10.1, foreign code is embedded in web applications either as part
of string constants or kept in external data sources. We introduce a pre- and a post-
processor to detect illegal code-elements. For every string constant the preprocessor
enforces a syntactic separation between data-elements and code-elements by masking
certain parts of the string. After the processing of an HTTP request, the post-processor
detects and neutralizes illegal code-elements. Furthermore, the post-processor removes
the masks that were applied by the pre-processor.
Before processing the HTTP request, all foreign code is masked to enable identification
of legal code-elements in the course of processing the request. Due to the backwards-
compatible nature of our approach we cannot fully utilize the data/code-classification
of language elements which has be discussed in Section 10.4. A given application’s
set of utilized foreign identifiers, such as variable- and function-names, is dynamic and
unknown to our pre-processor. Therefore, only code-elements which are statically defined
in the foreign language’s grammar are detectable. Thus, to find legal code-elements in
the application’s strings a set of language keywords is used.
The pre-processor examines every string constant that is part of the application’s
source code whether it contains any of the specified keywords. If such a keyword was
found, the keyword is replaced with a code mask. This mask is a per-request random
token representing the found keyword. If this keyword is found more than once, it is
always replaced by the same token. The masking is done on the first initialization of the
string constant. Furthermore, all server side input, that has been specified to contain
legal code, is filtered accordingly: All found keywords are replaced by per-request code
masks. This way it is ensured that all legal foreign code-elements are masked before
they enter the application. The pre-processor stores the pairs consisting of the original
keywords and the per-request masks in a table to enable the reverse transition later on.
A set of keywords has to be chosen to counter the projected attacks. To counter XSS
attacks our keyword list consists of reserved HTML signifier, HTML attributes, reserved
JavaScript words and names of global JavaScript/DOM objects (see Table 11.1).
160
11.2. Concept overview
Language Keywords
– All reserved HTML tag names with more
than two characters
HTML e.g., html, head, body, script
– All predefined HTML attributes
e.g., href, src, onload, onmouseover
– All reserved JavaScript words
e.g., for, while, try, eval
JavaScript – Selected DOM signifiers
e.g., document, children, getElementById
– Names of global JavaScript objects
e.g., window, location
If the variable $term is not sanitized by the application, this would be a classical
example for a XSS vulnerability. The pre-processor identifies the code-element href and
applies an one-time mask (the code-element a is not masked due to the chosen keyword
list, see Table 11.1):
1 echo " < a _x2sgth_ = ’ user . pl ’ > You </ a > searched for $term .";
If a malicious user would try to exploit the XSS vulnerability by passing JavaScript code
to $term, the output buffer may look like:
1 <a _x2sgth_ = ’ user . pl ’ > You </ a > searched for < script > var a = document . cookie ...
161
11. Identification of Data/Code Confusion
Before sending the resulting web page to the web browser, the post-processor scans the
output buffer for keywords again. Thus, he finds the injected code-elements. These
elements are encoded using HTML entities:
1 <a _x2sgth_ = ’ user . pl ’ > You </ a > searched for <scr...
162
11.2. Concept overview
operations can function as intended. Our proposed technique does not change the syn-
tactic structure represented in the application’s strings. It just replaces certain string
constants, the keywords, with other string constants, the code masks.
Finally, the identified keyword could be in fact a textual key-value used in one of the
application’s native language constructs. Some programming languages use string-based
keys to access data stored in containers like hashtables. If the hashtable’s keys are only
used inside the application source code such a false positive does not yield any prob-
lematic consequences. The mapping between the keyword and the code mask is static
for the complete processing of an HTTP request. Thus, the deterministic referencing
of information is unhindered. But if the hashtable’s keys are derived from an outside
entity like a database table or the actual HTTP request, the access to the hashtable’s
information may be hindered. In this case the pre-processor has to be adapted slightly
to avoid the false positive.
As it is the case with the pre-processor, a false positive of the post-processor occurs when
a keyword is found in a non-code context. In this case the keyword is either part of the
webpage’s text or a value of a dynamically generated HTML attribute. The former case
does not pose any problems. The post-processor encodes the found keyword in HTML
entities which are displayable by the web browser.
To discuss the latter case we have to differentiate between different attribute types.
We can divide HTML attributes in six classes based on the value type they accept (see
Table 11.2 for details). HTML attributes accept either numerical values, identifiers,
predefined textual data, JavaScript, URLs, or variable textual data. Three of these
classes are safe in this context as their values cannot cause false positives: Numerical
values cannot include foreign code keywords, identifiers are not derived from user input,
and the list of predefined attribute values does not intersect with the used list of foreign
code keywords. Furthermore, by definition there cannot be a false positive concerning
JavaScript, as our countermeasure explicitly aims at detecting and neutralizing rogue
script code. False positives in URL-attributes lead to URLs that are partly encoded
in HTML entities. As modern web browser interpret encoded URLs correctly, such an
incidence does not disturb the web application. This leaves false positives in attributes
that accept variable textual data. Within this class we have not encountered problems
caused by false positives. Commonly used attributes from this class are either never
parsed by the web browser (e.g., rel) or work transparent with HTML encoded values
(e.g., alt or value). But as such attributes are sometimes used for purposes that are
not covered in the HTML specification [117], there may be rare problematic scenarios.
As the encoding of the server side data is controlled and deterministic, such a false
negative can only happen if the used list of keywords is incomplete.
163
11. Identification of Data/Code Confusion
The correct detection of illegal code-elements depends on the ability of the post-processor
to find specific keywords in the output buffer. Attackers are known to employ various
input encoding techniques to evade filter mechanism [95]. The basic concept behind
most of these evading techniques is to create HTML syntax that does not comply with
the general grammar of HTML [117] but is still recognized by the web browser. The un-
derlying cause which enables this approach is that HTML parsers are known to employ
a rather forgiving parsing process. This behavior enables web browsers to render web
pages that contain faulty HTML code. The post-processor has to take all known evading
techniques into consideration to be able to detect such obfuscated HTML tokens. But
as it is undocumented which syntax errors in HTML code the diverse browsers accept,
there might still exist undiscovered evading techniques. Because of this special charac-
teristic of HTML parsers an attacker might be able to craft data that contains HTML
code which is not detectable by the post-processor. This way the attacker may under
certain conditions succeed to include an illegal HTML tag into the resulting webpage.
If such a previously undiscovered evading technique is discovered the mechanisms can
be adapted easily, as the post-processor is a single central component. Nonetheless, the
inclusion of a functioning JavaScript is not feasible: Other parsers are strict in which
syntax they accept or reject. Therefore, the techniques described in [95] do not apply
to programming languages like JavaScript or SQL. For a successful injection attack the
complete injected code has to evade the detection process. A single detected and en-
coded code fragment causes the attacked interpreter’s parser to encounter a syntax error
and abort the execution of the injected code.
164
11.2. Concept overview
code the post-processor checks if one of the application’s policies matches the request’s
URL. If this is the case, the post-processor skips the encoding of the keywords that are
specified in the matching policy.
Also, these policies are used by the pre-processor to identify trusted data-sources.
String values that are obtained from such sources are masked as if the strings were part
of the application’s source code. As the pre- and post-processor are single application-
global entities, these policies provide a central mechanism to control certain security
properties of the application, e.g., the particulars of user provided HTML.
Examples: A policy to allow a weblog’s visitors to add images to their comments would
look like this:
1 < policy unit =" post - processor " >
2 <url >/ blog / comments . php </ url >
3 < keyword > img </ keyword >
4 < keyword > src </ keyword >
5 </ policy >}
Accordingly, a policy specifying an external data source as trusted to contain legal HTML
code would look like this:
1 < policy unit =" pre - processor " >
2 < file >/ templates /* </ file >
3 < keyword > img </ keyword >
4 ...
5 </ policy >}
There are two distinct approaches to implement the proposed methods. Either the de-
scribed measures can be directly integrated in the native language’s interpreter/compiler
or they can be implemented by instrumenting the source code. The details of a direct
integration are very dependent on the specific language. Therefore, we omit a gen-
eral description of this approach for brevity reasons. See Section 11.3.1 for a concrete
example.
Code instrumentation is an automatic source-to-source transformation that wraps cer-
tain functions with calls to either the pre- or the post-processor. If code instrumentation
is used, the source code of the whole application is modified before passing it to the inter-
preter. The actions of the pre- and post-processor are implemented as regular functions
and added to the application’s code. All static strings are wrapped by the pre-processor
function. Furthermore, all function calls that retrieve string values from external data
sources are wrapped as well. Accordingly, the post-processor wraps all function calls,
that cause string data to leave the system. The application’s source code has to be
instrumented only once. The modified source code can be stored permanently and serve
as the application’s actual code base.
165
11. Identification of Data/Code Confusion
After instrumentation:
1 // static string constants
2 $code = __smPrepro (" < script >... </ script >");
3
4 // accessing external string constants
5 $data = __smPrepro ( fread ( $file , 100));
6
7 // writing string data
8 fwrite ( $file , __smPostpro ( $data ));
Implementing the final post-processing of the produced HTML code with code instru-
mentation may not always be possible. In this case two alternative solutions exist to
realize the post-processor without modifying the actual interpreter: If the language pro-
vides an output buffering mechanism, which collects the complete HTML code before
passing it to the web server, this mechanism can be employed to implement the final
post-processing. However, some languages do not provide such a buffering mechanism.
In this situation, a proxy mechanism between the language’s interpreter and the web
server has to be introduced.
166
11.3. Discussion
11.3. Discussion
11.3.2. Evaluation
The practical evaluation of our approach was twofold. On the one hand we examined
if our implementation is compatible with existing applications, on the other hand we
assured that our concept indeed provides the desired protection.
Evaluation of compatibility
At first we examined if execution problems occur when existing PHP applications are
run on a PHP system that uses our SMask extension. For this reason we installed
several popular open source PHP application (see Table 11.3 for details). All tested web
applications worked as expected without any modifications.
167
11. Identification of Data/Code Confusion
Evaluation of protection
In order to verify that our technique indeed prevents XSS attacks, two testing approaches
were applied. For one, we tested known XSS attack methods against a self written test
script and, secondly, we examined vulnerable versions of popular applications.
Our test script solely consists of a simple echoing function, that writes all user input
directly unfiltered in an HTML page. Using the XSS attacks listed in [95], two different
policies were evaluated: One policy that prohibits all user-supplied code and one policy
that allows a typical HTML subset, thus permitting the dynamic inclusion of basic
text-formating and usage of hyperlinks. Both policies prevented our XSS attacks.
Then we installed three PHP applications with public disclosed XSS flaws (see Table
11.3). Executing the attack vectors that were documented in the respective advisories,
we verified that SMask successfully prevented the exploit.
11.3.3. Protection
If an attacker injects correctly masked code-elements, these code-elements are translated
to working foreign code by the post-processor. Therefore, the measure’s effectiveness
in protecting against injection attacks depends on the ability of an attacker to guess
correct code masks. As every keyword is masked differently, the attacker has to guess
the individual masks for all keywords used in his attack. Consequently, the success
probability of such an attack shrinks with the number of keywords used in the attack.
To estimate a lower bound for this probability we have to look at attack vectors with as
few keywords as possible. For example, the following string represents the smallest XSS
attack vector that is able to conduct a meaningful attack:
1 < script src =" http :// a . org / a . js " > </ script >
This vector contains only two keywords: script and src. If the processors employs
code-masks of length eight over an alphabet of 62 symbols (numbers and characters in
upper and lower case), the probability of a successful attack is:
1
Psuccess =
628 (628 − 1)
168
11.4. Conclusion
In the case that the keyword src is permitted, e.g., by a site that allows its users to post
images, the probability is:
1
Psuccess = 8
62
These probabilities are constant over a series of attacks, as the code masks change for
every single HTTP request. For the same reason, hypothetical information leaks pose
no security problem.
Finally, there is room for improvement in the field of policies. Instead of solely relying
on keyword matching, we can use more sophisticated techniques to determine if dynam-
ically added foreign code is legal or illegal. Such techniques can e.g., take relationships
between single code fragments into consideration.
11.4. Conclusion
In this chapter we proposed a novel method to automatically identify and mitigate data/-
code confusion in order to counter string-based code injection attacks. Our approach
employs string masking to enable the web application to differentiate between legitimate
and injected code. This way a variety of code injection attacks can be prevented.
Our technique can either be implemented by integration in the native language’s
interpreter or by automatic source-to-source code instrumentation. Our approach works
transparent and requires no manual changes to the protected application. The two main
components, the pre- and the post-processor, are central entities which are configured
by policy files. Therefore, these policies establish a central point to administrate the
169
11. Identification of Data/Code Confusion
security properties of the web application. Using a proof of concept implementation for
PHP5 we were able to verify the technique’s protection mechanisms.
Using our approach web applications can be effectively protected against code injection
attacks without requiring profound changes in the application’s source code or existing
infrastructure.
However, due to the undecidable nature of the underlying problem (see Sec. 11.2.2),
our proposed solution’s detection mechanism can suffer from false positives and/or false
negatives (see Sec. 11.2.4). This shortcoming is due to our objective to leave the actual
process of string-based foreign code assembly unchanged in order to provide compatibility
with existing applications. We investigate an alternative approach which fundamentally
alters the methods to dynamically create foreign code in Chapter 12.
170
12. Enforcing Secure Code Creation
We have shown in Section 11.2.2 that attempts to dynamically resolve data/code con-
fusion lead to undecidable problems. For this reason, this chapter proposes a language-
based methodology to solve the problem of string-based code injection fundamentally by
removing the vulnerability class’ underlying mechanisms. For this purpose, we examine
how established programming language techniques and conventions have to be modified
and extended to ensure reliable secure foreign code creation.
This chapter is structured as follows: First in Section 12.1, we outline our general
methodology and identify our approach’s key components. The centerpiece of our ap-
proach is an extension of the native language’s type system which is the topic of Section
12.2. In this context we revisits the field of formal type theory and its applications to
security properties (see Sec. 12.2.1). Then we show how these results can be extended
towards guaranteeing secure code assembly (see Sec. 12.2.2). In Sections 12.3 and 12.4
we discuss further important components of our approach: The syntactical integration
of the foreign syntax into the native language and the design of an abstraction layer
that mediates all code-communication between the native language and the foreign in-
terpreters. Finally, we show how to adapt our approach for a specific case, native Java
and foreign HTML/JavaScript, (see Sec. 12.5) and evaluate our technique using a cor-
responding practical implementation (see Sec. 12.6). We finish with a conclusion in
Section 12.7.
171
12. Enforcing Secure Code Creation
injection flaws (see Figure 12.1.B), the resulting question would be: What would a pro-
gramming language look like that cannot interface directly with external interpreters using
the language’s string type?
C versus Java Vision
HTML / JS
Abstraction Layer
SQL
Abstraction Layer
e.g., bash
(Application Server)
(Virtual Machine)
XML
Web Web
Database Database
Memory Memory Browser Browser
Management Management
External Web External Web
Interpreters Services Interpreters Services
! Martin Johns, UH, FB Inf, SVS, 16.12.2005 10 ! Martin Johns, UH, FB Inf, SVS, 16.12.2005 11
172
12.1. Motivation and concept overview
areas, that can be resolved comfortably using the existing techniques, is unlikely to be
adopted.
Objectives concerning the native language: Foremost, the proposed concepts
should not depend on the specifics of a given native language. They rather should be
applicable for any programming language in the class of procedural and object-orientated
languages1 . Furthermore, the realisation of the concepts should not profoundly change
the native language. Only aspects of the native language that directly deal with the
assembly of foreign code should be affected.
In addition, the introduced means for foreign code creation should preserve the capa-
bilities and flexibility of the string type. String operations have been proven in practice
to be a powerful tool for code assembly. Therefore, the introduced mechanisms should,
e.g., provide means for easy combination of code fragments, and capabilities to search
and modify the data contents of a given foreign code instance.
Objectives concerning the creation of foreign code: The specific design of every
computer language is based on a set of paradigms that were chosen by the language’s
creators. These paradigms were selected because they fitted the creator’s design goals in
respect to the language’s scope. This holds especially true for languages like SQL that
were not designed to be a general purpose programming language but instead to solve
one specific problem domain. Therefore, a mechanism for assembling such foreign syntax
within a native language should aim to mimic the foreign language as closely as possible.
If the language integration requires profound changes in the foreign syntax it is highly
likely that some of the language’s original design paradigms are violated. Furthermore,
such changes would also cause considerable training effort even for developers that are
familiar with the original foreign language.
Datatype: We have to introduce a new datatype to the native language that is suitable to
assemble/represent foreign code and that guarantees strict separation between data
and code according to the programmer’s intent. In the context of this document
we refer to such a datatype as “Foreign Language Encapsulation Type (FLET)”.
Language integration: The handling of the newly created datatype and the assembly
of foreign language’s syntax have to be integrated in the native language. Such
an integration has to enforce that all generation of foreign code is explicit to avoid
accidental code creation, for instance due to implicit string serialization, that in
turn may lead to code injection vulnerabilities.
173
Key
12. Enforcing Secure Code components (I)
Creation
Datatype
Abstraction Layer
(Application Server)
Foreign code
ment is not allowed to interact with external interpreters directly anymore, this
abstraction mechanism has to handle such communication. Such an abstraction
layer receives the foreign instructions from the application’s runtime environment
encapsulated in the newly created datatype. It then translates the provided code
information into correct foreign code without being susceptible to injection attacks
and passes this code on to the external entity.
174
12.2. Introducing a specific datatype for secure code assembly
and complexity while retaining a separation between data and code. Most properties
of a given FLET are dependent on the specifics of the foreign syntax that the FLET
is supposed to assemble. However, there are properties that all potential FLET-types
share:
1. A minimal FLET has to posses a set of separate methods to add either code- or
data-elements information to a FLET instance.
• Trapped error: Execution errors that cause the computation to stop immedi-
ately.
• Untrapped errors: Execution errors that are not immediately detected and
cause arbitrary behavior later. An example of an untrapped error is improperly
accessing a legal address, for example, accessing data past the end of an array in
absence of run-time bounds checks.
A program fragment is safe if it does not cause untrapped errors to occur. Languages
where all program fragments are safe are called safe languages. Utilizing this notion, we
will extend the native language’s safety requirements by introducing an additional class
of untrapped errors: Insecure code assembly (proposed in Section 12.2.2). By extending
the language’s type-system accordingly we ensure the language’s safeness in this respect.
175
12. Enforcing Secure Code Creation
• Typing axioms: A set of underlying typing judgements which build the basis of
the examined type-system.
Example [30]:
` true : Bool (true has type Bool)
• Type rules: Type rules assert the validity of certain judgements on the basis of
other judgements that are already known to be valid.
Example [262]:
Γ ` M : int Γ ` N : int (Typing of integer addition)
Γ ` M + N : int
• Type derivation and inference: A type derivation in a given type system is a
tree of judgements, with leaves at the top and a root at the bottom, where each
judgement is obtained from the ones immediately above it by some rules of the
system [30].
The task of discovering a derivation for a term is called the type inference problem.
In the absence of any derivation for an examined term, we say that the term is not
typable or that is has a typing error.
1. The Simple Security Property states that a subject at a given security level may
not read an object at a higher security level (no read-up).
2. The *-property states that a subject at a given security level must not write to any
object at a lower security level (no write-down).
The Bell-LaPadula policies have their origin in modeling existing governmental and
military policies, resulting in a intuitive interpretation of the terms object and subject.
Mapping the policies to computer programs results in assigning the term object to a
program’s variables while the term subject describes general expressions. Consequently,
the *-property forbids that expressions of a high security level are assigned to variables of
176
12.2. Introducing a specific datatype for secure code assembly
a low security level and the *-property forbids interpretation of low typed expression in
high security contexts. Thus, enforcing the policy’s confidentiality requirements within
computer programs can be reduced to controlling and restricting the flow of information
within the program during execution. Denning and Denning [51] first observed that
static program analysis can be used to control such information flows, thus, statically
enforcing the policy’s requirements.
In [262] Volpano et al. formalized Denning’s approach in the form of a type-system.
This enabled them to proof the approach’s soundness. In Volpano’s model every term
carries an security level which is determined by the terms type (e.g., public or high). A
ordered lattice relationship between the individual types is modeled through subtyping,
for instance as follows:
Consequently, the security level of a term is determined by its highest value (a term
containing secret typed variables is considered to be of type secret entirely) while com-
mand typing guarantees that these levels are preserved.
Following both the general subtyping semantics as well as the intended confidentiality
objectives, it is allowed to reclassify a term to a higher level (i.e., interpret a subtype in
a supertype context). This is formalized by the subtype-rule:
Γ`e:τ ` τ ⊆ τ0
(subtype)
Γ ` e : τ0
Thus, this subtyping relationship formalizes that every term e that is typed with type τ
can also be typed with τ 0 if and only if τ is a subtype of τ 0 (i.e., public information can
be reclassified to secret).
Furthermore, Volpano et al. introduce the assignment typing rule which enforces that
all elements of an assignment of a term e to a variable v have to be of matching types:
177
12. Enforcing Secure Code Creation
typed variables (i.e., from super-types to subtypes). Therefore, such assignments cannot
be type checked and produce typing errors. Hence, the combination of the subtype and
the assignment typing rules effectively enforce Bell-LaPadula’s *-property (no write-
down) as no flows from high to low (form secret to pubic) can by type-checked.
Moreover, take the following line of code:
The indirect information flow in this code from asecret to bpublic is a violation of Bell-
LaPadula’s Simple Security-property (no read-up). Volpano’s type-system prohibits such
indirect information flows from secret to public. This is done by enforcing that all ele-
ments of program constructs which cause indirect information flow (such as conditionals)
have to be of matching type:
1. The Simple Integrity Axiom states that a subject at a given level of integrity may
not read an object at a lower integrity level (no read-down).
2. The *-Integrity Axiom states that a subject at a given level of integrity must not
write to any object at a higher level of integrity (no write-up).
These rules are the exact reverse of the Bell-LaPadula rules. Also, the interpretation
of the terms object and subject in the context of computer programs remains the same
as in the Bell-LaPadula case. Hence, by introducing type-classes for integrity level (high
and low), the subtype relationship can be defined accordingly:
high ⊆ low
This way Volpano’s typing rules can be applied to ensure integrity requirements
through type-checking. Thus, for instance, assignments from low integrity terms to high
integrity variables are prohibited in this type-system, as demanded by the *-Integrity
Axiom.
However, considering integrity as a straight dual to confidentiality is not entirely cor-
rect. As Sabelfeld and Myers warn in [227]: “Integrity has an important difference
from confidentiality: a computing system can damage integrity without any interaction
178
12.2. Introducing a specific datatype for secure code assembly
with the external world, simply by computing data incorrectly.” Therefore, strong en-
forcement of unspecific integrity properties may require proving the correctness of the
program. For this reason, the utilized definitions of the desired integrity properties have
to be chosen carefully to only include characteristics that can be ensured regardless of
program-correctness.
In the next section we will show how to utilize the duality between the Bell-LaPadula
and the Biba models for applying Volpano’s results to secure code assembly.
Applying the Biba model to dynamic code creation: We propose to apply Biba’s
integrity policies to dynamic code creation. As discussed, string-based code injection
vulnerabilities stem from interpreting data elements as code. By using integrity levels to
separate the two element classes, this type of mix-up can be prevented on the language
level. Code elements in dynamically assembled foreign statements should be of high
integrity as they are responsible for the statements semantics. However, the integrity
level of data elements should be considered to be low, as often the contents of the
elements may be controlled by the adversary.
Consequently, we introduce two new security types: DT (data-type) and CT (code-
type) which corresponded to the integrity levels low and high. More specifically, the
implicit, static mapping between the token-types and the integrity classification is the
following:
data ⇒ DT ⇒ low
code ⇒ CT ⇒ high
Applying the Biba model to this mapping enforces that low integrity information (i.e.,
data) cannot influence high integrity information (i.e., code). This results in a type-
based separation of data and code. For this purpose, we utilize the typing judgements
from [242] which prevent explicit flows from low to high (see Figure 12.3) by formalizing
the Biba model as discussed in Section 12.2.1.
Apart from to the security types we also have to add two new basic datatypes to
the native language: codetoken and datatoken. These datatypes represent the foreign
language’s corresponding syntactic elements, as specified in Section 10.4. They are
utilized to practically assemble the foreign code within the native syntax. Codetoken-
elements are implicitly typed with CT , datatoken-elements with DT .
179
12. Enforcing Secure Code Creation
CT ⊆ DT
(base) Γ ` e : τ
(r-val) Γ ` e : τ var
Γ`e:τ
τ ⊆ τ0
(cmd− )
τ 0 cmd ⊆ τ cmd
Γ`e:τ τ ⊆ τ0
(subtype)
Γ ` e : τ0
τ ⊆ τ0 τ 0 ⊆ τ 00
(trans)
τ ⊆ τ 00
Γ ` ei : τi τi ∈ {DT, CT } i ∈ 1...n
(FLET)
Γ ` F LET (e1 : τ1 , ..., en : τn )
The FLET itself is a type-preserving container. Thus, the security typing remains
unchanged through retrieval procedures:
180
12.2. Introducing a specific datatype for secure code assembly
Consequently in our model, a given foreign code statement can be regarded sequence
of code- and data-tokens which are aligned in a FLET container. Within the native
language’s syntax the FLET is represented by a corresponding flet-datatype. Hence,
our model defines the following mapping between security types and datatypes:
To show that our type system has the claimed characteristics we have to examine if
Biba’s *-Axiom is fulfilled, i.e. DT typed terms can not be utilized to define CT code.
Please note: For a complete proof of this claim we would have to take the applicable
semantics of the native language into account (as it is done for instance in [242]). As,
in the context of this section, such semantics are not available, due to the fact that it
is unspecified which native language is extended, we solely consider conditions that can
be derived from the typing-rules. The correct compliance to the typing rules have to
be enforced in the actual implementation. From now on, we assume that the regarded
native language has comparable characteristics to the language utilized in [242].
Lemma: In the given type system direct information flows from low integrity data to
high integrity code are not typable.
Proof: We examine the following assignment cases, which constitute all possible infor-
mation flows from a term e into a variable v:
The lemma’s claim is satisfied, if it is guaranteed that for all cases in which one of the
operands is typed with DT it holds that either
181
12. Enforcing Secure Code Creation
As in such cases the assignment-rule is satisfied, the term is valid typed (exemplified for
τi = CT ):
Γ ` v : CT var Γ ` e : CT
Γ ` v := e : CT cmd
Next, we show that assignments from high integrity data to low integrity variables is
typable:
vDT := eCT resulting in Γ ` v : DT var and Γ ` e : CT
CT ⊆ DT
Γ ` e : CT CT ⊆ DT
Γ ` e : DT
Thus, type inference allows the assignment if and only if the resulting term is typed DT :
Γ ` e : CT CT ⊆ DT 1
Γ ` v : DT var Γ ` e : DT 2
Γ ` v := e : DT cmd
1
: via subtype rule
2
: via assignment rule
This operation is not typable: The assignment-rule demands that both operands have
to be of matching type. Therefore, one of the operands would have to be type-casted.
Consequently, one of the following two hypothetical type inference steps would be nec-
essary: Either the v : CT var expression has to be downtyped to DT . For such a step,
no typing rule is defined. Or the e : DT term has to be casted to CT . However, the
subtype-rule allows only type-casting from subtypes to supertypes. As CT is a subtype
of DT the rule is not satisfiable.
182
12.2. Introducing a specific datatype for secure code assembly
Thus, we have shown that assignments involving both code and data elements are only
valid typable if the resulting term is of type DT. Hence, attempts to create code elements
through low integrity types, such as strings or data-tokens, cannot be typed in our type-
system. Therefore, as motivated in Section 12.2.1, in such situations a newly introduced
typing error is detected by the language’s type-checker: Insecure code assembly.
Datatokens and the native string are both typed with DT . Therefore, assignments in
both directions are allowed by the type-system, thus, enabling dynamic parametrisation
of foreign code statements (the specifics of such assignments depend on the particular
implementation that adds the new types to the native language).
Consequently, even when direct flows from the low integrity string-type to the high
integrity code-tokens are prohibited, the application logic requires the implementation
of an indirect information flow. For this reason, we explicitly allow such indirect flows
in our proposed type-system by solely enforcing one of Biba’s Axioms: the *-Integrity
Axiom (“no write-up”). Therefore, an implementation of our approach is not required
to type indirect relationships as they arise through conditionals (see above and [262]).
Nonetheless, in certain security-critical scenarios, such a non-interference property
for code assembly can be important, for instance, in the case of executing semi-trusted
code that interfaces with security sensitive external entities (e.g., a third-party weblog
plugin). In such cases, our approach can be extended analogous to Volpano’s work [262]
in order to enforce Biba’s Simple-Integrity Axiom (“no read-down”).
183
12. Enforcing Secure Code Creation
The FLET holds the assembled foreign code in the form of a sequence of code- and data-
tokens. However, before communicating with the external entities, the FLET’s content
has to be serialized back into a character-based representation suitable for the entities’
interfaces and parsers. In order to ensure the approach’s security guarantees, these serial-
ization and communication steps are realised outside the programmer-accessible, native
language features. Instead, as motivated in Section 12.1.2, the steps are implemented
safely encapsulated in the abstraction layer (see Sec. 12.4).
As initially motivated in Section 12.1.1, this methodology closely mirrors the tech-
niques of type-safe languages, such as Java, to ensure type-safety in respect to memory
allocation: Type-safe languages hide the actual memory management from the language
features. Instead, all memory related processes are implemented outside the program-
mer’s reach, safely abstracted through safe language features.
184
12.3. Language integration
Semantic APIs follow the semantics of the language’s instructions (examples of this
approach would be, for instance, the Document Object Model API [102] to create HTML-
structures or SQLDom [178] to create SQL-queries). Within this approach the API does
not mirror the structure of unparsed source code but the structure of the resulting
language object (e.g., the tree structure of a parsed HTML document). Either way,
to satisfy the security requirements that are the basis of our approach, the internal
implementation of the API has to retransform the method-calls into matching datatoken
and codetoken-elements before adding them to a flet container.
Advantages: Implementing this approach does not require any changes to the native
language or the language’s compilation/interpretation process. Therefore, it is applicable
immediately by solely implementing the API.
Example:
1 String UName = " Joe Doe ";
2 SQLQuery q = SELECT * FROM Users WHERE Name = UName ;
185
12. Enforcing Secure Code Creation
For instance, following a related approach Meijer et al. [184] extended the C# -
grammar to contain a subsets of SQL and XML. Furthermore, the ECMA standard 357
[233] specifies E4X, a related integration of XML code into JavaScript’s native syntax.
Advantages: Ideally such a solution would not require any syntactical changes in the
foreign language. Therefore, the objective to closely mimic the foreign syntax is satisfi-
able and the expected training effort that would be required by an introduction of such
a mechanism can be expected to be moderate.
Example:
1 String UName = " Joe Doe ";
2 SQLFlet q = $$ SELECT * FROM Users WHERE
3 Name = $nativeString ( UName ) $ ORDER BY ID ; $$
First steps in this direction were realized with SQLJ [6] and Embedded SQL [192],
two independently developed mechanisms to combine static SQL statements either with
Java or C respectively using a pre-processor. However, unlike our proposed approach
these techniques only allow the inclusion of static SQL statements in the source code.
The pre-processor creates native code that immediately communicates the SQL code to
the database. Thus, dynamic assembly and processing of foreign code, as it is provided
in our proposed approach via the FLET, is not possible.
186
12.4. Abstraction layer design
Advantages: By using such a mechanism the foreign language’s syntax remains un-
changed. Therefore, the expected training effort consists mainly in learning the pre-
processor’s meta-syntax.
The abstraction layer could be realized within the means of the native language. Such
an implementation would either be done by integrating the layer’s functionality in the
language’s runtime (comparable to Java’s memory management) or by implementing
a programming library. In either case, the layer provides an interface through which
an instantiated FLET is received, serialized to foreign code and communicated to the
external entity.
187
12. Enforcing Secure Code Creation
Abstraction layer: Position (I)
AL
AL
AL
Intermediate entity
Secondly, the abstraction layer could be implemented as a detached unit that resides
in between the native language’s interpreter and the external entity. In this case, the
native language translates an instantiated FLET into a language independent serializa-
tion object, that encodes the foreign instructions while maintaining the strict separation
between data and code. This object is then translated by the abstraction layer into
actual foreign code.
Advantages: Such an abstraction layer is independent from a specific native language
and is, thus, usable with any language for which a module exists that translates a FLET
into the language independent serialization format. Hence, all domain specific knowledge
concerning how to create safe foreign instructions has to be implemented only once.
Disadvantages: Realizing the abstraction layer as an intermediate entity adds com-
plexity to the installation process of an application. In addition to the native language’s
runtime and the external entity also the abstraction layer has to be deployed.
Furthermore, in this scenario an intermediate serialization step is necessary. The
FLET is first serialized into the language independent format before this format is
translated into foreign code by the abstraction layer, resulting in overhead and potential
performance penalties.
188
12.4. Abstraction layer design
Finally, the abstraction layer could be directly integrated in the external entity (e.g., into
the database’s parser). In this case, the entity’s parsing unit can employ the data/code
information provided by the FLET.
Advantages: As discussed in Section 10.3 code injection vulnerabilities occur be-
cause of the confusion between data and code portions of dynamically generated foreign
instructions. The FLET’s internal structure maintains a strict separation between in-
formation that was meant by the programmer to be executed and information that was
meant to represent data. Additionally, as no step is necessary to translate the FLET’s
information back into foreign code, potential ambiguities cannot be reintroduced. Thus,
by directly using the information concerning data/code separation provided by the FLET
the external entity’s parser can reliably avoid mistakes that lead to code injection vul-
nerabilities.
In addition to the reliable protection this approach also should provide advantages
concerning the performance of applications employing this solution: The external entity’s
parser can benefit from the FLET’s representation of the foreign code, as the FLET
already provides the information in a pre-parsed form which is comfortably transferable
into a parse tree.
Disadvantages: Implementing this approach requires profound changes in the exter-
nal interpreter’s interface and parser. While the alternative solutions discussed above
can be implemented with programming libraries or additional executables, realizing such
an integration demands changing the actual external entity, resulting in high anticipated
development costs.
Furthermore, such alteration of the external entity is not always feasible. In certain
scenarios the external entity can not be influenced by the deployer of the application.
For instance, the operator of a web application has no means to alter the web browsers
of the application’s users.
Finally, such a solution is highly specific for a certain external entity, e.g., one cer-
tain database. This circumstance is significant when changes in the deployed technology
occur, e.g., when the actual deployed database is exchanged. While a given implemen-
tation of the alternative approaches outlined above can be adapted comparatively easy,
such a change would require high development costs in the currently discussed solution
approach, unless the newly deployed database already supports the FLET’s serialization
format.
189
12. Enforcing Secure Code Creation
abstraction layer’s functionality does not rely on approximation. Utilizing the data/
code-information provided by the FLET, the abstraction layer is able to deterministi-
cally establish the correct code-context of a given data-element. Because of this knowl-
edge, the abstraction layer can choose reliably the correct encoding/mitigating strategy.
Therefore, neither false negatives, resulting in code injection problems, nor false positives
can occur.
The applicable serialization method is highly specific for the respective foreign lan-
guage. In the remainder of this section we discuss three general approaches towards
securely translating the FLET’s content into a character-based representation. Fur-
thermore, see Section 12.5.3 for an exemplified abstraction layer design concerning the
languages HTML and JavaScript.
190
12.5. Realising the concepts for HTML, JavaScript and Java
of output sanitation. In our case, there is the significant advantage that the sanita-
tion algorithm has concrete knowledge about the intended nature of the examined
code segments.
While being comparatively easy to realize, this approach has to be implemented
with great care as otherwise the application might still be vulnerable to sophisti-
cated attacks.
Metasyntax
To allow unambiguous identification of foreign HTML/JavaScript code that is meant to
be handled by the pre-processor, such code is framed by predefined syntactic markers
(based on the “$”-character). We introduce a simple metasyntax that enables the pro-
grammer to implement sophisticated code assembly within the native language. The
191
12. Enforcing Secure Code Creation
meta-syntax provides means for creating, combining, and extending foreign code blocks
(see Listing 12.2) In addition to basic foreign code assembly, the meta-syntax also offers
methods to add native data-information for flexible dynamic creation of foreign code.
In particular, the meta-method $data()$ is available to include data values from Java’s
basic datatypes (string, int, double) into the foreign code.
Due to the heterogeneous nature of the combined HTML/JavaScript grammar, the cre-
ation of Java-Script code requires special attention. The pre-processor can only distin-
guish JavaScript code from general text through the HTML-context of a particular code
fragment. An according context would either be framing <script>-tags or an attribute-
definition that expects JavaScript code inside its value, e.g., an event handler. Either
way, such a context is always limited to one specific foreign code block which is defined
by its framing syntactic markers. If the pre-processor should create JavaScript code
outside of such a context, the programmer has to communicate his intention explicitly
by employing the $+JS$-marker. Otherwise, the text would be added to the FLET as
non-executable data.
192
12.5. Realising the concepts for HTML, JavaScript and Java
Before we can discuss the specific characteristics of our implemented API we have to
revisit and slightly extend the type-system which was proposed in Section 12.2.2.
As discussed in the section on dividing language elements to be either data or code,
we identified the element-class of identifier-tokens, such as variable- or function-names.
As such elements have an impact on the BSP (see Definition 10.4), identifier-tokens are
classified to be typed as code. However, the name-value of identifier-tokens is by nature
variable (opposed to static, pre-defined names of keyword tokens) and character-based.
Thus, by introducing an API for creating identifier-tokens to the native language’s scope,
we would introduce a direct flow from the low-integrity string type (DT , i.e.,data) to
the high-integrity codetokens (CT , i.e., code). Such a flow is not typable in our current
type-system.
For this reason, we have to introduce an additional, median integrity level (medium)
with a corresponding security type IT (identifier-type).
CT ⊆ IT ⊆ DT
However, our system still prevents all flows from dynamic strings to either CT or
IT typed elements. As the Java type-system does not explicitly differentiate between
constant and dynamic strings, it is the pre-processor’s responsibility to enforce this
aspect of the type system.
193
12. Enforcing Secure Code Creation
• The primary purpose of the API is to inhibit code injection attacks. Hence, its
elements do not necessarily mirror the semantic meaning of the foreign language’s
elements.
A direct manual usage of this API by the programmer cannot be prevented. Therefore,
the API is specifically designed to prevent the implicit code-serialization of arbitrary
string-values. As a consequence, the FLET does not differentiate between trusted static
data and untrusted data that has entered the application on runtime. Such a distinction
would provide the programmer with a possible shortcut towards implicit code generation.
To design the actual API methods we strictly followed our classification of basic
language-elements which we presented in Section 10.4.2. For each of the identified basic
element-classes we added a family of methods which create corresponding token-elements
(while adding them implicitly to the FLET).
Before implementing these API methods, we established the strictest syntactic restric-
tion applying to a class’ elements. The API methods to add elements of a certain class
obey this syntactic restriction to enforce explicit code creation. For instance, a JavaScript
variable-identifier can only be composed of dashes, underscores, and alpha-numerical
characters, excluding the list of reserved keywords [57]. Consequently, a method to add
a variable-identifier to a JavaScript-FLET solely accepts a single parameter satisfying
these syntactic constraints.
194
12.5. Realising the concepts for HTML, JavaScript and Java
1. Tag-elements: For each HTML tag the FLET provides a distinct set of meth-
ods to add opening and closing tags. For example, opening tags are created
with openingTag tagname() where tagname is replaced with the actual tag (e.g.,
openingTag h1() adds a <h1> tag). By calling such a method, a corresponding
codetoken object is created and added to the FLET.
3. Text-elements: All data that is neither classified to belong in the tag- or attribute-
classes nor meant to represent JavaScript-code (including HTML entities) is consid-
ered to be general text. Such elements are created with the method addText(String
text) and added as corresponding datatokens to the FLET.
195
12. Enforcing Secure Code Creation
4. Data: String and numeric datatoken elements are added to the FLET with
the functions addJSStringValue(String val) and addJSNumericValue(Double
val) respectively.
196
12.5. Realising the concepts for HTML, JavaScript and Java
Method Purpose
FLETIterator SearchDataSegment(String e) Searches the data-portion of the FLET for e
FLETIterator SearchForSubFLET(HTMLFlet f) Searches the FLET for occurrences of f
HTMLFlet split(FLETIterator it) Splits the FLET at the position indicated by it
HTMLFlet append(HTMLFlet f) Appends the FLET f
values that are encoded this way are still handled/displayed correctly, the encoding re-
liably causes the entity to treat such data as non-executable. Depending on the actual
context a given element appears in an HTML page, a different encoding technique has
to be employed to avoid injection attacks. As an instantiated FLET has detailed knowl-
edge on the foreign code’s semantic structure, the abstraction layer is able to reliably
determine the given code context. More specifically, there are three applicable, distinct
code contexts:
197
12. Enforcing Secure Code Creation
URL referencing a resource belonging to the original web application. In this case,
the complete URL-value gets encoded.
In order to assemble the final HTML output the abstraction layer iterates through
the FLET’s elements to receive the actual foreign code information in combination with
the applicable context. According to the given code-context the matching encoding
technique is applied to transform all data-values into a non-executable form.
198
12.6. Implementation and evaluation
Implementing the abstraction layer in the form of a J2EE filter has several advan-
tages. Foremost, no changes to the actual application-server have to be applied - all
necessary components are part of a deployable application. Furthermore, to integrate
our abstraction layer into an existing application only minor changes to the application’s
web.xml meta-file have to be applied (besides the source code changes that are discussed
in Section 12.6.2).
199
12. Enforcing Secure Code Creation
Response Time
CPU Usage
60
in ms
in %
30
40
20
20 10
0 0
5 10 25 50 75 100 150 200 5 10 25 50 75 100
Users Users
intermixes HTML and Java code within a single file. Before its interpretation, the ap-
plication server compiles the JSP into a standard Java servlet on the fly. We created
an additional pre-processor which aided the transformation of the JSP-markup into our
meta-syntax (see Sec. 12.5.1) in a semi-automatic fashion. Furthermore, the application’s
JSPs frequently include custom markup-tags which are realized using J2EE’s tag library
mechanism (“Taglib”). The porting of the Taglib-tag’s implementation from string-
based to FLET-based code creation was unproblematic. However, our FletFilter-
implementation had to be changed slightly to allow the correct interpretation of situa-
tions in which a certain code context (e.g. a single HTML-tag) was composed by several
separate Taglib-elements.
After these extensions had been made, the actual porting process was surprisingly
straightforward. JSPWiki’s user-interface follows in most parts a rather clean version of
the Model-View-Controller (MVC) pattern [156] which aided the porting process. Be-
sides the user-interface also the application’s Wiki-markup parser and
HTML-generator had to be adapted. It took a single programmer about a week to
port the application’s core functionality. In total 103 source files had to be processed.
As expected, all documented XSS vulnerabilities [157] did not occur in the resulting
software. This resolving of the vulnerabilities was solely achieved by the porting process
without specifically addressing the issues in particular.
Performance measures
The concluding evaluation step was to examine the runtime overhead that is introduced
by our approach. For this purpose, we benchmarked the unaltered JSP code against the
adapted version utilizing the FLET paradigm. The performance tests were done using
the HP LoadRunner [104] tool, simulating an increasing number of concurrent users per
test run. The benchmarked applications were served by an Apache Tomcat 5.5.20.0 on
a 2,8 GHz Pentium 4 computer running Windows XP Professional.
In situations with medium to high server-load, we observed an overhead of approx-
imately 25% in the application’s response times (see Figure 12.5). Considering that
neither the FLET’s nor the abstraction layer’s implementation have been specifically
optimized in respect to performance, this first result is promising. Besides streamlining
the actual FLET implementation, further conceptual options to enhance the implemen-
tation’s performance exist. For instance, integrating the abstraction layer directly into
200
JavaServer Pages
12.7. Conclusion
the application server, instead of introducing it via object wrappers would aid the overall
performance.
12.6.3. Limitations
Our proposed solution reliably prevents XSS vulnerabilities which occur because of pro-
gramming errors made in the native language. However, there are certain classes of XSS
issues that arise due to causes which cannot be controlled by the discussed approach.
Foremost, this applies to all XSS problems that are rooted at the client-side because
of unsafe written JavaScript, e.g. issues based on unsafe dynamic code creation via
eval(), or DOM based XSS [153]. Furthermore, vulnerable browser configurations can
cause so called “universal XSS”-conditions [206]. In such situations, all web applications
displayed in the affected browser are susceptible to XSS attacks. A related problem
may also occur if the web server itself causes XSS problems, e.g., the “expect-header”-
vulnerability of the Apache web server [284]. Finally, there are several rich data formats
like Flash or Java Applets that may carry JavaScript code. If an application allows their
users to include such objects from external sources into the application’s pages these
objects may penetrate the application security.
12.7. Conclusion
In this section we proposed techniques to enhance programming languages with capabili-
ties for secure creation of foreign code. Our approach is based on a generalized model that
introduces an abstraction layer which prevents direct string-based code-communication
between the programming language’s runtime environment and potential external enti-
ties. Furthermore, we showed how a language pre-processor and a dedicated datatype
201
12. Enforcing Secure Code Creation
can be employed to outfit a given programming language with means for secure creation
of foreign code. The centerpiece of our code assembly architecture is the FLET (see
Sec. 12.2), an abstract datatype that allows the assembly and processing of foreign code
segments while strictly preserving the separation between data and code. This way,
injection vulnerabilities that are introduced by implicit, string-serialization based code-
generation become impossible. To examine the feasibility of the proposed approach, we
implemented an integration of the foreign languages HTML and JavaScript into the Java
programming language.
Usage of our approach results in a system in which every creation of foreign code is
an explicit action. More specifically, the developer always has to define the exact par-
ticularities of the assembled code precisely. Therefore, accidental inclusion of adversary-
provided semantics is not possible anymore. Furthermore, the only way to assemble
foreign code is by FLET, which effectively prevents programmers from taking insecure
shortcuts. Thus, our solution provides better protection as related approaches, such as
precise taint-propagation. A wide adoption of our proposed techniques would reduce the
attack surface of code injection attacks significantly.
202
Part IV.
203
13. Related Work
We divided the set of existing related work in four general categories: First we discus
approaches which were designed to address specific XSS Payloads (see Sec. 13.1), com-
parable to the work presented in Part II of this thesis. Then, we examine defensive
techniques which aim to prevent XSS attacks in general without focusing on specific
payload types (see Sec. 13.2). The approaches that are subsumed in this section have
in common that they are based on specific characteristics of XSS and cannot be easily
extended towards the general class of string-based code injection issues. Consequently,
in Section 13.3, we document approaches which are capable to address a broader range of
string-based code injection types. Finally, we conclude this chapter in Section 13.4 with
an overview of language-based approaches that, while not being specifically targeted to
prevent XSS or string-based code injection, share significant similarities with our work
presented in Chapter 12.
If applicable, we compare to our proposed techniques with the approaches documented
in this chapter.
205
13. Related Work
Furthermore, Vogt et al. [261] propose a combination of static analysis and dynamic
data tainting to stop the effects of XSS attacks. The outlined approach does not iden-
tify or stop the actual injected script but instead aims to prohibit resulting leakage of
sensitive information. To achieve this, their technique employs an enhanced JavaScript
engine. The added features of this modified engine are twofold: For one, the flow of sen-
sitive data, like cookie-values, through the script can be tracked dynamically. This way
the mechanism detects and prevents the transmission of such data to the adversary. Fur-
thermore, via static analysis, all control flow dependencies in scripts that handle sensitive
information are established. This is done to identify indirect and hidden channels that
could be abused for data leakage. If such channels are identified, their communication
with external hosts is prevented.
Livshits and Erlingsson propose in [169] to extend the Same Origin Policy using a
novel HTML-attribute. Using this attribute can create isolated parts within a DOM
tree that have only access rights to their respective child-elements within the DOM tree.
If an XSS injection point exists in such a constraint area, the injected script can only
access and alter a very restricted set of the attacked webpage’s elements. Thus, e.g., only
values which are located within the reach of the script can be leaked to the attacker.
Furthermore, several alternatives and enhancements in respect to the form-based com-
munication of passwords have been made, such as [223], [228], [240], or [159]. Most of
these techniques were designed to prevent phishing attacks in general and were not specif-
ically targeted at XSS attacks. However, some of them provide protection against certain
forms of XSS based password theft. See [105] for an overview and detailed discussion of
this matter.
All approaches which have been listed in this section prevent the attacker from ob-
taining sensitive information. However, some of the papers also claim that they prevent
session hijacking attacks. This is only partially the case. The discussed techniques are
only capable to prevent a limited subset of all session hijacking attacks – the class of
SID theft attacks. But, as discussed in Section 4.1, both browser hijacking attacks and
background XSS propagation are potentially as powerful as SID theft. In comparison,
our proposed countermeasure (see Chapter 7) protects against all documented variants
of session hijacking attacks. However, the here discussed techniques are well suited to
serve as complementary techniques to our approach.
206
13.1. Mitigation of XSS Payloads
to the URLs, thus effectively creating URL pseudonyms. For this purpose, they intro-
duced a server-side web-proxy to apply the randomized components to the application’s
URL transparently.
To defend against cross-site timing attacks, (see Sec. 5.2.2), Bortz et al. [23] proposed
a server-side module to ensure that the web server always takes a constant amount of
time to process a request. For this purpose they implemented an Apache module called
“mod timepad”. “Mod timepad” functions by guarantying that every HTTP chunk is
sent a time since the request was received which is a multiple of n milliseconds (with n
being a user-adjustable parameter).
Furthermore, following our work in [133] (see Chapter 8), CSRF attacks have received
further attention.
Jovanovic et al. describe in [137] NoForge, a server-side proxy solution, which is
closely related to the technique we proposed in Chapter 8. By automatic addition
of request-nonces to outgoing HTML content, NoForge verifies that incoming requests
which belong to an existing session were indeed generated within the application. The
OWASP CSRFGuard [202] implements Jovanovic’s technique as a J2EE filter.
Two browser extensions for the Firefox browser aim to provide automatic protection
against CSRF attacks. For one, the NoScript-extension [175] strips all POST-parameters
from cross-site POST requests, thus, rendering the majority of CSRF attacks useless.
Furthermore, Zeller and Felton [286] implemented an experimental browser extension
which prevents cross-site POST requests completely.
Finally, Barth et al. [15] propose the introduction of an additional, mandatory origin
HTTP-header for HTTP requests. This header contains origin-information about the
webpage which caused the corresponding HTTP request, namely the protocol, the
domain-value, and the port. The origin-header is only sent with POST-requests. This
way the origin-header addresses the privacy problems of the referer-header while still
containing all necessary information to reliably counter CSRF attacks.
207
13. Related Work
208
13.2. Dynamic detection and prevention of XSS attacks
requests. Spectator consists of an HTTP proxy inspecting the Traffic between the user’s
browser and a web server in order to detect malicious patterns of JavaScript code propa-
gation. By applying unique and persistent labels to incoming HTML fragments, the flow
of these fragments through the application over the course of multiple request/response-
pairs is possible. Thus, Spectator is capable to spot reoccurring labels which are in-
voluntarily transported by worm traffic. While the proposed mechanism is capable to
identify worm outbreaks, it cannot detect single, targeted XSS attacks as the mecha-
nism’s algorithm relies on associating a series of request.
Finally, the NoScript-plugin for Firefox [175] provides a simple detection mechanism
for reflected XSS: Outgoing HTTP parameters are checked if they potentially contain
JavaScript code. If such parameters are detected, the plugin warns the user before
sending the respective HTTP request.
209
13. Related Work
an open source web application firewall specific for the Apache web server that allows
detailed analysis and modification of incoming HTTP requests. Besides these examples,
further web application firewalls exist in the market place. Generally, WAFs can seldom
provide more than additional input validation mechanisms, as they do not possess any
knowledge about the application’s internals. The provided protection is therefore seldom
complete.
210
13.3. Detection and prevention of string-based code injection vulnerabilities
The here discussed approaches are in general related to the presented topics of Part III
of this thesis.
211
13. Related Work
use interpreters that were written in C. To protect an interpreted application against in-
jection attacks the application has to be executed by a recompiled interpreter. Based on
dynamic taint propagation, Su and Wassermann [248] describe an approach that utilizes
specifically crafted grammars to deterministically identify SQL injection attempts.
However, taint-tracking is not without problems: Taint-tracking aims to prevent the
exploitation of injection vulnerabilities while their fundamental causes, string-based code
assembly and the actual vulnerable code, remain unchanged. Therefore, the sanitazion
of the tainted data still relies on string operations. The application has to “untaint” data
after applying manually written validation and encoding function, a process which in
practice has been proven to be non-trivial and error-prone. This holds especially true in
situations where limited user-provided code, for instance HTML, is permitted. E.g., no
taint-tracking solution would have prevented the myspace.com XSS that was exploited
by the Samy-worm [140]. In our approach, even in cases where user-provided HTML
is allowed, such markup has to be parsed from the user’s data and recreated explicitly
using FLET semantics, thus, effectively preventing the inclusion of any unwanted code.
Furthermore, unlike our FLET approach, taint-tracking is susceptible to second-order
code injection vulnerabilities [200] due to its necessary classification of data origins as
either trusted or untrusted. In the case of second-order code injection the attacker is able
to reroute his attack through a trusted component (e.g., temporary storage of an XSS
attack in the database).
Boyd and Keromytis propose SQLrand [25] which uses instruction set randomization to
counter SQL injection attacks. All SQL statements that are included in the protected
application are modified to include a randomized component. Between the application
and the database a proxy mechanism is introduced that parses every query using the
modified instruction set. As the attacker does not know the correct syntax, a code in-
jection attack will result in a parsing error. SQLrand requires the programmer of the
application to permanently include the randomized syntax in the application’s source
code. Therefore, as the randomization is static, information leaks like SQL error mes-
sages might lead to disclosure of the randomized instruction set. In comparison, our
related approach (see Chapter 11) uses dynamic string masks which change with every
processed HTTP request. Therefore, information leaks do not pose a problem.
Finally, in this section we collect language based techniques which were not specifically
developed to prevent string-based code injection but still expose similarities to our FLET
approach (see Chapter 12).
212
13.4. Language based approaches
213
13. Related Work
properties, such as retrieval (SQL) and processing (XML). For this reason, a straight for-
ward extension to general imperative language features is not possible. In comparison,
our FLET approach is capable of achieving complete coverage of all foreign language
features regardless of the foreign language’s nature.
214
14. Conclusion
We conclude this thesis with a summary of our main results, a discussion of the remaining
open problems, and an outlook.
14.1. Summary
We structure the discussion into three segments which mirror the three main parts of
the thesis: XSS & XSS Payloads, mitigation of XSS exploits, and prevention of XSS
vulnerabilities.
XSS vulnerabilities: The specifics of individual XSS vulnerabilities are diverse and
potentially complex. They are determined by factors such as type (reflected, stored,
DOM based), injection constraints, or injection position. Furthermore, as we doc-
umented in Chapter 2, XSS vulnerabilities can be caused by insecure programming
as well as by insecure infrastructure (see Sec. 2.1). In particular, vulnerable sce-
narios caused by insecure infrastructure can involve a highly heterogeneous set of
causing components, such as web proxies or browser plug-ins. Finally, XSS is not
limited to web applications but also can affect other technologies (see Sec. 2.3),
resulting in a significant attack surface.
XSS Payloads: An XSS vulnerability enables the attacker to execute arbitrary Java-
Script code within the victim’s browser. To assess the severity of such a vulner-
ability, it is crucial to thoroughly examine JavaScript’s capabilities which can be
utilized in XSS Payloads.
For this purpose, we identified a set of general attack techniques (see Sec. 3.3) and
introduced a comprehensive and systematic classification of potential XSS Pay-
loads (see Sec. 3.4). Our proposed classification is based on dividing the potential
actions of a given JavaScript according to a disjunct set of execution-contexts.
This enabled us to group individually reported attacks into larger classes and to
identify the set of existing payload targets, such as the affected web application,
the victim’s computer, or intranet resources.
215
14. Conclusion
The results of this part of the thesis lead to the conclusion that XSS poses a signifi-
cant and complex problem involving a wide and versatile set of causing circumstances,
involved technologies, and attack targets. Due to the heterogeneous nature of this vul-
nerability class, the discovery of a comprehensive, uniform approach to address the
problem seems unlikely. Consequently, based on this outcome we deducted two gen-
eral, complementary defensive approaches: Countering the actions of XSS Payloads and
fundamentally preventing XSS on the source code level.
• As already stated in the introduction to Part III, XSS problems which are caused
by insecure programming account for the dominant amount of XSS issues.
216
14.1. Summary
• Finally, this bug pattern is not specific for XSS. Instead, several other wide-spread
code-based vulnerability types expose the same cause, e.g., SQL injection or direc-
tory traversal.
Consequently, we widened our attention to the more general vulnerability type – the
class of string-based code injection vulnerabilities. Such vulnerabilities occur because of
a confusion of data- and code-information during application programming. While pro-
gramming application components which dynamically assemble foreign language code,
such as HTML or SQL, the programmer involuntarily creates insecure conditions. This
results in cases in which information that is regraded to be data may end up in a syn-
tactical code context. Hence, to fundamentally solve this problem, an investigation of
methods to reliably separate data from code is required.
This observation exposed the necessity to clearly define the general terms data and
code in the context of foreign syntax assembly. For this purpose, we specified a set of
criteria (see Sec. 10.4.1) which can be applied to a given computer language in order
to map the identified syntactic language elements to represent either data-information
or code-elements. Then, we exemplified the usage of these criteria by applying them
to three common language classes: General purpose programming languages, mark-up
languages, and resource specifiers (see Sec. 10.4.2).
We utilized our proposed data/code-classification of language-elements twofold: For
one, in Chapter 11, we showed how to create a mechanism which detects on runtime
the injection of adversary controlled code-elements into foreign syntax statements. We
achieved this by locating legitimate code-elements before program execution and syn-
tactically marking them with secret string-masks. As the adversary does not know the
utilized string-masks, he is not able to inject correctly masked code-elements. Hence,
our technique is capable to detect and disarm injected code-elements before sending the
foreign syntax to the external interpreter.
Furthermore, we showed that the string type is not suited for run-time assembly of
foreign syntax (see Sec. 10.3). The string type does not provide sufficient capabilities
to separate data- from code-elements. Consequently, in Chapter 12, we proposed the
introduction of a novel datatype which is specifically designed for code assembly – the
Foreign Language Encapsulation Type (FLET). The FLET is a container type which
encapsulates a sequence of foreign language tokens. These token elements carry an
integrity type, which marks them to be either data-, identifier-, or code-elements. To
deterministically enforce a secure separation between these integrity classes, we specified
a set of typing rules which apply the BIBA integrity model to the token elements (see
Sec. 12.2). By mapping data-tokens to be of low-integrity and code-tokens to be of high-
integrity, the proposed type system extension reliably prevents information flows from
low to high integrity elements and, thus, the insecure interpretation of data as code.
Using a specific implementation target, the languages Java (native) and HTML/-
JavaScript (foreign), we demonstrated how to utilize this approach. In this context,
217
14. Conclusion
we examined further key aspects which are necessary for our approach to be usable in
practice. More precisely, for one we explored the integration of the foreign syntax into
the native language (see Sec. 12.3). Furthermore, we discussed the design of an abstrac-
tion layer which is responsible for interacting with the external interpreter by securely
translating the FLET into foreign code (see Sec. 12.4).
By means of our FLET-based approach, we have shown that practical separation
between data and code during foreign code assembly is feasible and, hence, provides
reliable, fundamental prevention of string-based code injection vulnerabilities.
218
14.2. Future work and open problems
security depends on an outside entity which cannot be controlled by the application itself.
This fact leads to the discussed DNS rebinding vulnerabilities (see Sec. 3.3.4). In turn
DNS pinning, which was introduced to counter rebinding attacks, introduces problems
with dynamic DNS services and DNS based redundancy solutions. Furthermore, DNS
pinning is unable to protect against multi-session attacks as they have been described
by Soref [245] and Rios [220].
219
14. Conclusion
ter 6). Our proposed solution (see Chapter 9) works well in situations where a boundary
between local and remote network location is clearly defined. However, in some cases
the distinction between these two classifiers is blurry, for example within large internal
networks which include several departments of a single company. In such cases, it is not
always obvious which cross-domain requests are legitimate. Hence, further research is
needed to design flexible and fine-grained methods to securely handle such situations.
Furthermore, for the time being, the attacked server has only very limited capabilities
to notice the attack, such as checking referrer- or host-headers. Consequently, the devel-
opment of detection techniques targeted at the documented attacks could improve the
security of intranet resources.
Enforcing further constraints: The FLET encapsulates the foreign code in a partially
processed state. Depending on the FLET’s actual implementation this state might, for
example, resemble a token stream or an abstract syntax tree. In any case, the FLET pro-
vides better means towards an automatic processing of the foreign code than the general
string-datatype. This could be employed to globally enforce further constraints on the
foreign code. For example, the well-formedness of dynamically created XML documents
could be verified before passing them on to the external entity. Also, depending on the
execution context, the FLET could restrict the set of legal code-keywords and APIs to
a “safe” subset. For instance, this way third party add-ons/plug-ins to the application
can be restricted by an SQL-FLET to use only non-altering database operations like
select-statements.
Furthermore, in addition to enforcing restrictions on the foreign code, the FLET
could also be employed to transparently extend the foreign code. For example, an
220
14.2. Future work and open problems
HTML-FLET could automatically add hidden one-time tokens into HTML forms to
avoid CSRF-issues.
221
14. Conclusion
taken place. By monitoring potential malicious activities this way, the application’s
operators can identify sources of malicious behaviour like suspicious user accounts or
compromised network locations.
Templates in web applications: Most mature web application frameworks provide file-
formats which allow the separation of the program’s logic from the application’s inter-
face as it can be found in Model-View-Controller architectures [156]. Such templating-
formats usually combine static HTML-code with well defined insertion points. These
insertion points are filled with dynamic data during execution. Popular examples of
such templating-mechanisms are J2EE’s JSPs [253], or Ruby-on-Rail’s rhtml-format
[100]. In addition, many applications, such as content management systems, implement
application-specific templating mechanisms of their own.
Creating a templating-engine that conforms to our concept’s fundamental objectives
and type-safety constraints is not trivial. This holds especially true, if the actual
templates are dynamically retrieved from files or the database, as it is the case with
custom, application-specific templating mechanisms. In such cases, an unsophisticated
templating-implementation might reintroduce implicit code-serialization by allowing the
creation of foreign code from strings that, for instance, are stored in files. Consequently,
this could provide careless programmers with an insecure shortcut towards foreign code
assembly by reading their foreign code from dynamically created files.
14.3. Outlook
The web application paradigm is still evolving. Both JavaScript and HTML are under
active development. Web browsers recently started to implement HTML 5 [58], the next
major version of the language. New language elements, such as canvas, and extended
capabilities, such as cross-domain HTTP requests or persistent client-side storage, may
grant the adversary new capabilities. Therefore, existing and proposed countermeasures
have to be continuously reevaluated whether they still function given the current state
of the technology. Also, the novel capacities may lead to the development of currently
unknown XSS Payloads.
However, the methodologies discussed in this thesis remain valid for new attacks: For
one, the underlying approach of our payload classification (segmentation of execution-
contexts and identification of attack targets through URL schema iteration) is inde-
pendent from actual language features and, hence, can be applied to assess freshly dis-
covered payload types. Furthermore, our general methodology of Part II to develop
payload-specific mitigation can be utilized to create suiting countermeasures.
Also, the attack surface of XSS attacks is directly related to the number of existing
XSS vulnerabilities in deployed applications. Thus, a wide adaption of our FLET-based
technique for reliably secure foreign code assembly would cause a significant reduction
of this attack surface.
Consequently, this thesis’ contributions can provide crucial leverage to address the
pressing problem of XSS.
222
Part V.
Appendix
223
A. Graphical Representation of the XSS
Payload Classification
In addition to the information given in Section 3.4, this section provides a graphical
representation of the classified JSDAs in the application context. For further details
please refer to Section 3.4 and Chapter 4.
225
A. Graphical Representation of the XSS Payload Classification
Static Dynamic
Statefull
Attack-target browser browser
web apps
properties properties
226
A.3. Computer context
localhost
Attack-target localhost Installed
http Filesystem
ACSII network applications
servers
services
227
A. Graphical Representation of the XSS Payload Classification
Attack-type
Confidentiality State Confidentiality State Confidentiality
228
A.5. Internet context
Attack-type State
Confidentiality Confidentiality State Confidentiality
229
A. Graphical Representation of the XSS Payload Classification
230
Bibliography
[1] Ben Adida. The Browser as a Secure Platform for Loosley Coupled, Private-Data
Mashups. In Web 2.0 Security & Privacy 2007 (W2SP 07), May 2007.
[2] Adobe Acrobat Developer Center. JavaScript for Acrobat. [online], http://www.
adobe.com/devnet/acrobat/javascript.html, (08/08/08), 2008.
[3] Adobe Coperation. Adobe flash. [online] http://www.adobe.com/products/
flash/flashpro/.
[4] Wade Alcorn. Inter-protocol communication. Whitepaper, http://www.
ngssoftware.com/research/papers/InterProtocolCommunication.pdf,
(11/13/06), August 2006.
[5] Wade Alcorn. Inter-Protocol Exploitation. Whitepaper, NGSSoftware Insight
Security Research (NISR), http://www.ngssoftware.com/research/papers/
InterProtocolExploitation.pdf, March 2007.
[6] American National Standard for Information Technology. ANSI/INCITS 331.1-
1999 - Database Languages - SQLJ - Part 1: SQL Routines using the Java (TM)
Programming Language. InterNational Committee for Information Technology
Standards (formerly NCITS), September 1999.
[7] Yair Amit. Google Desktop Cross-Site Scripting Weakness. Security Advisory,
[online], http://www.securityfocus.com/bid/22650 (01/20/08), February 2007.
[8] Chris Anley. Advanced SQL Injection In SQL Server Applications. Whitepaper,
http://www.ngssoftware.com/papers/advanced sql injection.pdf, 2002.
[9] Apache HTTP Server Documentation Project. Security Tips for Server Configura-
tion. [online], http://httpd.apache.org/docs/1.3/misc/security tips.html,
(12/12/08).
[10] Apple Developer Connection. Developing Dashboard Widgets. [online], http:
//developer.apple.com/macosx/dashboard.html, (08/08/08), February 2007.
[11] Maksymilian Arciemowicz. Bypass XSS filter in PHPNUKE 7.9. mailing list
Bugtraq, http://www.securityfocus.com/archive/1/419496/30/0/threaded,
December 2005.
[12] Ken Ashcroft and Dawson Engler. Using Programmer Written Compiler Exten-
sions to catch security holes. In IEEE Symposium on Security and Privacy, pages
143–159, May 2002.
231
Bibliography
[14] A. Baratloo, N. Singh, and T. Tsai. Transparent run-time defense against stack
smashing attacks. In USENIX Annual Technical Conference, 2000.
[15] Adam Barth, Collin Jackson, and John C. Mitchell. Robust Defenses for Cross-Site
Request Forgery. In CCS’09, 2009.
[18] Tim Berners-Lee and Robert Cailliau. WorldWideWeb: Proposal for a HyperText
Project. [online], http://www.w3.org/Proposal, 1990.
[19] Tim Berners-Lee, Larry Masinter, and Mark McCahill. Uniform Resource Locators
(URL). RFC 1738, http://www.faqs.org/rfcs/rfc1738.html, December 1994.
[20] Jean Berstel and Luc Boasson. XML grammars. In Mathematical Foundations of
Computer Science 2000, Bratislava, Lect. Notes Comput. Sci. 1893, pages 182–191.
Springer, 2000.
[21] Kenneth J. Biba. Integrity Considerations for Secure Computer Systems. Technical
Report MTR-3153, Mitre Corporation, April 1977.
[22] Blwood. Multiple XSS Vulnerabilities in Tikiwiki 1.9.x. mailing list Bugtraq, http:
//www.securityfocus.com/archive/1/435127/30/120/threaded, May 2006.
[23] Andrew Bortz, Dan Boneh, and Palash Nandy. Exposing Private Information by
Timing Web Applications. In WWW 2007, 2007.
[24] David Boswell, Brian King, Ian Oeschger, Pete Collins, and Eric Murphy. Creating
Applications with Mozilla. O’Reilly Media, September 2002.
[25] Stephen W. Boyd and Angelos D. Keromytis. SQLrand: Preventing SQL Injection
Attacks. In Proceedings of the 2nd Applied Cryptography and Network Security
(ACNS) Conference, 2004.
[27] Jesse Burns. Cross Site Request Forgery - An introduction to a common web ap-
plication weakness. Whitepaper, https://www.isecpartners.com/documents/
XSRF Paper.pdf, 2005.
232
Bibliography
[28] David Byrne. Anti-DNS Pinning and Java Applets. Posting to the Bugtraq mailing
list, http://seclists.org/fulldisclosure/2007/Jul/0159.html, July 2007.
[29] David Byrne. Intranet Invasion Through Anti-DNS Pinning. Talk at the Black
Hat 2007 conference, August 2007.
[30] Luca Cardelli. ”Type systems” in The Computer Science and Engineering Hand-
book, chapter 97. CRC Press, 2nd edition, February 2004.
[31] Rob Carter. Local Web Servers Are Dangerous. [online], http:
//r00tin.blogspot.com/2008/03/local-web-servers-are-dangerous.html,
(04/25/08), March 2008.
[34] Steve Champeon. JavaScript: How Did We Get Here? [online], http://www.
oreillynet.com/pub/a/javascript/2001/04/06/js history.html (02/20/09),
June 2001.
[35] H. Chen and D. Wagner. MOPS: an Infrastructure for Examining Security Prop-
erties of Software. In Proceedings of the 9th ACM Conference on Computer and
Communication Security (CCS ’02), October 2002.
[36] B. Chess and G. McGraw. Static Analysis for Security. IEEE Security & Privacy,
Nov/Dec, 2004.
[37] Brian Chess, Yekaterina Tsipenyuk O’Neil, and Jacob West. JavaScript Hi-
jacking. [whitepaper], Fortify Software, http://www.fortifysoftware.com/
servlet/downloads/public/JavaScript Hijacking.pdf, March 2007.
[38] T. Chiueh and F. Hsu. RAD: A compile-time solution to buffer overflow attacks.
In IEEE International Conference on Distributed Computing Systems, 2001.
[39] Steve Christey and Robert A. Martin. Vulnerability Type Distributions in CVE,
Version 1.1. [online], http://cwe.mitre.org/documents/vuln-trends/index.
html, (09/11/07), May 2007.
[40] James Clark and Murata Makoto. RELAX NG. OASIS Specification, http://www.
oasis-open.org/committees/relax-ng/spec-20011203.html, December 2001.
[41] Andrew Clover. CSS visited pages disclosure. Posting to the Bugtraq mailing list,
http://seclists.org/bugtraq/2002/Feb/0271.html, February 2002.
233
Bibliography
[44] William R. Cook and Siddhartha Rai. Safe Query Objects: Statically Typed
Objects as Remotely Executable Queries. In Proc. of the International Conference
on Software Engineering (ICSE 2005), pages 97–106, 2005.
[45] Crispan Cowan, Calton Pu, Dave Maier, Jonathan Walpole, Peat Bakke, Steve
Beattie, Aaron Grier, Perry Wagle, Qian Zhang, and Heather Hinton. StackGuard:
Automatic adaptive detection and prevention of buffer-overflow attacks. In Proc.
7th USENIX Security Conference, pages 63–78, San Antonio, Texas, jan 1998.
[46] Crispin Cowan, Matt Barringer, Steve Beattie, Greg Kroah-Hartman, Mike
Frantzen, and Jamie Lokier. Format guard: Automatic protection from printf
format string vulnerabilities. In Proceedings of the 10th USENIX Security, 2001.
[47] Crispin Cowan, Steve Beattie, John Johansen, and Perry Wagle. PointGuard:
Protecting Pointers from Buffer Overflow Vulnerabilities. In 12th USENIX Security
Symposium, 2003.
[48] D. Crockford. The application/json Media Type for JavaScript Object Notation
(JSON). RFC 4627, http://www.ietf.org/rfc/rfc4627.txt, July 2006.
[50] Akim Demaille, Joel E. Denny, and Paul Egger (maintainers). Bison - GNU parser
generator. Software, http://www.gnu.org/software/bison/.
[52] Rachna Dhamija and J.D. Tygar. The Battle Against Phishing: Dynamic Security
Skins. In Symposium On Usable Privacy and Security (SOUPS) 2005, July 2005.
[53] T. Dierks and C. Allen. The TLS Protocol Version 1.0. RFC 2246, http://www.
ietf.org/rfc/rfc2246.txt, January 1999.
[55] Thai N. Duong. Zombilizing the browser via Flash player 9. talk at
the VNSecurity 2007 conference, http://vnhacker.blogspot.com/2007/08/
zombilizing-web-browsers-via-flash.html, August 2007.
234
Bibliography
[56] D.Wagner, J. Foster, E. Brewer, and A. Aiken. A first step towards automated
detection of buffer overrun vulnerabilities. In Proceedings of NDSS 2000, 2000.
[59] F. Ellermann. The ’news’ and ’nntp’ URI Schemes. Draft RFC, http://tools.
ietf.org/html/draft-ellermann-news-nntp-uri-11, April 2008.
[60] David Endler. The Evolution of Cross-Site Scripting Attacks. Whitepaper, iDe-
fense Inc., http://www.cgisecurity.com/lib/XSS.pdf, May 2002.
[61] Ulfar Erlingsson, Benjamin Livshits, and Yinglian Xie. End-to-end Web Applica-
tion Security. In Proceedings of the 11th Workshop on Hot Topics in Operating
Systems (HotOS’07), May 2007.
[64] Hiroaki Etoh. GCC extension for protecting applications from stack-smashing
attacks. [software], http://www.research.ibm.com/trl/projects/security/
ssp/.
[65] F-Secure. Yamanner - JavaScript worm that targets Yahoo! Mail. [online], http:
//www.f-secure.com/weblog/archives/00000899.html, (04/18/08), June 2006.
[66] David C. Fallside and Priscilla Walmsley. XML Schema. W3C Recommendation,
http://www.w3.org/TR/xmlschema-0, October 2004.
[67] Sacha Faust. LDAP Injection. Whitepaper, SPI Dynamics, Inc., http://www.
dsinet.org/files/textfiles/LDAPinjection.pdf, 2003.
[68] Renaud Feil and Louis Nyffenegger. Evolution of cross site request forgery attacks.
Journal in Computer Virology, 4(1):61–71, February 2007.
[69] Kenneth Feldt. Programming Firefox: Building Rich Internet Applications with
XUL. O’Reilly Media, April 2007.
235
Bibliography
[70] Edward W. Felten and Michael A. Schneider. Timing Attacks on Web Privacy. In
Proceedings of the 9th ACM Conference on Computer and Communication Security
(CCS ’02), 2000.
[71] Dave Ferguson. Netflix.com XSRF vuln. Posting to the Web Se-
curity Mailinglist, http://www.webappsec.org/lists/websecurity/archive/
2006-10/msg00063.html, October 2006.
[72] Kevin Fernandez and Dimitris Pagkalos. XSSed.com - XSS (cross-site script-
ing) information and vulnerabile websites archive. [online], http://xssed.com
(03/20/08).
[73] Abe Fettig. Twisted Network Programming Essentials. O’Reilly, first edition,
October 2005.
[75] David Flanagan. JavaScript: The Definitive Guide. O’Reilly, 4th edition, Novem-
ber 2001.
[78] Tom Gallagher, Bryan Jeffries, and Lawrence Landauer. Hunting Security Bugs.
Microsoft Press, 2006.
[79] Vladimir Gapeyev and Benjamin C. Pierce. Regular Object Types. In Euro-
pean Conference on Object-Oriented Programming (ECOOP), Darmstadt, Ger-
many, 2003.
[82] James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Spec-
ification. Addison-Wesley, third edition, 2005.
[83] Roger A. Grimes. MySpace password exploit: Crunching the numbers (and let-
ters). [online], http://www.infoworld.com/article/06/11/17/47OPsecadvise
1.html (07/01/08), November 2007.
236
Bibliography
[84] Jeremiah Grossman. Cross-Site Tracing (XST) - The New Techniques and
Emerging Threats to Bypass Current Web Security Measures Using Trace
and XSS. Whitepaper, http://www.cgisecurity.com/whitehat-mirror/
WhitePaper screen.pdf, January 2003.
[85] Jeremiah Grossman. Cross-Site Scripting Worms and Viruses - The Impend-
ing Threat and the Best Defense. whitepaper, http://www.whitehatsec.com/
downloads/WHXSSThreats.pdf, April 2006.
[88] Jeremiah Grossman. JavaScript Malware, port scanning, and beyond. Posting to
the websecurity mailing list, http://www.webappsec.org/lists/websecurity/
archive/2006-07/msg00097.html, July 2006.
[89] Jeremiah Grossman. CSRF DDoS, skeleton in the closet. [online], http://
jeremiahgrossman.blogspot.com/2008/04/csrf-ddos-skeleton-in-closet.
html (05/08/08), April 2008.
[90] Jeremiah Grossman, Robert Hansen, Petko Petkov, and Anton Rager. Cross Site
Scripting Attacks: XSS Exploits and Defense. Syngress, 2007.
[93] William G.J. Halfond, Alessandro Orso, and Panagiotis Manolios. Using Positive
Tainting and Syntax-Aware Evaluation to Counter SQL Injection Attacks. In 14th
ACM Symposium on the Foundations of Software Engineering (FSE), 2006.
[94] Oystein Hallaraker and Giovanni Vigna. Detecting Malicious JavaScript Code in
Mozilla. In Proceedings of the IEEE International Conference on Engineering of
Complex Computer Systems (ICECCS), pages 85–94, June 2005.
[95] Robert Hansen. XSS (cross-site scripting) cheat sheet - esp: for filter evasion.
[online], http://ha.ckers.org/xss.html, (05/05/07).
237
Bibliography
[98] Robert Hansen. Hacking Intranets Via Brute Force. [online], http://ha.ckers.
org/blog/20061228/hacking-intranets-via-brute-force/, December 2006.
[99] Robert Hansen. List of common internal domain names. [online], http://ha.
ckers.org/fierce/hosts.txt, (09/06/07), March 2007.
[102] Philippe Le Hegaret, Ray Whitmer, and Lauren Wood. Document Object Model
(DOM). W3C recommendation, http://www.w3.org/DOM/, January 2005.
[106] Billy Hoffman. JavaScript Malware for a Gray Goo Tomorrow! Talk
at the Shmoocon’07, http://www.spidynamics.com/spilabs/education/
presentations/Javascript malware.pdf, March 2007.
[108] Michael Howard and David LeBlanc. Writing Secure Code, Second Edition. Mi-
crosoft Press, 2003.
[109] Yao-Wen Huang, Fang Yu, Christian Hang, Chung-Hung Tsai, Der-Tsai Lee, and
Sy-Yen Kuo. Securing web application code by static analysis and runtime pro-
tection. In Proceedings of the 13th conference on World Wide Web, pages 40–52.
ACM Press, 2004.
238
Bibliography
[110] Kingsley Idehen. The Open Database Connectivity Standard (ODBC). Whitepa-
per, OpenLink Software, http://www.openlinksw.com/info/docs/odbcwhp/
tableof.htm, 1993.
[111] Matthew Inman. XSS - How to get 20 .gov links in 20 minutes. [online], http:
//www.seomoz.org/blog/xss-how-to-get-20-gov-links-in-20-minutes,
(08/08/08), August 2006.
[112] Omar Ismail, Masashi Eto, Youki Kadobayashi, and Suguru Yamaguchi. A Pro-
posal and Implementation of Automatic Detection/Collection System for Cross-
Site Scripting Vulnerability. In 8th International Conference on Advanced Infor-
mation Networking and Applications (AINA04), March 2004.
[113] Collin Jackson, Adam Barth, Andrew Bortz, Weidong Shao, and Dan Boneh.
Protecting Browsers from DNS Rebinding Attack. In Proceedings of the 14th ACM
Conference on Computer and Communication Security (CCS ’07), October 2007.
[114] Collin Jackson, Andrew Bortz, Dan Boneh, and John C. Mitchell. Protecting
Browser State from Web Privacy Attacks. In Proceedings of the 15th ACM World
Wide Web Conference (WWW 2006), 2006.
[115] Collin Jackson, Andrew Bortz, Dan Boneh, and John C. Mitchell. SafeHistory.
[software], http://www.safehistory.com/, 2006.
[116] Collin Jackson and Helen J. Wang. Subspace: Secure Cross-Domain Communica-
tion for Web Mashups. In WWW 2007, 2007.
[117] Ian Jacobs, Arnaud Le Hors, and David Raggett. HTML 4.01 Specification.
W3C recommendation, http://www.w3.org/TR/1999/REC-html401-19991224,
November 1999.
[118] Markus Jakobsson and Sid Stamm. Invasive Browser Sniffing and Counter-
measures. In Proceedings of The 15th annual World Wide Web Conference
(WWW2006), 2006.
[120] Trevor Jim, Greg Morrisett, Dan Grossman, Michael Hicks, James Cheney, and
Yanling Wang. Cyclone: A safe dialect of C. In USENIX Annual Technical Con-
ference, 2002.
[121] Trevor Jim, Nikhil Swamy, and Michael Hicks. Defeating Script Injection Attacks
with Browser-Enforced Embedded Policies. In 16th International World Wide Web
Conference (WWW2007), May 2007.
239
Bibliography
[124] Martin Johns. (somewhat) breaking the same-origin policy by undermining dns-
pinning. Posting to the Bugtraq mailinglist, http://www.securityfocus.com/
archive/107/443429/30/180/threaded, August 2006.
[125] Martin Johns. Using eval() in Greasemonkey scripts considered harmful. [online],
Security Advisory, http://shampoo.antville.org/stories/1537256/, Decem-
ber 2006.
[126] Martin Johns. Code injection via CSRF in Wordpress < 2.03. [online], Security
Advisory, http://shampoo.antville.org/stories/1540873/, (08/08/08), Jan-
uary 2007.
[128] Martin Johns. On JavaScript Malware and Related Threats - Web Page Based
Attacks Revisited. Journal in Computer Virology, Springer Paris, 4(3):161–178,
August 2008.
[129] Martin Johns and Christian Beyerlein. SMask: Preventing Injection Attacks in
Web Applications by Approximating Automatic Data/Code Separation. In 22nd
ACM Symposium on Applied Computing (SAC 2007), Security Track, pages 284 –
291. ACM, March 2007.
[130] Martin Johns, Bjoern Engelmann, and Joachim Posegga. XSSDS: Server-side De-
tection of Cross-site Scripting Attacks. In Annual Computer Security Applications
Conference (ACSAC’08), pages 335 – 344. IEEE Computer Society, December
2008.
[131] Martin Johns and Kanatoko. Using Java in anti DNS-pinning attacks (Firefox and
Opera). [online], Security Advisory, http://shampoo.antville.org/stories/
1566124/, (08/27/07), Februar 2007.
[133] Martin Johns and Justus Winter. RequestRodeo: Client Side Protection against
Session Riding. In Frank Piessens, editor, Proceedings of the OWASP Europe
2006 Conference, refereed papers track, Report CW448, pages 5 – 17. Departement
Computerwetenschappen, Katholieke Universiteit Leuven, May 2006.
240
Bibliography
[134] Martin Johns and Justus Winter. Protecting the Intranet Against ”JavaScript
Malware” and Related Attacks. In Robin Sommer Bernhard M. Haemmerli, editor,
Detection of Intrusions and Malware & Vulnerability Assessment (DIMVA 2007),
volume 4579 of LNCS, pages 40 – 59. Springer, July 2007.
[136] Nenad Jovanovic, Christopher Kruegel, and Engin Kirda. Pixy: A Static Anal-
ysis Tool for Detecting Web Application Vulnerabilities. In IEEE Symposium on
Security and Privacy, May 2006.
[137] Nenad Jovanovic, Christopher Kruegel, and Engin Kirda. Preventing cross site re-
quest forgery attacks. In Proceedings of the IEEE International Conference on Se-
curity and Privacy for Emerging Areas in Communication Networks (Securecomm
2006), 2006.
[138] Dan Kaminsky. Black Ops 2007: Design Reviewing The Web. talk at the Black
Hat 2007 conference, http://www.doxpara.com/?q=node/1149, August 2007.
[139] Dan Kaminsky. h0h0h0h0. Talk at the ToorCon Seattle Conference, http://
seattle.toorcon.org/2008/conference.php?id=42, April 2008.
[140] Samy Kamkar. Technical explanation of the MySpace worm. [online], http:
//namb.la/popular/tech.html, (01/10/06), October 2005.
[143] Chris Karlof, Umesh Shankar, J.D. Tygar, and David Wagner. Dynamic pharming
attacks and the locked same-origin policies for web browsers. In Proceedings of
the 14th ACM Conference on Computer and Communication Security (CCS ’07),
October 2007.
[144] Martin Kempa and Volker Linnemann. On XML Objects. In Programming Lan-
guage Technologies for XML (PLAN-X 2002), 2002.
[146] Pekka Kilpelaeinen and Derick Wood. SGML and XML Document Grammars and
Exceptions. Information and Computation, 169(2):230–251, 2001.
241
Bibliography
[148] Engin Kirda, Christopher Kruegel, Giovanni Vigna, and Nenad Jovanovic. Noxes:
A Client-Side Solution for Mitigating Cross Site Scripting Attacks. In Security
Track of the 21st ACM Symposium on Applied Computing (SAC 2006), April
2006.
[150] Amid Klein. ”Divide and Conquer” - HTTP Response Splitting, Web
Cache Poisoning Attacks, and Related Topics. Whitepaper, Sanc-
tum Inc., http://packetstormsecurity.org/papers/general/whitepaper
httpresponse.pdf, March 2004.
[151] Amit Klein. Cross Site Scripting Explained. White Paper, Sanctum Secu-
rity Group / IBM, http://download.boulder.ibm.com/ibmdl/pub/software/
dw/rational/pdf/0325 segal.pdf, June 2002.
[153] Amit Klein. DOM Based Cross Site Scripting or XSS of the Third
Kind. [online], http://www.webappsec.org/projects/articles/071105.shtml,
(05/05/07), Sebtember 2005.
[154] Amit Klein. XST Strikes Back. Posting to the websecurity mailinglist, http:
//www.webappsec.org/lists/websecurity/archive/2006-01/msg00051.html,
January 2006.
[155] Alex ”Kuza55” Kouzemtchenko. Unusual Web Bugs - A Web Hacker’s Bag O’
Tricks. Talk a the 24C3 conference, http://events.ccc.de/congress/2007/
Fahrplan/events/2212.en.html, December 2007.
[156] Glenn Krasner and Stephen Pope. A Cookbook for Using the Model-View-
Controller User Interface Paradigm in Smalltalk-80. Journal Of Object Oriented
Programming, 1(3):26 ff, August/September 1989.
[157] Jason Kratzer. JSPWiki Multiple Vulnerabilities. Posting to the Bugtraq mail-
inglist, http://seclists.org/bugtraq/2007/Sep/0324.html, September 2007.
[158] D. Kristol and L. Montulli. HTTP State Management Mechanism. RFC 2965,
http://www.ietf.org/rfc/rfc2965.txt, October 2000.
[159] Christopher Kruegel and Engin Kirda. Protecting Users Against Phishing Attacks
with AntiPhish. In 29th Annual International Computer Software and Applications
Conference (COMPSAC’05), July 2005.
242
Bibliography
[160] SPI Labs. Detecting, Analyzing, and Exploiting Intranet Applications us-
ing JavaScript. Whitepaper, http://www.spidynamics.com/assets/documents/
JSportscan.pdf, July 2006.
[161] SPI Labs. Stealing Search Engine Queries with JavaScript. Whitepaper, http:
//www.spidynamics.com/assets/documents/JS SearchQueryTheft.pdf, 2006.
[163] Julien Lamarre. AJAX without XMLHttpRequest, frame, iframe, Java or Flash.
[online], http://zingzoom.com/ajax/ajax with image.php, (02/02/2006),
September 2005.
[165] Thor Larholm. IIS allows universal CrossSiteScripting. Posting to the bugtraq
mailing list, http://seclists.org/bugtraq/2002/Apr/0129.html, April 2002.
[166] James R. Larus, Thomas Ball, Manuvir Das, Robert DeLine, Manuel Faehndrich,
Jon Pincus, Sriram K. Rajamani, and Ramanathan Venkatapathy. Righting soft-
ware. IEEE Software, 21(3):92–100, 2004.
[167] Ben Laurie and Peter Laurie. Apache: The Definitive Guide. O’Reilly, 3rd edition,
December 2002.
[168] Benjamin Livshits and Weidong Cui. Spectator: Detection and Containment of
JavaScript Worms. In Usenix Annual Technical Conference, June 2008.
[169] Benjamin Livshits and Ulfar Erlingsson. Using Web Application Construction
Frameworks To Protect Against Code Injection Attacks. In Workshop on Pro-
gramming Languages and Analysis for Security (PLAS 2007), June 2007.
[170] Benjamin Livshits and Monica S. Lam. Finding Security Vulnerabilities in Java
Applications Using Static Analysis. In Proceedings of the 14th USENIX Security
Symposium, August 2005.
[171] LMH. MOAB-01-01-2007: Apple Quicktime rtsp URL Handler Stack-based Buffer
Overflow. [online], http://projects.info-pull.com/moab/MOAB-01-01-2007.
html, (05/13/08), January 2007.
[172] Miroslav Lucinskij. Skype videomood XSS. Posting to the full disclosure mail-
inglist, http://seclists.org/fulldisclosure/2008/Jan/0328.html, January
2008.
243
Bibliography
[178] R. A. McClure and I. H. Krueger. SQL DOM: compile time checking of dynamic
SQL statements. In Proceedings of the 27th International Conference on Software
Engineering, 2005.
[179] Nathan McFeters and Billy Rios. URI Use and Abuse. Whitepaper, http://www.
xs-sniper.com/nmcfeters/URI Use and Abuse.pdf, July 2007.
[180] Haroon Meer and Marco Slaviero. It’s all about the timing... Whitepaper, http:
//www.sensepost.com/research/squeeza/dc-15-meer and slaviero-WP.pdf,
August 2007.
[181] Adam Megacz. Firewall circumvention possible with all browsers. Posting to the
Bugtraq mailinglist, http://seclists.org/bugtraq/2002/Jul/0362.html, July
2002.
[182] Erik Meijer, Brian Beckman, and Gavien Bierman. LINQ: Reconciling Objects,
Relations, and XML In the .NET Framework. In SIGMOD 2006 Industrial Track,
2006.
[183] Erik Meijer, Wolfram Schulte, and Gavin Bierman. Programming with Circles,
Triangles and Rectangles. In XML 2003, 2003.
[184] Erik Meijer, Wolfram Schulte, and Gavin Bierman. Unifying Tables, Objects,
and Documents. In Declarative Programming in the Context of OO Languages
(DP-COOL ’03), volume 27. John von Neumann Institute of Computing, 2003.
[185] Steffen Meschkat. JSON RPC - Cross Site Scripting and Client Side Web Services.
Talk at the 23C3 Congress, http://events.ccc.de/congress/2006/Fahrplan/
attachments/1198-jsonrpcmesch.pdf, December 2006.
[186] Microsoft. How to use security zones in Internet Explorer. [online], http://
support.microsoft.com/default.aspx?scid=KB;EN-US;Q174360, (04/25/08),
December 2007.
244
Bibliography
[188] Mark S. Miller, Mike Samuel, Ben Laurie, Ihab Awad, and Mike Stay. Caja -
Safe active content in sanitized JavaScript. Whitepaper, http://google-caja.
googlecode.com/files/caja-spec-2008-01-15.pdf, January 2008.
[193] MSDN. Mitigating Cross-site Scripting With HTTP-only Cookies. [online], http:
//msdn.microsoft.com/workshop/author/dhtml/httponly cookies.asp,
(01/23/06).
[194] Marianne Mueller. Sun’s Response to the DNS Spoofing Attack. [online], http:
//www.cs.princeton.edu/sip/news/sun-02-22-96.html, (09/09/07), February
1996.
[195] Makoto Murata, Dongwon Lee, Murali Mani, and Kohsuke Kawaguchi. Taxonomy
of XML schema languages using formal language theory. ACM Trans. Interet
Technol., 5(4):660–704, 2005.
[196] George C. Necula, Scott McPeak, and Westley Weimer. CCured: Type-Safe
Retrofitting of Legacy Code. In Symposium on Principles of Programming Lan-
guages (POPL’02), 2002.
[197] Jeff Nelson and David Jeske. Limits to Anti Phishing. In Proceedings of the W3C
Security and Usability Workshop, 2006.
[199] Object Management Group, Inc. Common Object Request Broker Architecture:
Core Specification, Version 3.0.3. [Specification Document], http://www.omg.
org/docs/formal/04-03-12.pdf, March 2004.
245
Bibliography
[201] Aleph One. Smashing the stack for fun and profit. Phrack, 49, 1996.
[202] Open Web Application Project (OWASP). CSRF Guard 2.2. Software, http:
//www.owasp.org/index.php/CSRF Guard, June 2008.
[204] Open Web Application Project (OWASP). Path traversal. [online], http://www.
owasp.org/index.php/Path Traversal (08/08/08), May 2008.
[205] Tim O’Reilly. What is Web 2.0: Design Patterns and Business Models for the
Next Generation of Software. Communications & Strategies, (65), 1. quarter 2007.
[206] Stefano Di Paola and Giorgio Fedon. Subverting Ajax - Next generation vulnerabil-
ities in 2.0 Web Applications. In 23rd Chaos Communication Congress, December
2006.
[208] Charles P. Pfleeger and Shari Lawrence Pfleeger. Security in computing. Prentice
Hall, 4th edition, 2007.
[209] Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002.
[210] Tadeusz Pietraszek and Chris Vanden Berghe. Defending against Injection Attacks
through Context-Sensitive String Evaluation. In Recent Advances in Intrusion
Detection (RAID2005), 2005.
[211] Alex Pigrelax. XSS in nested tag in phpbb 2.0.16. mailing list Bugtraq, http:
//www.securityfocus.com/archive/1/404300, July 2005.
[215] Niels Provos, Dean McNamee, Panayiotis Mavrommatis, Ke Wang, and Nagen-
dra Modadugu. The Ghost in the Browser: Analysis of Web-based Malware. In
USENIX Workshop on Hot Topics in Understanding Botnets, April 2007.
246
Bibliography
[218] E. Rescorla and A. Schiffman. The Secure HyperText Transfer Protocol. RFC
2660, http://www.ietf.org/rfc/rfc2660.txt, August 1999.
[219] H. G Rice. Classes of Recursively Enumerable Sets and Their Decision Problems.
Trans. Amer. Math. Soc., 74:358–366, 1953.
[220] Billy K. Rios and Nathan McFeters. Slipping Past The Firewall. Talk at the HITB-
SecConf2007 conference, http://conference.hitb.org/hitbsecconf2007kl/
agenda.htm, September 2007.
[222] Thomas Roessler. When Widgets Go Bad. Lightning talk at the 24C3 con-
ference, http://log.does-not-exist.org/archives/2007/12/28/2160 when
widgets go bad.html, December 2007.
[223] Blake Ross, Collin Jackson, Nicholas Miyake, Dan Boneh, and John C. Mitchell.
Stronger Password Authentication Using Browser Extensions. In Proceedings of
the 14th Usenix Security Symposium, 2005.
[226] Olatunji Ruwase and Monica S. Lam. A Practical Dynamic Buffer Overflow De-
tector. In Proceedings of the Network and Distributed System Security (NDSS)
Symposium, 2004.
[228] Daniel Sandler and Dan S. Wallach. <input type=”password”> must die! In Web
2.0 Security and Privacy 2008 (W2SP’08), May 2008.
[229] S. S. Sarma and Garima Narayan. Analysis of defaced Indian websites Year-
2006. CERT-In White Paper CIWP-2007-02, http://www.cert-in.org.in/
knowledgebase/whitepapers/CIWP-2007-02.pdf, February 2007.
247
Bibliography
[230] Stuart E. Schechter, Rachna Dhamija, Andy Ozment, and Ian Fischer. The Em-
peror’s New Security Indicators - An evaluation of website authentication and the
effect of role playing on usability studies. In IEEE Symposium on Security and
Privacy, pages 51–65, May 2007.
[232] Juergen Schmidt. Password stealing for dummies... or why Cross Site Script-
ing really matters. [online], http://www.heise-online.co.uk/security/
Password-stealing-for-dummies--/features/93141, August 2007.
[233] John Schneider, Rok Yu, and Jeff Dyer (Editors). ECMAScript for XML (E4X)
Specification. ECMA Standard 357, http://www.ecma-international.org/
publications/standards/Ecma-357.htm, 2nd Edition, December 2005.
[237] Princeton University Secure Internet Programming Group. DNS Attack Scenario.
[online], http://www.cs.princeton.edu/sip/news/dns-scenario.html, Febru-
ary 1996.
[238] Rajesh Sethumadhavan. Microsoft Internet Explorer Local File Accesses Vul-
nerability. Posting to the full disclosure mailing list, http://seclists.org/
fulldisclosure/2007/Feb/0434.html, February 2007.
[240] Mohsen Sharifi, Alireza Saberi, Mojtaba Vahidi, and Mohammad Zoroufi. A Zero
Knowledge Password Proof Mutual Authentication Technique Against Real-Time
Phishing Attacks. In Patrick Drew McDaniel and Shyam K. Gupta, editors, ICISS,
volume 4812 of Lecture Notes in Computer Science, pages 254–258. Springer, 2007.
248
Bibliography
[243] Window Snyder. jar: Protocol XSS Security Issues. [online], http://blog.
mozilla.com/security/2007/11/16/jar-protocol-xss-security-issues/,
(04/18/08), November 2007.
[246] Sid Stamm, Zulfikar Ramzan, and Markus Jakobsson. Drive-by Pharming. In In
Proceedings of Information and Communications Security (ICICS ’07), number
4861 in LNCS, December 2007.
[247] Dafydd Stuttard. DNS Pinning and Web Proxies. NISR whitepaper, http://www.
ngssoftware.com/research/papers/DnsPinningAndWebProxies.pdf, 2007.
[248] Zhendong Su and Gary Wassermann. The Essence of Command Injection Attacks
in Web Applications. In Proceedings of POPL’06, January 2006.
[249] Sun Developer Network. Java Remote Method Invocation (RMI). [online], http://
java.sun.com/javase/technologies/core/basic/rmi/index.jsp, (08/08/08).
[251] Sun Microsystems Inc. Java Applets - Code Samples and Apps. [online], http:
//java.sun.com/applets/ (08/10/09).
[252] Sun Microsystems Inc. J2EE - Java Platform Enterprise Edition 5. [online], http:
//java.sun.com/javaee/technologies/javaee5.jsp, (05/05/07), 2007.
[254] The PHP Group. PHP: Hypertext Preprocessor. Programming Language, http:
//www.php.net, 1995 - 2009.
[255] The webappsec mailing list. The Cross Site Scripting (XSS) FAQ. [online], http:
//www.cgisecurity.com/articles/xss-faq.shtml, May 2002.
[256] Jochen Topf. The HTML Form Protocol Attack. Whitepaper, http://www.
remote.org/jochen/sec/hfpa/hfpa.pdf, August 2001.
[257] Rosario Valotta. Nduja Connection: A proof of concept of a XWW - cross webmail
worm. [online], http://rosario.valotta.googlepages.com/home, (04/17/08),
July 2007.
[258] Anne van Kesteren. The XMLHttpRequest Object. W3C Working Draft, http:
//www.w3.org/TR/XMLHttpRequest, April 2008.
249
Bibliography
[259] Anne van Kesteren (Editor). Cross-Origin Resource Sharing. W3C Working Draft,
Version 20090317, http://www.w3.org/TR/access-control/, March 2009.
[260] John Viega, J.T. Bloch, Tadayoshi Kohno, and Gary McGraw. ITS4: A static
vulnerability scanner for C and C++ code. In Proceedings of the 16th Annual
Computer Security Applications Conference, 2000.
[261] Philipp Vogt, Florian Nentwich, Nenad Jovanovic, Christopher Kruegel, Engin
Kirda, and Giovanni Vigna. Cross Site Scripting Prevention with Dynamic Data
Tainting and Static Analysis. In 14th Annual Network and Distributed System
Security Symposium (NDSS 2007), 2007.
[262] Dennis M. Volpano, Geoffrey Smith, and Cynthia Irvine. A sound type system for
secure flow analysis. Journal of Computer Security, 4:167–187, 1996.
[263] L. von Ahn, M. Blum, N. Hopper, and J. Langford. CAPTCHA: Using Hard AI
Problems For Security. In Proceedings of Eurocrypt, pages 294–311, 2003.
[264] Sergey Vzloman and Robert Hansen. Enumerate Windows Users In JS. [online],
http://ha.ckers.org/blog/20070518/enumerate-windows-users-in-js/,
(08/08/07), May 2007.
[265] Sergey Vzloman and Robert Hansen. Read Firefox Settings (PoC).
[online], http://ha.ckers.org/blog/20070516/read-firefox-settings-poc/,
(08/08/07), May 2007.
[268] Larry Wall, Tom Christiansen, and Jon Orwant. Programming Perl. O’Reilly, 3rd
edition, July 2000.
[269] Gary Wassermann and Zhendong Su. Sound and Precise Analysis of Web Ap-
plications for Injection Vulnerabilities. In Proceedings of Programming Language
Design and Implementation (PLDI’07), San Diego, CA, June 10-13 2007.
[270] Gary Wassermann and Zhendong Su. Static Detection of Cross-Site Scripting
Vulnerabilities. In Proceedings of the 30th International Conference on Software
Engineering, Leipzig, Germany, May 2008. ACM Press New York, NY, USA.
[272] Web Application Security Consortium. The Web Security Threat Classifica-
tion - Path Traversal. [online], http://www.webappsec.org/projects/threat/
classes/path traversal.shtml, (08/08/08), 2005.
250
Bibliography
[273] Web Application Security Consortium. The Script Mapping Project. [online],
http://www.webappsec.org/projects/scriptmapping/ (04/30/08), December
2007.
[274] Christian Weitendorf. Implementierung von Ma§nahmen zur Sicherung des Web-
Session-Managements im J2EE-Framework. Master’s thesis, University of Ham-
burg, 2006.
[275] Justus Winter and Martin Johns. LocalRodeo: Client Side Protection against
JavaScript Malware. [online], http://databasement.net/labs/localrodeo,
(01/02/07), January 2007.
[276] Min Wu, Robert C. Miller, and Greg Little. Web Wallet: Preventing Phishing
Attacks by Revealing User Intentions. In Proceedings of the second symposium on
Usable privacy and security (SOUPS 06), 2006.
[277] Yichen Xie and Alex Aiken. Static Detection of Security Vulnerabilities in Scripting
Languages. In 15th USENIX Security Symposium, 2006.
[278] XSS-News. A large number of sites hosted by 1&1 Internet Inc. are
vulnerable to XSS. [online], http://www.xssnews.com/2007/12/27/
a-large-number-of-sites-hosted-by-11-internet-inc-are-vulnerable-to-xss/,
(04/17/08), December 2007.
[279] Wei Xu, Sandeep Bhatkar, and R. Sekar. Taint-Enhanced Policy Enforcement: A
Practical Approach to Defeat a Wide Range of Attacks. In 15th USENIX Security
Symposium, August 2006.
[281] Yves Younan, Wouter Joosen, and Frank Piessens. Efficient protection against
heap-based buffer overflows without resorting to magic. In Eighth International
Conference on Information and Communication Security (ICICS 2006), 2006.
[282] Yves Younan, Davide Pozza, Frank Piessens, and Wouter Joosen. Extended protec-
tion against stack smashing attacks without performance loss. In Twenty-Second
Annual Computer Security Applications Conference (ACSAC 2006), 2006.
[283] Michal Zalewski. Browser Security Handbook. Whitepaper, Google Inc., http:
//code.google.com/p/browsersec/wiki/Main, (01/13/09), 2008.
[284] Thiago Zaninotti and Amit Klein. Apache HTTPd ”Expect” Header Handling
Client-Side Cross Site Scripting Vulnerability (CVE-2006-3918). [online]. http:
//www.frsirt.com/english/advisories/2006/2963, (05/05/07), July 2006.
251
Bibliography
[286] William Zeller and Edward W. Felten. Cross-Site Request Forgeries: Exploitation
and Prevention. Technical report, Princeton University, 2008.
View
252