11.01.2015 Views

salesforce_security_impl_guide

salesforce_security_impl_guide

salesforce_security_impl_guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Security Tips for Apex and Visualforce Development<br />

Cross-Site Scripting (XSS)<br />

• http://www.owasp.org/index.php/Cross_Site_Scripting<br />

• http://www.cgi<strong>security</strong>.com/xss-faq.html<br />

• http://www.owasp.org/index.php/Testing_for_Cross_site_scripting<br />

• http://www.google.com/searchq=cross-site+scripting<br />

Within the Force.com platform there are several anti-XSS defenses in place. For example, <strong>salesforce</strong>.com has <strong>impl</strong>emented filters that<br />

screen out harmful characters in most output methods. For the developer using standard classes and output methods, the threats of<br />

XSS flaws have been largely mitigated. However, the creative developer can still find ways to intentionally or accidentally bypass the<br />

default controls. The following sections show where protection does and does not exist.<br />

Existing Protection<br />

All standard Visualforce components, which start with , have anti-XSS filters in place. For example, the following code is normally<br />

vulnerable to an XSS attack because it takes user-supplied input and outputs it directly back to the user, but the <br />

tag is XSS-safe. All characters that appear to be HTML tags are converted to their literal form. For example, the < character is converted<br />

to &lt; so that a literal < displays on the user's screen.<br />

<br />

{!$CurrentPage.parameters.userInput}<br />

<br />

Disabling Escape on Visualforce Tags<br />

By default, nearly all Visualforce tags escape the XSS-vulnerable characters. It is possible to disable this behavior by setting the optional<br />

attribute escape="false" . For example, the following output is vulnerable to XSS attacks:<br />

<br />

Programming Items Not Protected from XSS<br />

The following items do not have built-in XSS protections, so take extra care when using these tags and objects. This is because these<br />

items were intended to allow the developer to customize the page by inserting script commands. It does not makes sense to include<br />

anti-XSS filters on commands that are intentionally added to a page.<br />

Custom JavaScript<br />

If you write your own JavaScript, the Force.com platform has no way to protect you. For example, the following code is vulnerable<br />

to XSS if used in JavaScript.<br />

<br />

var foo = location.search;<br />

document.write(foo);<br />

<br />

<br />

The Visualforce component allows you to include a custom script on the page. In these cases, be<br />

very careful to validate that the content is safe and does not include user-supplied data. For example, the following snippet is<br />

extremely vulnerable because it includes user-supplied input as the value of the script text. The value provided by the tag is a URL<br />

to the JavaScript to include. If an attacker can supply arbitrary data to this parameter (as in the example below), they can potentially<br />

direct the victim to include any JavaScript file from any other website.<br />

<br />

101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!