SlideShare a Scribd company logo
Salesforce Static
code Analysis
An option to avoid most commonly done mistakes
- Prasanna Deshpande
Helpshift Inc.
Tweet - @_prasu_
Email - prasu@prasannadeshpande.com
1
Pareto Principle or Pareto Rule
• 80% of software quality is maintained by 20% of
programmers
• 80% of bugs in an application are written by 20%
of developers
• 80% of bugs are fixed in 20% of time
2
What is static code analysis
• Static code analysis is a
method of computer program
debugging that is done by
examine in the code without
executing the program
• It is a technique that allows, at
the same time with unit-tests,
dynamic code analysis, code
review and others, to increase
code quality, increase its
reliability and decrease the
development time.
3
Who needs static code
analysis
• Any medium-sized and large software development
company – to increase code reliability and decrease
its price
• Any small company and individual developers – in a
lesser extent – to drink coffee instead of searching
and fixing annoying bugs,
• Anyone, who supports any old code
4
Static code analysis advantages
• Allows to find bugs on early stages (the earlier the
bug was spotted, the cheaper it is to be fixed)
• High analysis speed
• Does not require to run the application, only an
access to source code and (not always) – to
preprocessed files
• Allows to locate bugs in code that is rarely executed
(exception handlers, for instance).
5
Static code analysis
disadvantages
• Possibility of false positive alarm on correct code,
• Correct positive alarms on old code, which works correctly and
which should better not be bothered, may be nauseous.
• Comparatively small class of bugs detected due to the exponential
difficulty of “honest” bug search.
• Does not detects logical errors (this is a drawback of almost all
automatic testing tools in contrast to code review and manually
written unit tests).
6
How static code analysis
can be done for Salesforce?
7
Available tools
• Force.com Security Source
Scanner
https://security.secure.force.com/sec
urity/tools/forcecom/scanner
• PMD
http://pmd.sourceforge.net/snapshot/
pmd-apex/
• Checkmarx
https://www.checkmarx.com/
• CodeScan -
https://www.code-scan.com/
many more…
8
Force.com security source scanner
9
Force.com Security Source Scanner
Security Profile
• Cross Site Scripting (reflected, stored, and DOM
based)
• SOQL/SOSL Injection
• Access Control Issues (Sharing, FLS)
• Cross site request forgery attacks
• Arbitrary Redirects
• Overly permissive postMessage targets
• Static Resource referencing
• Multiple Visualforce forms in the same page
• Test methods without assert
Quality Profile
• DML statements inside loops
• SOQL/SOSL inside loops
• Hardcoding Trigger.new[0]
• Hardcoding Trigger.old[0]
• Queries with no Where clause or no LIMIT clause
• Not bulkifying apex methods
• Async (@future) methods inside loops
• Hardcoding IDs
• Multiple triggers on same object
10
Limitations of Force.com
security code scanner
• Scan submissions to be less than 2 million source lines of code for
Partners
• Customers with production or enterprise organizations can scan
360000 lines of code in any 12 months period of time
• Each scan is less than 5000 lines of code for Personal users. And
sandbox cannot be scanned.
• Scanning cannot be done for application on the NA21 or CS32
instances due to technical limitation of access
• Inconsistent Scan results
11
Report from Force.com Security source scanner
12
Detail view of scanner reported issue
13
PMD for Apex
14
Advantages of PMD
• Free and open source
• It can be part of ANT build script to generate error reports
• It can also be added to Jenkins job for scheduled code
scans
• Eclipse plugin available
• One can define their own custom rules
1. Custom rules for Naming convention
2. Comments format
15
Available Rulesets from
PMD
• ApexUnit
Should have asserts
shouldn't have SeeallData=true
• Complexity
Too many nested IF,
Excessive number of parameters for method,
Excessive length of class,
Excessive length of methods,
Excessive public variables,
Excessive class members
• Performance
SOQL in for loops,
DML in for loops
• Security
Apex sharing violation,
Open redirects,
insecure endpoints,
XSS from parameters,
CRUD violation,
• Style - Naming conventions for Methods and classes.
16
How PMD works
Let’s find a bug with PMD help!
public class HotLeads {
public Lead getTopLead() {
return [SELECT … ] ;
}
}
17
How PMD works
Let’s find a bug: Sharing violation
public with sharing class HotLeads {
public Lead getTopLead() {
return [SELECT … ] ;
}
}
18
Mostly issues are categories in 2 types:
• Definitely a bug: public class Foo {}
• Might be a bug : public class without sharing Foo {}
Expected : public with sharing Foo {}
19
How PMD works
Let’s find one more bug
public void saveTopLead() {
insert new Lead(firstName='Astro');
}
20
How PMD works
Let’s find one more bug: CRUD and FLS
public void saveTopLead() {
Boolean canCreate =
Schema.sObjectType.Lead.fields.firstName.isCreateable();
if(canCreate) {
insert new Lead(firstName='Astro');
}
}
21
How to use PMD
• Download PMD from https://pmd.github.io/
• Create a ApexRules.xml
• Execute the PMD script
./run.sh pmd -d "/Users/prasu/sfdc-app" -f html -R "apexrules.xml" -reportfile
“output.html"
./run.sh pmd -d "<SourceCodeFolder>" -f html -R "<ApexRulesFile>" -reportfile
“<OutputFileName"
22
Sample Apex Rule File
23
Report generated by PMD Apex
24
25
Thank you!
26

