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 />

SOQL Injection<br />

}<br />

return ;<br />

}<br />

In this case, the developer has unknowingly bypassed the anti-CSRF controls by developing their own action method. The id parameter<br />

is read and used in the code. The anti-CSRF token is never read or validated. An attacker Web page might have sent the user to this page<br />

using a CSRF attack and provided any value they wish for the id parameter.<br />

There are no built-in defenses for situations like this and developers should be cautious about writing pages that take action based upon<br />

a user-supplied parameter like the id variable in the preceding example. A possible work-around is to insert an intermediate confirmation<br />

page before taking the action, to make sure the user intended to call the page. Other suggestions include shortening the idle session<br />

timeout for the organization and educating users to log out of their active session and not use their browser to visit other sites while<br />

authenticated.<br />

SOQL Injection<br />

In other programming languages, the previous flaw is known as SQL injection. Apex does not use SQL, but uses its own database query<br />

language, SOQL. SOQL is much s<strong>impl</strong>er and more limited in functionality than SQL. Therefore, the risks are much lower for SOQL injection<br />

than for SQL injection, but the attacks are nearly identical to traditional SQL injection. In summary SQL/SOQL injection involves taking<br />

user-supplied input and using those values in a dynamic SOQL query. If the input is not validated, it can include SOQL commands that<br />

effectively modify the SOQL statement and trick the application into performing unintended commands.<br />

For more information on SQL Injection attacks see:<br />

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

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

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

• http://www.google.com/searchq=sql+injection<br />

SOQL Injection Vulnerability in Apex<br />

Below is a s<strong>impl</strong>e example of Apex and Visualforce code vulnerable to SOQL injection.<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!