Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Apex Secure Coding Considerations

Apex is an on-demand language that extends the platform by providing the ability to write applications that run on servers. Unlike other general-purpose languages such as C# or Java which can be used to build many different types of applications, Apex is more limited in scope and focused on building business applications. While building applications or performing a security code review of an Apex application there are some special considerations to know that are specific to Apex and the platform.

SOQL Injection

  • Apex applications utilize SOQL, which is a proprietary but simplified and limited version of SQL. SOQL queries are constructed similar to SQL:

query = 'select * from users where username = \'' +username + '\' and password =\'' + password + '\'';

  • SOQL queries are also vulnerable to injection attacks in much the same way that SQL queries are vulnerable when user-supplied input is not properly sanitized before being used in a request sent to the database server.
  • One solution for preventing SOQL injection is similar to preventing SQL injection: Use prepared statements with bind variables:

query = [select * from users where user= :username and password=:password];

Cross-Site Scripting

  • Cross Site Scripting (XSS) is an attack where an attacker is able to modify a webpage to contain a malicious client-side script. This type of attack may be used to steal sensitive information such as usernames and passwords, perform session hijacking, remotely control or monitor the user's browser, or to impersonate a web page.
  • The platform provides output validation on all standard Visualforce components e.g. <apex:outputText> encode the characters within the components (< becomes &lt;). However this behavior can be overridden by setting the escape="false" attribute.

<apex:outputText escape="false">

  • Additionally, Custom JavaScript and S-Controls that give direct access to the HTML page also provide no XSS protection. In these cases, exact-match or whitelist input validation and output validation should be performed.

Cross-Site Request Forgery (CSRF)

  • CSRF is an attack where forged requests are made on behalf of an authenticated victim when the victim visits a malicious web page. The platform implements an anti-CSRF token to prevent this attack. Every form includes the token as a hidden field and the platform checks the validity of this token for POST submissions.

Finally, Apex applications hosted on the platform have the Secure flag set for all sensitive cookies by default. Apex applications can also use "Custom Settings" to store sensitive data such as encryption keys and passwords on the server. When configured correctly, this data will only be available programmatically to the Apex code within the package.

Latest SpiderLabs Blogs

Hunting For Integer Overflows In Web Servers

Allow me to set the scene and start proceedings off with a definition of an integer overflow, according to Wikipedia:

Read More

Welcome to Adventures in Cybersecurity: The Defender Series

I’m happy to say I’m done chasing Microsoft certifications (AZ104/AZ500/SC100), and as a result, I’ve had the time to put some effort into a blog series that hopefully will entertain and inform you...

Read More

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More