More Related Content

What's hot

Demystify Salesforce Bulk API
Demystify Salesforce Bulk APIDemystify Salesforce Bulk API
Demystify Salesforce Bulk API
Dhanik Sahni
 
Managing Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox ArchitectureManaging Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox Architecture
Alexander Sutherland
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
Salesforce Developers
 
Simple Salesforce Data Migration
Simple Salesforce Data MigrationSimple Salesforce Data Migration
Simple Salesforce Data Migration
Scribe Software Corp.
 
Salesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABITSalesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABIT
Vishnu Raju Datla
 
Adminとうまく共存するためのApex開発Tips
Adminとうまく共存するためのApex開発TipsAdminとうまく共存するためのApex開発Tips
Adminとうまく共存するためのApex開発Tips
Takashi Hatamoto
 
SFDC Organization Setup
SFDC Organization SetupSFDC Organization Setup
SFDC Organization Setup
Simeon Tzanev
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
Salesforce Admins
 
Salesforce administrator training presentation slides
Salesforce administrator training presentation slides Salesforce administrator training presentation slides
Salesforce administrator training presentation slides
Salesforce Associates
 
Single Sign-On and User Provisioning with Salesforce Identity
Single Sign-On and User Provisioning with Salesforce IdentitySingle Sign-On and User Provisioning with Salesforce Identity
Single Sign-On and User Provisioning with Salesforce Identity
Salesforce Developers
 
Flow builder pros and cons
Flow builder pros and consFlow builder pros and cons
Flow builder pros and cons
Melissa Shook
 
Security and Your Salesforce Org
Security and Your Salesforce OrgSecurity and Your Salesforce Org
Security and Your Salesforce Org
Salesforce Admins
 
Salesforce 101
Salesforce 101Salesforce 101
Salesforce 101
501Partners
 
Setting up Security in Your Salesforce Instance
Setting up Security in Your Salesforce InstanceSetting up Security in Your Salesforce Instance
Setting up Security in Your Salesforce Instance
Salesforce Developers
 
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
VMware Tanzu
 
Migration to Flows – Getting it Right!
Migration to Flows – Getting it Right!Migration to Flows – Getting it Right!
Migration to Flows – Getting it Right!
panayaofficial
 
Introduction to lightning Web Component
Introduction to lightning Web ComponentIntroduction to lightning Web Component
Introduction to lightning Web Component
Mohith Shrivastava
 
Ladies Be Architects - Study Group I: Territory Management
Ladies Be Architects - Study Group I: Territory ManagementLadies Be Architects - Study Group I: Territory Management
Ladies Be Architects - Study Group I: Territory Management
gemziebeth
 
Classic vs. lightning
Classic vs. lightningClassic vs. lightning
Classic vs. lightning
Gaurav Kumar
 

What's hot (20)

Demystify Salesforce Bulk API
Demystify Salesforce Bulk APIDemystify Salesforce Bulk API
Demystify Salesforce Bulk API
 
