This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
OWASP Embedded Application Security
OWASP Embedded Application Security ProjectEach year, the number of enterprise and consumer devices with embedded software are on the rise. Given the publicity with IoT and more devices becoming network connected, it is essential to create secure coding guidelines for embedded software. Embedded Application Security is not often a high priority for embedded devices such as Routers, Managed Switches, IoT devices, and even ATM Kiosks. There are many challenges in the embedded field including ODM supply chain, limited memory, a small stack, and the challenge of pushing firmware updates securely to an endpoint. The goal of this project is to identify the risks in embedded applications on a generalized list of devices, create a list of best practices, draw on the resources that OWASP already has, and bring OWASP expertise to the embedded world. IntroductionContextual Output Encoding is a computer programming technique necessary to stop Cross Site Scripting. This project is a Java 1.5+ simple-to-use drop-in high-performance encoder class with no dependencies and little baggage. It provides numerous encoding functions to help defend against XSS in a variety of different HTML, JavaScript, XML and CSS contexts. Quick OverviewThe OWASP Java Encoder library is intended for quick contextual encoding with very little overhead, either in performance or usage. To get started, simply add the encoder-1.2.jar, import org.owasp.encoder.Encode and start encoding. Please look at the javadoc for Encode to see the variety of contexts for which you can encode. Tag libraries and JSP EL functions can be found in the encoder-jsp-1.2.jar. If you want to try it out or see it in action, head over to "Can You XSS This? (.com)" and hit it with your best XSS attack vectors! Happy Encoding! LicensingThe OWASP Java Encoder is free to use under the New BSD License.
|
What is this?The OWASP Java Encoder provides:
Important LinksJava Encoder at GitHub Mailing ListProject LeadersAuthor: Jeff Ichnowski @ Related Projects
|
Quick DownloadNews and Events
In PrintWe will be releasing a user guide soon! Classifications
|
The general API pattern is to utilize the Java Encoder Project in your user interface code and wrap all variables added dynamically to HTML with a proper encoding function. The encoding pattern is "Encode.forContextName(untrustedData)", where "ContextName" is the name of the target context and "untrustedData" is untrusted output.
Basic HTML Context
<body><%= Encode.forHtml(UNTRUSTED) %></body>
HTML Content Context
<textarea name="text"><%= Encode.forHtmlContent(UNTRUSTED) %></textarea>
HTML Attribute context
<input type="text" name="address" value="<%= Encode.forHtmlAttribute(UNTRUSTED) %>" />
Generally Encode.forHtml(UNTRUSTED) is also safe but slightly less efficient for the above two contexts (for textarea content and input value text) since it encodes more characters than necessary but might be easier for developers to use.
CSS contexts
<div style="width:<= Encode.forCssString(UNTRUSTED) %>"> <div style="background:<= Encode.forCssUrl(UNTRUSTED) %>">
Javascript Block context
<script type="text/javascript"> var msg = "<%= Encode.forJavaScriptBlock(UNTRUSTED) %>"; alert(msg); </script>
Javascript Variable context
<button onclick="alert('<%= Encode.forJavaScriptAttribute(UNTRUSTED) %>');"> click me</button>
JavaScript Content Notes: Encode.forJavaScript(UNTRUSTED) is safe for the above two contexts, but encodes more characters and is less efficient.
Encode URL parameter values
<a href="/search?value=<%= Encode.forUriComponent(UNTRUSTED) %>&order=1#top">
Encode REST URL parameters
<a href="/page/<%= Encode.forUriComponent(UNTRUSTED) %>">
Handling an Full Untrusted URL
When handling a full url with the OWASP Java encoder, first verify the URL is a legal URL.
String url = validateURL(untrustedInput);
Then encode the URL as an HTML attribute when outputting to the page. Note the linkable text needs to be encoded in a different context.
<a href="<%= Encode.forHtmlAttribute(untrustedUrl) %>"> <%= Encode.forHtmlContent(untrustedLinkName) %> </a>
To use in a JSP with EL
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %> <html> <head> <title><e:forHtml value="${param.title}" /></title> </head> <body> <h1>${e:forHtml(param.data)}</h1> </body> </html>
Other contexts can be found in the org.owasp.Encode class methods, including CSS strings, CSS urls, XML contexts, URIs and URI components.
Prevent the use of dangerous functions and APIs in efforts to protect against memory-corruption vulnerabilities inside firmware functions. Ensure secure compiler flags or switches are utilized upon each firmware build. (i.e For GCC -fPIE, -fstack-protector-all, -Wl,-z,noexecstack, -Wl,-z,noexecheap etc..) Ensure robust update mechanisms utilize cryptographically signed firmware images for updating functions. Do not hard code secrets such as passwords, usernames, tokens or similar variants into firmware images. Dispose and securely wipe sensitive information stored in buffers or temporary files during runtime after they are no longer needed (e.g. Wipe buffers from locations where personal identifiable information is stored before releasing the buffers) Modify Busybox and embedded frameworks alike to only libraries and functions that are being used. (e.g. Remove unused languages like perl and services such as Telnet, FTP etc) Validate all debugging and pre-production code have been removed prior to firmware deployment. Ensure all methods of communication are utilizing industry standard encryption configurations for TLS. Limit collection, storage, and sharing of personal identifiable information (PII) to items that are only required for operation. Ensure kernel and software packages on embedded images are updated to prevent from known publicly available exploits.
2016-2017 Roadmap
- Add decoders and canonicalization
- Build more complex examples