I often have "ideas" that, in the haystack of my mind, are usually straws rather than that elusive needle. One recent one was whether the username is necessary to login to a website. Usually the Internet is excellent at helping identifying straws, and this idea is no exception, see http://blog.codinghorror.com/why-do-login-dialogs-have-a-user-field/. But let's follow through on the idea and see where it takes us.
So the basic idea is that when a user wants to authenticate to a website, all they do is provide their password and the website will use that information to identify them.
The draw of removing usernames for me is really an efficiency one, as it's not immediately clear that usernames are required to authenticate to a website.
The obvious problem though is if someone tries to register with the same password as an existing user. Since we can't have 2 users with the same password (more on unique passwords later), we must reject the registration and reveal that the chosen password is a valid credential for another user. We can overcome this problem by forcing the existing user with that password to change their password (using (an assumed pre-existing) out-of-band password reset mechanism e.g. email). Which highlights one benefit of authenticating with the password only, it creates an incentive for the user to choose a strong password (as otherwise they will continually have to change their password when new users attempt to register with the same password).
From the website's perspective there is a problem though, how do you identify the user? If passwords are being stored using a salted password-hashing algorithm, then it would be too inefficient for the website to, for each row in the password hash DB table, fetch the salt for that row, then generate the password hash (using the password of the user trying to authenticate), and the compare it against the stored password hash in that row. That approach simply does not scale. We certainly don't want to use a password hash without a salt or with a fixed salt (as this makes dictionary attacks on the password hash DB table much quicker in the event the table is exposed).
One option is to encrypt the password and use that as the salt for the password hash. To verify a login attempt the website would encrypt the password to create the salt, calculate the password hash (using the salt) and compare with the list of stored password hashes (potentially sorted for efficient searching). It's important to point out this encrypted password, which we are using as the salt, is not stored, but calculated during the login attempt.
If the password hash store was ever compromised (and we always assume it will be) then it will be impossible to brute-force the passwords without the encryption key as well (as the salt will not be known and not be practical to guess). Thus the security of this approach relies on protecting the encryption key. The key should not be stored in the DB, as the likely extraction method of the password hash DB table is SQL Injection, meaning if the key was in the DB it too could be extracted. The key should be stored somewhere the DB cannot access (the goal is to require the attacker to find a separate exploit to obtain the key). It could be stored in configuration files, but the best option would be an HSM, with encryption done on-board. At the stage an attacker has code executing talking to the HSM, it's game over anyway. If the encryption key was obtained by an attacker then they could more efficiently (than attacking traditional salted passwords hashes) perform a dictionary attack on the password hash DB table.
We can make another optimisation for security as well. We should keep track of the passwords that more than one user has chosen in the past i.e. password collisions discovered during user registration. After all, we don't want to force a user to change their weak password, only for that password to become available for use again! This way we will avoid the re-use of weak passwords e.g. 123456. Now imagine we had a list of passwords that we know more than one person had thought of. Now imagine we publicly shared that list (so other websites could avoid letting users choose those passwords as well).
So let's imagine we now have an application that doesn't require usernames for authentication and all users have unique passwords. What are the threats? Well a distributed dictionary attack against our application is a problem because every password guess is a possible match for every user. Annoyingly the more users we have the better the chances of the guess being right. Additionally, limiting the number of guesses is more difficult since authentication attempts are not user specific. This makes clear the benefit of having usernames; they make online authentication attacks much harder.
So my conclusion was that although usernames might not be strictly necessary, they do offer significant security benefits. From a user perspective as well there is minimal burden in using usernames as browsers (or other user agents) often remember the username for convenience.
But what about the benefits of unique passwords! What about the incentive we gained when users were forced to choose strong passwords? Well what if we keep usernames AND still forced passwords to be unique? Could this be the best of both worlds? Might I have just pricked my finger on a needle?
The 'sticking point' for me is the user acceptability of forcing unique passwords. It may drive the uptake of password managers or strong passwords, or it might annoy the hell out of people. Perhaps for higher security situations it could be justified.
Friday, 4 April 2014
Tuesday, 1 April 2014
Revisiting Fundamentals: Defence in Depth
I think it is a worthwhile exercise to revisit fundamental ideas occasionally. We are constantly learning new things and this new knowledge can have an effect on the way we understand fundamental concepts or assumptions, sometimes challenging them and sometimes offering new insights or facets to appreciate. I recently learned about how Defence in Depth was used in some historic military battles and it really challenged my understanding of how the principle can be applied to security.
So what is Defence in Depth (DiD) and what is it good for? My understanding is that DiD originated as a military tactic, but is more commonly understood in its engineering sense. It turns out the term has different meanings in these different disciplines. Largely I am going to focus on the meanings with regard to application security (as this is relevant to me).
Engineering
In engineering DiD is a design tactic to protect a resource by using layers of controls, so if one control fails (bypassed by an attacker) there is another control still protecting an asset. By incorporating DiD into an application's security design we add (passive) redundant controls that provide a margin of safety for a control being bypassed. The controls we add may be at different trust boundaries or act as only a partially redundant control for other controls e.g. input validation at the perimeter partially helps protect against XSS, SQLi, etc.
I would say that adding DiD in the engineering sense is essential to any security design of an application. Security controls should be expected to fail, and so accounting for this by architecting in redundancy to achieve a margin of safety makes sense. I will say that some disadvantages to redundancy have been identified that likely apply to DiD as well. Briefly:
Military
DiD in military terms is a layered use of defensive forces and capabilities that are designed to expend the resources of the attacker trying to penetrate them e.g. Battle of Kursk. What's crucial to appreciate, I think, is that in the physical world the attacker's resources (e.g. troops, guns, bombs, time) are usually limited in supply. In this way DiD grinds down an enemy and the defender wins if the cost/benefit analysis of the attacker changes so they either stop or focus on another target. Additionally, defensive forces are also a limited resource and can be ground down by an attacker. It is possible for an attack to result in stalemate as well, which may be considered a defensive win.
As an aside, this could be why APT attacks are considered so dangerous, it's not so much the advanced bit (I rarely read about advanced attacks), but the 'persistent' bit; the persistent threat is a reflection of the persistence (or resolve) of the attacker. The risk being that most defences are going to be unlikely to break that resolve.
So if those are the resources of the attacker then that gives us a way to measure how effective our DiD controls are; we need to measure how they increase time or weaken resolve.
Layered controls work well in increasing the time the attacker has to spend. The more dead ends they go down, the more controls they encounter that they cannot bypass, all that takes time. Also, attackers tend to have a standard approach, usually a set of tools they use, so any controls that limit the effectiveness of those tools and force them to manually attack the application will cause a larger use of time. Ironically though, consuming time could have an opposite effect on the resolve of the attacker, since there is likely a strong belief that a weakness exists somewhere, and also the "sunk cost effect", meaning the attacker may become more resolved to find a way in.
I'm not a psychologist so I can't speak with authority on what would wear down resolve. I suspect it would involve making the attack frustrating though. I will suggest that any control that makes the application inconsistent or inefficient to attack, will help to wear down resolve.
I did a bit of brain-storming to think of (mostly pre-existing) controls or designs an application could implement to consume 'time' and 'resolve' resources:
TL;DR
Defence in Depth in application security should involve redundant controls but may also include active defences.
So what is Defence in Depth (DiD) and what is it good for? My understanding is that DiD originated as a military tactic, but is more commonly understood in its engineering sense. It turns out the term has different meanings in these different disciplines. Largely I am going to focus on the meanings with regard to application security (as this is relevant to me).
Engineering
In engineering DiD is a design tactic to protect a resource by using layers of controls, so if one control fails (bypassed by an attacker) there is another control still protecting an asset. By incorporating DiD into an application's security design we add (passive) redundant controls that provide a margin of safety for a control being bypassed. The controls we add may be at different trust boundaries or act as only a partially redundant control for other controls e.g. input validation at the perimeter partially helps protect against XSS, SQLi, etc.
I would say that adding DiD in the engineering sense is essential to any security design of an application. Security controls should be expected to fail, and so accounting for this by architecting in redundancy to achieve a margin of safety makes sense. I will say that some disadvantages to redundancy have been identified that likely apply to DiD as well. Briefly:
- Redundancy can result in a more complex system. Complex systems are harder to secure.
- The redundancy is used to justify weaker security controls in downstream systems.
- The redundancy is used as an excuse to implement risky functionality which reduces the margin of safety. Multiple independent functionality relying on the margin can have an accumulated effect that reduces or removes the margin of safety.
Military
DiD in military terms is a layered use of defensive forces and capabilities that are designed to expend the resources of the attacker trying to penetrate them e.g. Battle of Kursk. What's crucial to appreciate, I think, is that in the physical world the attacker's resources (e.g. troops, guns, bombs, time) are usually limited in supply. In this way DiD grinds down an enemy and the defender wins if the cost/benefit analysis of the attacker changes so they either stop or focus on another target. Additionally, defensive forces are also a limited resource and can be ground down by an attacker. It is possible for an attack to result in stalemate as well, which may be considered a defensive win.
Taking this point of view then, is protecting an application analogous to protecting a physical resource? We need it to be analogous in some way otherwise using DiD (in the military sense) might not be an appropriate tactic to use for defending applications.
Well one of the key points in the physical arena is the consumption of resources, but in the application arena it seems less accurate (to me) to say that computing resources are consumed in the same way. If an attacker uses a computer to attack an application, the computer is not "consumed" in the process, or less able to be used again. The same is true for the application defences.
Well one of the key points in the physical arena is the consumption of resources, but in the application arena it seems less accurate (to me) to say that computing resources are consumed in the same way. If an attacker uses a computer to attack an application, the computer is not "consumed" in the process, or less able to be used again. The same is true for the application defences.
So it isn't analogous that physical resources are consumed in the same way in the physical and application security arenas. But there are other types of resources though, non-physical resources. I can think of 2 resources of an attacker that are limited and are applicable to application security;
- time - as a resource, if a defensive position can increase the time an attacker needs to spend performing an attack, the cost/benefit analysis of the attacker may change, the "opportunity cost" of that time may be too high.
- resolve - in the sense that an attacker will focus on a target for as long as they believe that attacking that target is possible and practical. If a defensive position can make the attacker believe that attacking it is impractical, then the attacker will focus their efforts elsewhere.
There is an irony in 'resolve' being a required resource. The folks who have the appropriate skills to attack applications are a funny bunch I reckon, as they are exactly the type of people who are very persistent, after all, if someone can master the art of reverse engineering or blind SQL injection, they are likely one persistence SOB. In a sense they are drawn to the problem of (application) security because it requires the very resource they have in abundance.
So if those are the resources of the attacker then that gives us a way to measure how effective our DiD controls are; we need to measure how they increase time or weaken resolve.
Layered controls work well in increasing the time the attacker has to spend. The more dead ends they go down, the more controls they encounter that they cannot bypass, all that takes time. Also, attackers tend to have a standard approach, usually a set of tools they use, so any controls that limit the effectiveness of those tools and force them to manually attack the application will cause a larger use of time. Ironically though, consuming time could have an opposite effect on the resolve of the attacker, since there is likely a strong belief that a weakness exists somewhere, and also the "sunk cost effect", meaning the attacker may become more resolved to find a way in.
I'm not a psychologist so I can't speak with authority on what would wear down resolve. I suspect it would involve making the attack frustrating though. I will suggest that any control that makes the application inconsistent or inefficient to attack, will help to wear down resolve.
I did a bit of brain-storming to think of (mostly pre-existing) controls or designs an application could implement to consume 'time' and 'resolve' resources:
- Simplicity. Attackers are drawn to complex functionality because complexity is the enemy of security. Complexity is where the vulnerabilities will be. The simpler the design and interface (a.k.a minimal attack surface area) the less opportunity the attacker will perceive.
- Defensive counter controls. Any controls that react to block or limit attacks (or tools).
- Rapid Incident Response. Any detection of partial attacks should be met with the tightening of existing controls or attack-specific controls. If you can fix things faster than the attacker can turn a weakness into a vulnerability, then they may lose hope. I do not pretend this would be easy.
- Random CAPTCHAs. Use a CAPTCHA (a good one that requires a human to solve), make these randomly appear on requests, especially if an attack might be under way against you.
- Offensive counter controls. Any control that misleads the attacker (or their tools).
- Random error response. Replace real error responses with random (but valid looking) error responses, the goal is to make the attacker think they have found a weakness but in reality they haven't. This could have a detrimental effect on actual trouble shooting though.
- Random time delays. Vary the response time of some requests, especially those that hit the database. Occasionally adding a 1 second delay won't be an issue for most users but could frustrate attacker timing attacks.
- Hang responses. If you think you are being attacked, you could hang responses, or deliver very slow responses so the connection doesn't time out.
TL;DR
Defence in Depth in application security should involve redundant controls but may also include active defences.
Tuesday, 25 March 2014
Making Java RIAs MIA - Enterprise Style
This post is all about how to disable Java in the browser, or alternative making Java Rich Internet Applications (RIA) missing-in-action. There is a lot of information out there on how to do this, but I couldn't find a good source that covered it from an Enterprise point of, that is, how to disable Java in the browser at scale (rather than just doing it on our own machine using a GUI), across multiple browsers and OSes.
First let's cover the obvious, why do we want to do this. See my page on Java Vulnerabilities. Basically if Java is enabled in your browsers then you are opening yourself up to a world of pain. If you have Java enabled in your browsers then you have malware somewhere in your Enterprise.
What we want is to understand the options we have for disabling Java in the browser and understand what the settings are that we need to configure.
Browser Agnostic
Uninstall Java
A system version, containing the default values for all users, can be created and stored at (on Windows and non-Windows respectively):
This system version is only used by Java if a deployment.config file exists at (on Windows and non-Windows respectively):
The system version contains the default values that the user version will use, but the user can override these. That is unless the system version indicates that the option should be locked (which means the user cannot change the option).
Both the system deployment.config and deployment.properties should be ACL’ed so that the user cannot edit them (but can read them).
Browser Specific
Internet Explorer (IE)
The executable disables Java in the browser and appears as “IE Java Block 32bit Shim” in the list of installed programs. Presumably the FixIt installs a 64bit equivalent on 64bit versions of IE.
We can detect if the Microsoft FixIt is installed by confirming that the following registry exists
Firefox
Firefox needs to be instructed to load this lock file and this is done by creating a “local-settings.js” file in the “defaults\pref” sub-directory of the Firefox installation directory with:
With these configuration files and options in place the option plugin.state.java in about:config will be italicized and greyed out.
I think I am not sure of is in what version of Firefox the plugin.state.java configuration was introduced, or even the ability to lock configuration options. If your Enterprise is using a very old version of Firefox then this approach might not be available.
Chrome
Windows
Non-Windows
First let's cover the obvious, why do we want to do this. See my page on Java Vulnerabilities. Basically if Java is enabled in your browsers then you are opening yourself up to a world of pain. If you have Java enabled in your browsers then you have malware somewhere in your Enterprise.
What we want is to understand the options we have for disabling Java in the browser and understand what the settings are that we need to configure.
Browser Agnostic
Uninstall Java
This is obviously a good option as it removes the risk of Java. However, depending on your environment user's may just re-install Java, so unless you are actively scanning for Java installations your Enterprise this approach might not be as effective as you'd like it to be.
For that reason I'm not going to focus on this solution too much, but for non-Windows machines see Oracle's advice on uninstalling and this post.
For Windows you can detect the installed versions of Java using
wmic product where "name like 'Java%'"
get name
and uninstall these via
wmic product where "name like 'Java%'"
call uninstall
Java Deployment Options
From Java version 7 update 10 a deployment
option exists to disable Java content in all browsers (these are the same options as available in the Java
Control Panel).
This option is a feature of Java and so is available on both Windows and
non-Windows OSes.
The option is stored in a
deployment.properties file. The user has
their own version of this file stored at (on Windows and non-Windows
respectively):
<user_profile>\AppData\LocalLow\Sun\Java\Deployment\deployment.properties
<user home>/.java/deployment/deployment.properties
A system version, containing the default values for all users, can be created and stored at (on Windows and non-Windows respectively):
%WINDIR%\Sun\Java\Deployment\deployment.properties
/etc/.java/deployment/deployment.properties
This system version is only used by Java if a deployment.config file exists at (on Windows and non-Windows respectively):
%WINDIR%\Sun\Java\Deployment\deployment.config
/etc/.java/deployment/deployment.config
and contains an option that specifies the
location of the system deployment.properties to use e.g. on Windows:
deployment.system.config=file\:C:/WINDOWS/Sun/Java/Deployment/deployment.properties
deployment.system.config.mandatory=true
The system version contains the default values that the user version will use, but the user can override these. That is unless the system version indicates that the option should be locked (which means the user cannot change the option).
So to disable the plugin across all
browsers and users the system deployment.properties should contain:
deployment.webjava.enabled=false
deployment.webjava.enabled.locked
Both the system deployment.config and deployment.properties should be ACL’ed so that the user cannot edit them (but can read them).
Although this option only applies from Java
version 7 update 10, there is no issue in settings this option for earlier
versions of Java, as the setting is ignored.
The benefit is that should Java be upgraded then this setting will be
adopted.
In response to the threat posed by Java in
the browser Microsoft released a FixIt
solution that disables Java in IE - http://support.microsoft.com/kb/2751647
The executable disables Java in the browser and appears as “IE Java Block 32bit Shim” in the list of installed programs. Presumably the FixIt installs a 64bit equivalent on 64bit versions of IE.
We can detect if the Microsoft FixIt is installed by confirming that the following registry exists
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{01cf069a-f8a1-4067-adc4-5ef7e922733c}.sdb
If the Windows OS is 64-bit and 32-bit IE
is installed then the key will be under:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
There is some debate about the effectiveness of this FixIt. Advice from CERT states that it doesn't completely prevent RIAs from being invoked by IE. Alternative methods to disable Java exist that may be more reliable but seem to involve updating a list of blocked ActiveX controls with every release of Java. You'll have to decide on the risk yourself, but on Windows perhaps unnstalling Java or using the Java deployment options are the safest options.
There is some debate about the effectiveness of this FixIt. Advice from CERT states that it doesn't completely prevent RIAs from being invoked by IE. Alternative methods to disable Java exist that may be more reliable but seem to involve updating a list of blocked ActiveX controls with every release of Java. You'll have to decide on the risk yourself, but on Windows perhaps unnstalling Java or using the Java deployment options are the safest options.
Firefox has a configuration option that
controls whether the plugin is enabled.
The option can be viewed by going to about:config and is called “plugin.state.java”. It can take one of three values:
- 0 = disabled
- 1 = click to play
- 2 = enabled
The value of this option is stored in a
file called “prefs.js” in the user’s Firefox profile directory. If a user was to set this option via
about:config their selection would be saved in this file.
It’s preferably to enforce all users (and
all user profiles) to disable the plugin.
Firefox supports a ‘lock’ on the preference so that the user cannot
(easily) change the option and enable the plugin (see Locking preferences). By creating a file called “mozilla.cfg” in
the installation directory of Firefox
with the entry:
//
lockPref("plugin.state.java",
0);
Firefox needs to be instructed to load this lock file and this is done by creating a “local-settings.js” file in the “defaults\pref” sub-directory of the Firefox installation directory with:
pref("general.config.obscure_value",
0);
pref("general.config.filename",
"mozilla.cfg");
With these configuration files and options in place the option plugin.state.java in about:config will be italicized and greyed out.
To prevent a user from changing “mozilla.cfg”
and “local-settings.js” these files should be ACL’ed so that the user cannot
edit them (but can read them).
I think I am not sure of is in what version of Firefox the plugin.state.java configuration was introduced, or even the ability to lock configuration options. If your Enterprise is using a very old version of Firefox then this approach might not be available.
Reference - http://stealthpuppy.com/prepare-mozilla-firefox-for-enterprise-deployment-and-virtualization/
Chrome
This method applies to Google Chrome and
Chromium (with minor differences). Chrome supports configuration via Policy (see chrome://policy) and the policy value we want
to set is called DisabledPlugins
(see list of plugins via chrome://plugins/).
The DisabledPlugins policy can be overridden by the EnabledPlugins
and DisabledPluginsExceptions policies though,
so these policies also need to be set to ensure the Java plugin is disabled.
Windows
Chrome policy can be enforced via Group
Policy. Google provides ADM/ADMX templates. The GPO should be configured at the "Computer Configuration" level:
- To set the DisabledPlugins policy, the policy entry “Specify a list of disabled plug-ins” should be set to “Enabled” and an entry of “Java(TM)” should be added.
- To set the EnabledPlugins policy, the policy entry “Specify a list of enabled plug-ins” should be set to a random value. (1)
- The set the DisabledPluginsExceptions policy, the policy entry “Specify a list of plug-ins that the user can enable or disable” should be set to a random value. (1)
Chrome historically supported policy
configuration through the registry but this ability was removed in
version 28. The current policy is still written to the registry though, so this provides a mechanism to verify the policy exists on a machine.
Non-Windows
Chrome also supports configuration via policy on
Non-Windows machines via a local JSON file containing the policy
configuration. The policy files live under /etc/opt/chrome for
Google Chrome (and /etc/chromium for Chromium).
Two types of policies exist; "managed", which
are mandatory policies, and "recommended" which are not mandatory. These policies are respectively located
under:
/etc/opt/chrome/policies/managed/
/etc/opt/chrome/policies/recommended/
To disable the Java
plugin create a file “policy.json” in
/etc/opt/chrome/policies/managed/ with the contents:
{
“DisabledPlugins”:["Java(TM)"],
“DisabledPluginsExceptions”:[" "],
“EnabledPlugins”:[" "],
}
The policy file should have ACLs applied to
it so that users cannot edit (but can read) it.
(1) So why do we assign the EnabledPlugins and DisabledPluginsExceptions random values (or a space character)? Turns out if we set these policies to "Not configured" or "Disabled" then a user can enable Java in the browser by configuring these policies in the "User Configuration" policy section. If this seems like a security issue to you, well it seemed like one to me as well, that's why I opened a bug with Google about it. They didn't really agree, but I concede it's complicated (and potentially it's a bug in Microsoft's Group Policy functionality).
Labels:
Chrome,
disable Java,
enterprise,
Firefox,
IE,
Java,
Java deployment options,
uninstall Java
Tuesday, 4 March 2014
Running Java applications without installing Java
Although it seems to be a dying breed, there are still some Java client-side applications that you may want or need to use e.g. the excellent Burp Suite. But this means having Java installed on your workstation - queue dramatic music.
This is less like handing over the keys to your computer than it used to be. Java can be configured so that Java content is disabled in all browsers (at least from version 7 update 10 and higher). But if the application requires an old version, or you just have little faith in the Swiss cheese that is Java's security controls, then it would be nice to isolate your Java installation.
There are several ways to isolate Java, from hardening its configuration to only running it in a virtual machine. What I'm going to suggest here is another option, using Java without installing Java.
This approach is already really common with server-side applications. It is common for server-side applications to install themselves with their own copy of the Java runtime, as this means there is no danger of compatibility issues with the current shared install of Java on the server or any updates to it. So why not take the same approach for client-side applications, and benefit from isolating Java to the one application that needs it.
So here's what to do (using Windows notation, but it's similar for non-Windows):
I got this working for Burp Suite, but I didn't regression test all of its functionality, so whilst the method seems to work, I can't give any guarantees it does. YMMV.
Dave
This is less like handing over the keys to your computer than it used to be. Java can be configured so that Java content is disabled in all browsers (at least from version 7 update 10 and higher). But if the application requires an old version, or you just have little faith in the Swiss cheese that is Java's security controls, then it would be nice to isolate your Java installation.
There are several ways to isolate Java, from hardening its configuration to only running it in a virtual machine. What I'm going to suggest here is another option, using Java without installing Java.
This approach is already really common with server-side applications. It is common for server-side applications to install themselves with their own copy of the Java runtime, as this means there is no danger of compatibility issues with the current shared install of Java on the server or any updates to it. So why not take the same approach for client-side applications, and benefit from isolating Java to the one application that needs it.
So here's what to do (using Windows notation, but it's similar for non-Windows):
- Obtain the offline Java installation .exe
- Follow these instructions to get access to the Data1.cab file
- Unzip the Data1.cab to get the core.zip file
- Unzip the core.zip file to get the JRE files
- In the .\lib folder there are several .pack files, you need to unpack these to their .jar equivalents using unpack200.exe (in the .\bin folder) e.g. "..\bin\unpack200.exe -r rt.pack rt.jar". Hat tip.
- (Optional) You can remove several files as they are usually unnecessary (importantly the browser plugin is one of them). This makes the total size smaller, but not by much.
- Run you client-side Java application by directly invoking .\bin\java.exe
I got this working for Burp Suite, but I didn't regression test all of its functionality, so whilst the method seems to work, I can't give any guarantees it does. YMMV.
Dave
Labels:
client-side,
isolate,
Java,
redistribute
Thursday, 27 February 2014
Java by numbers
A lot has been written about how bad Java is from a security perspective. Specifically, if you have Java enabled in your browser, well, you're going to get pwned (unless you have some compensating controls). Assuming your business requires Java be enabled in browsers for certain applications to work, then whilst it's not the only compensating control that should be used, having the latest version installed is a good start.
I've been looking at Java recently and wanted to know more precisely how much risk it posed. So I pulled together the number of vulnerabilities related to applets and web start applications (i.e. Rich Internet Applications) that have been discovered over the last couple years. You can see the numbers on my page Java Vulnerabilities. It makes for scary reading.
I've been looking at Java recently and wanted to know more precisely how much risk it posed. So I pulled together the number of vulnerabilities related to applets and web start applications (i.e. Rich Internet Applications) that have been discovered over the last couple years. You can see the numbers on my page Java Vulnerabilities. It makes for scary reading.
Labels:
Java,
Vulnerability Management
Friday, 21 February 2014
Is contextual output escaping too hard?
So whilst writing my post on Unobtrusive Javascript and JSON Data Islands I got to thinking about how successful contextual output escaping (or encoding) is as a tactic to mitigate XSS vulnerabilities.
I think there is an argument that it hasn't been very successful, and I don't think it is too hard to imagine the reasons for this:
(1) See also "Insane in the IFRAME - The case for client-side HTML sanitisation" (video - slides) from OWASP AppSecEU 2013.
I think there is an argument that it hasn't been very successful, and I don't think it is too hard to imagine the reasons for this:
- As a mitigation to XSS it involves a task that is essentially difficult. Knowing the context (either HTML, HTML attribute, JavaScript, CSS, etc.) where you are binding data into a template, either involves writing an HTML parser (to do it properly), or have developers manually specify the context for each binding site. That is not a solution as much as it is a whole new problem.
- There is a reason why there is no "contextual SQL escaping" mitigation promoted by the security community, and why parameterised queries is the mandated mitigation to SQL injection. It's because history has shown us that people are terrible at combining data and code and that the best option is to let the component that executes the code (and hence has the best code parser) do the combining for us. XSS is the same problem, combining data with code (HTML), which suggests that the browser should be combining the data and code(1) and we shouldn't be suggesting people do this themselves.
Of course it's all very well saying that people should architect their web applications to have the browser combine code and data, but developing web applications is a complex problem and there are lots of considerations to take into account when architecting the application, not just security. My impression is that the main considerations are performance and convenience.
Performance is tough to comment on, and depends on many things, but potentially moving more work to the client-side could improve server performance (you could argue that client-side performance might suffer, and thus user experience, but JavaScript performance only improves). Though there is no doubt that some businesses are very sensitive to page load times.
Convenience isn't a good reason in my opinion. It might not be convenient but that doesn't mean it can't be convenient. If a web application framework was designed from the ground up to let the browser combine code and data then likely they would (eventually) do it in a way that was convenient. Of course relying on frameworks means getting popular frameworks(2) to change, and I think the security community has a role to play there.
I will say that I've spent a good deal of time telling businesses to use contextual output escaping, and it is always difficult to challenge a long held belief, but there is evidence and reasoning to suggest that parameterising HTML is the better mitigation. The jury is still out in my mind, but I would be keen to hear other points of view?
(1) See also "Insane in the IFRAME - The case for client-side HTML sanitisation" (video - slides) from OWASP AppSecEU 2013.
(2) That's not to say there aren't some web application frameworks that have contextual output escaping built-in or support data binding on the client i.e. JavaScript templating engines (although I'm not sure the browser does the escaping), but I think (but am not an expert) that most don't. There are a lot of web application frameworks out there.
Labels:
Contextual Output Escaping,
security controls,
XSS
Thursday, 20 February 2014
Unobtrusive JavaScript and JSON Data Islands
I saw a tweet the other day from Jim Manico
The advice is basically to have more or less static HTML and JavaScript and all dynamic data should come from a JSON request. Not bad advice.
Reading the article reminded me of a similar approach that I once proposed, using Unobtrusive JavaScript. Unobtrusive JavaScript is an approach to developing a web application that clearly separates HTML from JavaScript from CSS. Now if you are a developer then rest assured this is not an approach created by a security guy who prioritises security above all else, this is an approach suggested by people who actually know what they are talking about. The Wikipedia page has the details, and interestingly is doesn't even mention the word 'security'.
So why is Unobtrusive JavaScript good for security? Well the best approach to preventing XSS is to use contextual output encoding, however that hard part of that is the 'contextual' bit. It seems that figuring out on the server side how the data being bound to a template is going to be interpreted by the browser, as either HTMl, JS or CSS, is often quite difficult. But if all the HTML, JS and CSS reside in different files, then the context couldn't be easier to determine, which makes output encoding a much simpler task. Additionally, this separation can be enforced by using the Content Security Policy (CSP) so you don't get any naughty developers slipping in JS where they shouldn't.
Of course if you are going to be suggesting Unobtrusive JavaScript then I wouldn't even mention security, there are so many other benefits that make it a good idea that you probably don't want any security related ulterior motives to be an issue ;)
So there are obvious similarities to what Adam Barth suggested, but a difference that I proposed was an alternative to using AJAX requests. So instead of making a separate network request for the JSON data another option is to put the JSON data inside the the HTML, in a 'JSON data island' (sadly it seems someone else beat me to coining this phrase). The comes from XML Data Islands, but obviously if the data is going to be used by JS it makes more sense for it to be JSON than XML.
The JSON data island could be implemented as a hidden <div> element or a <script> element with type="application/json".
The basic advantage is that it saves a network request. Admittedly this makes more sense for HTML pages that wouldn't be cached, so its appropriateness does depend on how the web application is architected (in terms of caching optimisations made). The data island would also need its own output encoding as the appropriate encoding for the server to do is to JS encode the data going into the JSON and then HTML encode the entire data island contents.
Sadly my proposal represented too much of a change to the web application I suggested it for, so if you like the idea, I hope you have better luck than me.
Hey @ndm, @adambarth was right all along about next generation XSS defense architectures. http://t.co/fXf1sydKvJ
Rock on Adam!
— Jim Manico (@manicode) February 12, 2014
That link is to http://www.educatedguesswork.org/2011/08/guest_post_adam_barth_on_three.html.The advice is basically to have more or less static HTML and JavaScript and all dynamic data should come from a JSON request. Not bad advice.
Reading the article reminded me of a similar approach that I once proposed, using Unobtrusive JavaScript. Unobtrusive JavaScript is an approach to developing a web application that clearly separates HTML from JavaScript from CSS. Now if you are a developer then rest assured this is not an approach created by a security guy who prioritises security above all else, this is an approach suggested by people who actually know what they are talking about. The Wikipedia page has the details, and interestingly is doesn't even mention the word 'security'.
So why is Unobtrusive JavaScript good for security? Well the best approach to preventing XSS is to use contextual output encoding, however that hard part of that is the 'contextual' bit. It seems that figuring out on the server side how the data being bound to a template is going to be interpreted by the browser, as either HTMl, JS or CSS, is often quite difficult. But if all the HTML, JS and CSS reside in different files, then the context couldn't be easier to determine, which makes output encoding a much simpler task. Additionally, this separation can be enforced by using the Content Security Policy (CSP) so you don't get any naughty developers slipping in JS where they shouldn't.
Of course if you are going to be suggesting Unobtrusive JavaScript then I wouldn't even mention security, there are so many other benefits that make it a good idea that you probably don't want any security related ulterior motives to be an issue ;)
So there are obvious similarities to what Adam Barth suggested, but a difference that I proposed was an alternative to using AJAX requests. So instead of making a separate network request for the JSON data another option is to put the JSON data inside the the HTML, in a 'JSON data island' (sadly it seems someone else beat me to coining this phrase). The comes from XML Data Islands, but obviously if the data is going to be used by JS it makes more sense for it to be JSON than XML.
The JSON data island could be implemented as a hidden <div> element or a <script> element with type="application/json".
The basic advantage is that it saves a network request. Admittedly this makes more sense for HTML pages that wouldn't be cached, so its appropriateness does depend on how the web application is architected (in terms of caching optimisations made). The data island would also need its own output encoding as the appropriate encoding for the server to do is to JS encode the data going into the JSON and then HTML encode the entire data island contents.
Sadly my proposal represented too much of a change to the web application I suggested it for, so if you like the idea, I hope you have better luck than me.
Labels:
Content Security Policy,
JSON,
Unobtrusive JavaScript,
XSS
Subscribe to:
Posts (Atom)