Managing Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox ArchitectureManaging Change With A Sensible Sandbox Architecture
Managing Change With A Sensible Sandbox Architecture
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
 
Simple Salesforce Data Migration
Simple Salesforce Data MigrationSimple Salesforce Data Migration
Simple Salesforce Data Migration
 
Salesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABITSalesforce Continuous Integration with AutoRABIT
Salesforce Continuous Integration with AutoRABIT
 
Adminとうまく共存するためのApex開発Tips
Adminとうまく共存するためのApex開発TipsAdminとうまく共存するためのApex開発Tips
Adminとうまく共存するためのApex開発Tips
 
SFDC Organization Setup
SFDC Organization SetupSFDC Organization Setup
SFDC Organization Setup
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
 
Salesforce administrator training presentation slides
Salesforce administrator training presentation slides Salesforce administrator training presentation slides
Salesforce administrator training presentation slides
 
Single Sign-On and User Provisioning with Salesforce Identity
Single Sign-On and User Provisioning with Salesforce IdentitySingle Sign-On and User Provisioning with Salesforce Identity
Single Sign-On and User Provisioning with Salesforce Identity
 
Flow builder pros and cons
Flow builder pros and consFlow builder pros and cons
Flow builder pros and cons
 
Security and Your Salesforce Org
Security and Your Salesforce OrgSecurity and Your Salesforce Org
Security and Your Salesforce Org
 
Salesforce 101
Salesforce 101Salesforce 101
Salesforce 101
 
Setting up Security in Your Salesforce Instance
Setting up Security in Your Salesforce InstanceSetting up Security in Your Salesforce Instance
Setting up Security in Your Salesforce Instance
 
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
Chassis and AppFactory: Accelerate Development of Cloud-Native Microservices ...
 
Migration to Flows – Getting it Right!
Migration to Flows – Getting it Right!Migration to Flows – Getting it Right!
Migration to Flows – Getting it Right!
 
Introduction to lightning Web Component
Introduction to lightning Web ComponentIntroduction to lightning Web Component
Introduction to lightning Web Component
 
Architecting Multi-Org Solutions
Architecting Multi-Org SolutionsArchitecting Multi-Org Solutions
Architecting Multi-Org Solutions
 
Ladies Be Architects - Study Group I: Territory Management
Ladies Be Architects - Study Group I: Territory ManagementLadies Be Architects - Study Group I: Territory Management
Ladies Be Architects - Study Group I: Territory Management
 
Classic vs. lightning
Classic vs. lightningClassic vs. lightning
Classic vs. lightning
 

Similar to Salesforce static code analysis

Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Security
sedukull
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis PrimerCoverity
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
Maven Logix
 
AppSec in an Agile World
AppSec in an Agile WorldAppSec in an Agile World
AppSec in an Agile World
David Lindner
 
Programming languages and techniques for today’s embedded andIoT world
Programming languages and techniques for today’s embedded andIoT worldProgramming languages and techniques for today’s embedded andIoT world
Programming languages and techniques for today’s embedded andIoT world
Rogue Wave Software
 
Cyber security - It starts with the embedded system
Cyber security - It starts with the embedded systemCyber security - It starts with the embedded system
Cyber security - It starts with the embedded system
Rogue Wave Software
 
CSS 17: NYC - Protecting your Web Applications
CSS 17: NYC - Protecting your Web ApplicationsCSS 17: NYC - Protecting your Web Applications
CSS 17: NYC - Protecting your Web Applications
Alert Logic
 
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austinDev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Matt Tesauro
 
Providence: rapid vulnerability prevention
Providence: rapid vulnerability preventionProvidence: rapid vulnerability prevention
Providence: rapid vulnerability prevention
Salesforce Engineering
 
Jason Kent - AppSec Without Additional Tools
Jason Kent - AppSec Without Additional ToolsJason Kent - AppSec Without Additional Tools
Jason Kent - AppSec Without Additional Tools
centralohioissa
 
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
Css sf azure_8-9-17-protecting_web_apps_stephen coty_alCss sf azure_8-9-17-protecting_web_apps_stephen coty_al
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
Alert Logic
 
