= Internals of noXSS =
This page describes how noXSS actually detects [http://en.wikipedia.org/wiki/Cross-site_scripting XSS] attacks, what components noXSS consists of and how they work together.
Basically noXSS checks all executed scripts against relevant request data. If a certain amount of request data is found within a script noXSS assumes that a XSS attempt has occurred and prevents the execution of the whole script.
There is one other case noXSS has to handle. The injection of a entire script tag with a source to load (e.g. {{{}}}) instead of inline code. Ideally this would be detected in the same way as we detect code injection but done on markup instead of !JavaScript code. In it currents stage noXSS limits itself on checks of the host part of the URL provided in the src attribute. Integrity checks of the whole markup will follow in a later release (#33).
= Components =
noXSS mainly consists of [http://www.mozilla.org/projects/xpcom/ XPCOM] components. XPCOM is similar to Microsoft's [http://en.wikipedia.org/wiki/Component_Object_Model COM] and is heavily used within Mozilla's code base.
The strict separation of duties gives us the possibility to easily replace a component when necessary. One example is the currently used string matcher. It does a sub-string match and is going to be replaced by a sub-sequence matcher in the next major release.
== Interceptor ==
The interceptor is responsible for intercepting any !JavaScript code right before execution. This lazy evaluation approach has the advantage that we can limit our checks to a minimum (i.e. the code actually executed vs. the whole code of the current page).
Another advantage is that we are able to intercept code generated during runtime (e.g. through [http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/eval eval()] or [http://developer.mozilla.org/en/DOM/window.setTimeout window.setTimeout()]).
This gives us the possibility to detect some DOM based XSS (Type 0) attacks where the payload is contained within the request data we are checking.
Our initial approach replaced all instances implementing [http://mxr.mozilla.org/mozilla-central/source/dom/public/nsIScriptContext.h nsIScriptContext] with a proxy object but since Firefox 3.0 this is no longer possible for an extension due to the [http://developer.mozilla.org/en/Migrating_from_Internal_Linkage_to_Frozen_Linkage unavailability of internal linkage].
We are now using the debugging API of [http://www.mozilla.org/js/spidermonkey/ SpiderMonkey] which isn't a perfect solution but works for the moment.
== String Matcher ==
The string matcher does the actual matching. It gets request data and code and finds any matches longer than a requested length (15 characters at the moment). We are using sub-string matching in [milestone:0.1 0.1] which is fast but can by tricked by filter evasion techniques (especially if a dysfunctional removal filter is in place).
Consider the following vulnerable PHP snippet:
{{{
#!php
]*>/is", "", $_REQUEST["data"]);
// we need our data as variable within our script in order to access it
echo "";
...
?>
}}}
An attacker can exploit this vulnerability with the following attack vector:
{{{
';aler