CSS17: Houston - Protecting Web Apps
CSS17: Houston - Protecting Web AppsCSS17: Houston - Protecting Web Apps
CSS17: Houston - Protecting Web Apps
Alert Logic
 
Presentation Verification & Validation
Presentation Verification & ValidationPresentation Verification & Validation
Presentation Verification & Validation
Elmar Selbach
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Aleksandar Bozinovski
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
Aleksandar Bozinovski
 
Web App Security Presentation by Ryan Holland - 05-31-2017
Web App Security Presentation by Ryan Holland - 05-31-2017Web App Security Presentation by Ryan Holland - 05-31-2017
Web App Security Presentation by Ryan Holland - 05-31-2017
TriNimbus
 
The Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance TuningThe Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance Tuning
jClarity
 
Making security-agile matt-tesauro
Making security-agile matt-tesauroMaking security-agile matt-tesauro
Making security-agile matt-tesauro
Matt Tesauro
 
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Denim Group
 

Similar to Salesforce static code analysis (20)

Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Security
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis Primer
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
 
AppSec in an Agile World
AppSec in an Agile WorldAppSec in an Agile World
AppSec in an Agile World
 
Programming languages and techniques for today’s embedded andIoT world
Programming languages and techniques for today’s embedded andIoT worldProgramming languages and techniques for today’s embedded andIoT world
Programming languages and techniques for today’s embedded andIoT world
 
Cyber security - It starts with the embedded system
Cyber security - It starts with the embedded systemCyber security - It starts with the embedded system
Cyber security - It starts with the embedded system
 
CSS 17: NYC - Protecting your Web Applications
CSS 17: NYC - Protecting your Web ApplicationsCSS 17: NYC - Protecting your Web Applications
CSS 17: NYC - Protecting your Web Applications
 
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austinDev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
 
Providence: rapid vulnerability prevention
Providence: rapid vulnerability preventionProvidence: rapid vulnerability prevention
Providence: rapid vulnerability prevention
 
Jason Kent - AppSec Without Additional Tools
Jason Kent - AppSec Without Additional ToolsJason Kent - AppSec Without Additional Tools
Jason Kent - AppSec Without Additional Tools
 
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
Css sf azure_8-9-17-protecting_web_apps_stephen coty_alCss sf azure_8-9-17-protecting_web_apps_stephen coty_al
Css sf azure_8-9-17-protecting_web_apps_stephen coty_al
 
CSS17: Houston - Protecting Web Apps
CSS17: Houston - Protecting Web AppsCSS17: Houston - Protecting Web Apps
CSS17: Houston - Protecting Web Apps
 
Presentation Verification & Validation
Presentation Verification & ValidationPresentation Verification & Validation
Presentation Verification & Validation
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
 
Web App Security Presentation by Ryan Holland - 05-31-2017
Web App Security Presentation by Ryan Holland - 05-31-2017Web App Security Presentation by Ryan Holland - 05-31-2017
Web App Security Presentation by Ryan Holland - 05-31-2017
 
The Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance TuningThe Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance Tuning
 
Making security-agile matt-tesauro
Making security-agile matt-tesauroMaking security-agile matt-tesauro
Making security-agile matt-tesauro
 
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Salesforce static code analysis

  • 1. Salesforce Static code Analysis An option to avoid most commonly done mistakes - Prasanna Deshpande Helpshift Inc. Tweet - @_prasu_ Email - prasu@prasannadeshpande.com 1
  • 2. Pareto Principle or Pareto Rule • 80% of software quality is maintained by 20% of programmers • 80% of bugs in an application are written by 20% of developers • 80% of bugs are fixed in 20% of time 2
  • 3. What is static code analysis • Static code analysis is a method of computer program debugging that is done by examine in the code without executing the program • It is a technique that allows, at the same time with unit-tests, dynamic code analysis, code review and others, to increase code quality, increase its reliability and decrease the development time. 3
  • 4. Who needs static code analysis • Any medium-sized and large software development company – to increase code reliability and decrease its price • Any small company and individual developers – in a lesser extent – to drink coffee instead of searching and fixing annoying bugs, • Anyone, who supports any old code 4
  • 5. Static code analysis advantages • Allows to find bugs on early stages (the earlier the bug was spotted, the cheaper it is to be fixed) • High analysis speed • Does not require to run the application, only an access to source code and (not always) – to preprocessed files • Allows to locate bugs in code that is rarely executed (exception handlers, for instance). 5
  • 6. Static code analysis disadvantages • Possibility of false positive alarm on correct code, • Correct positive alarms on old code, which works correctly and which should better not be bothered, may be nauseous. • Comparatively small class of bugs detected due to the exponential difficulty of “honest” bug search. • Does not detects logical errors (this is a drawback of almost all automatic testing tools in contrast to code review and manually written unit tests). 6
  • 7. How static code analysis can be done for Salesforce? 7
  • 8. Available tools • Force.com Security Source Scanner https://security.secure.force.com/sec urity/tools/forcecom/scanner • PMD http://pmd.sourceforge.net/snapshot/ pmd-apex/ • Checkmarx https://www.checkmarx.com/ • CodeScan - https://www.code-scan.com/ many more… 8
  • 10. Force.com Security Source Scanner Security Profile • Cross Site Scripting (reflected, stored, and DOM based) • SOQL/SOSL Injection • Access Control Issues (Sharing, FLS) • Cross site request forgery attacks • Arbitrary Redirects • Overly permissive postMessage targets • Static Resource referencing • Multiple Visualforce forms in the same page • Test methods without assert Quality Profile • DML statements inside loops • SOQL/SOSL inside loops • Hardcoding Trigger.new[0] • Hardcoding Trigger.old[0] • Queries with no Where clause or no LIMIT clause • Not bulkifying apex methods • Async (@future) methods inside loops • Hardcoding IDs • Multiple triggers on same object 10
  • 11. Limitations of Force.com security code scanner • Scan submissions to be less than 2 million source lines of code for Partners • Customers with production or enterprise organizations can scan 360000 lines of code in any 12 months period of time • Each scan is less than 5000 lines of code for Personal users. And sandbox cannot be scanned. • Scanning cannot be done for application on the NA21 or CS32 instances due to technical limitation of access • Inconsistent Scan results 11
  • 12. Report from Force.com Security source scanner 12
  • 13. Detail view of scanner reported issue 13
  • 15. Advantages of PMD • Free and open source • It can be part of ANT build script to generate error reports • It can also be added to Jenkins job for scheduled code scans • Eclipse plugin available • One can define their own custom rules 1. Custom rules for Naming convention 2. Comments format 15
  • 16. Available Rulesets from PMD • ApexUnit Should have asserts shouldn't have SeeallData=true • Complexity Too many nested IF, Excessive number of parameters for method, Excessive length of class, Excessive length of methods, Excessive public variables, Excessive class members • Performance SOQL in for loops, DML in for loops • Security Apex sharing violation, Open redirects, insecure endpoints, XSS from parameters, CRUD violation, • Style - Naming conventions for Methods and classes. 16
  • 17. How PMD works Let’s find a bug with PMD help! public class HotLeads { public Lead getTopLead() { return [SELECT … ] ; } } 17
  • 18. How PMD works Let’s find a bug: Sharing violation public with sharing class HotLeads { public Lead getTopLead() { return [SELECT … ] ; } } 18
  • 19. Mostly issues are categories in 2 types: • Definitely a bug: public class Foo {} • Might be a bug : public class without sharing Foo {} Expected : public with sharing Foo {} 19
  • 20. How PMD works Let’s find one more bug public void saveTopLead() { insert new Lead(firstName='Astro'); } 20
  • 21. How PMD works Let’s find one more bug: CRUD and FLS public void saveTopLead() { Boolean canCreate = Schema.sObjectType.Lead.fields.firstName.isCreateable(); if(canCreate) { insert new Lead(firstName='Astro'); } } 21
  • 22. How to use PMD • Download PMD from https://pmd.github.io/ • Create a ApexRules.xml • Execute the PMD script ./run.sh pmd -d "/Users/prasu/sfdc-app" -f html -R "apexrules.xml" -reportfile “output.html" ./run.sh pmd -d "<SourceCodeFolder>" -f html -R "<ApexRulesFile>" -reportfile “<OutputFileName" 22
  • 23. Sample Apex Rule File 23
  • 24. Report generated by PMD Apex 24
  • 25. 25