SlideShare a Scribd company logo
March 10, 2016
Secure Salesforce Development
on the Salesforce Platform
Speakers
Max Feldman
Product Security Engineer
Lehan Huang
Web Application
Security Engineer
Vinayendra
Nataraja
Product Security Engineer
@vinayendra
Forward-Looking Statement
Statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve
risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of
salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other
than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth,
earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of
belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for
our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate
of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with
completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability
to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our
limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential
factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year
and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are
available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and
may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are
currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Go Social!
Salesforce Developers
Salesforce Developers
Salesforce Developers
The video will be posted to YouTube & the
webinar recap page (same URL as registration).This webinar is being recorded!
@salesforcedevs / #forcewebinar
▪ Don’t wait until the end to ask your question!
– Technical support will answer questions starting now.
▪ Respect Q&A etiquette
– Please don’t repeat questions. The support team is working
their way down the queue.
▪ Stick around for live Q&A at the end
– Speakers will tackle more questions at the end, time-
allowing.
▪ Head to Developer Forums
– More questions? Visit developer.salesforce.com/forums
Have Questions?
Agenda
1. Roadmap for the year:
– Four webinars, one per quarter
2. Plan for today:
– SDL, CRUD/FLS, Sharing, SOQL, Q&A
3. Introductions:
– Max
– Lehan
– Vinayendra
Security and the Force.com Platform
 Force.com was designed to be flexible and support
delevoper and business needs
 Force.com provides many built-in protections to protect
developers and their user base
 Salesforce protects end users by ensuring that all
applications listed in the AppExchange undergo a security
review
Background
 Principle of Least Privilege
– Users should only have access to the minimum amount of
information required to accomplish their duties
– Their ability to take advantage of excess privilege purposefully or
accidentally should be minimized
 Context
– User context: Enforces user permissions, field-level security, and
sharing rules of the current user
– System context: Ignores user permissions, field-level security, and
rules of the current user
Secure Development Lifecycle
 Design
– Plan your application with security in mind
– https://developer.salesforce.com/page/Security_Design_Resources
 Development
– Follow best practicies for secure development, implement securely
– https://developer.salesforce.com/page/Secure_Coding_Guideline
 Testing
– Test for security (as one would test functionality)
 Release
– Be prepared for the discovery of any security flaws
– Staying secure is an ongoing process
FourZip App
 Display zip codes in 12345-1234 format
– Read from Account object for the shipping address
– Take the 5 digit zip and make an external call to retrieve the 4 digit
extension
– Display associated Opportunities
Account Profiles
 System Administrator
– Default administrator profile
– Has access to everything
 ZipFour User
– Cloned profile from standard user
– Can access ZipFour app
– Cannot see Account’s Annual Revenue field
– Cannot see Opportunity
FourZip
 What will we develop today?
– One VF page
– One Apex controller
– Mock API call for the external call
• This will be covered in part 3 of the webinar series – External
application/system integration best practices
– Wrapper classes to hold the zip+4 information, plus opportunities
– Let’s take a look at the code!
Secure Development on the Salesforce Platform - Part I
Secure Development on the Salesforce Platform - Part I
CRUD
What is CRUD?
Create, Read, Update, Delete
 Define user’s access for
each object
 Controlled on the profile
and permission set
CRUD
 Apex classes do not enforce CRUD
– Runs in system context
 Visualforce pages enforce CRUD
– Runs in user context
CRUD Demo
<sObject>.sObjectType.getDescribe()
• isCreateable()
• isAccessible()
• isUpdateable()
• isDeletable()
1 Public Class MyController {
2 Public String getmyAccount {
3 if (!Account.sObjectType.getDescribe().isAccessible()) {
4 return '';
5 }
6 }
Enforcing CRUD in Apex
Visualforce code patterns respect read in CRUD:
1. <apex:outputField value="{!sObject.Field__c}"/>
2. <apex:outputText value="{!sObject.Field__c}"/>
3. {!sObject.Field__c}
Visualforce code pattern does not respect read:
1. <apex:outputText value="{!wObject.String}"/>
2. <apex:outputText value="{!someVariable}"/>
Enforcing CRUD in Visualforce
CRUD Fix
Let’s fix the vulnerability and demo the fix
Best Practices for CRUD
 Always check CRUD permissions before performing the
operation in apex classes
 Not checking can give elevated access to users who should
not have it
FLS
What is FLS?
Field-Level Security
 Define user’s access to
fields on a given object
 Controlled on the profile
and permission sets
FLS for Developers
 Apex classes do not enforce FLS
– Runs in system context
 Visualforce pages enforce FLS
– Runs in user context
– Does not enforce FLS for dereferenced fields
• {!Contact.Email} = yes
• {!contact Email} = no
FLS Demo
Schema.sObjectType.<sObject>.fields.<field>
• isAccessible()
• isUpdateable()
1 Public Class MyController {
2 Public String getmyAccount {
3 if (!Schema.sObjectType.Account.fields.Name.isAccessible()) {
4 return '';
5 }
6 ...
7 }
Enforcing FLS in Apex
When Sobject is assigned a primitive
Apex:
Random_Sensitive_Object_1__c r; // Salesforce sObject
wRandom_Sensitive_Object_1 wR; // Custom wrapper object
wR.Sensitive_Number = r.Sensitive_Number__c;
Visualforce:
<apex:OutputText value="{!r.Sensitive_Number__c}" /> <!--
FLS RESPECTED -->
<apex:OutputText value="{!wR.Sensitive_Number}" /> <!-- FLS
IGNORED -->
When does the Platform stop respecting FLS?
FLS Fix
Let’s fix the vulnerability and demo the fix
Best Practices for FLS
 Use sObject references whenever possible
 Iterate through your list of fields and check FLS for each
field
Sharing
What is Sharing?
Record-level access
 Dictates which records
of an object a user can
see
 Controlled outside the
profile via org-defaults,
roles, ownership, and
sharing rules
How is Sharing Enforced?
 Apex classes do not enforce sharing by default
– Runs in system context
– Exceptions: anonymous code blocks, developer console, and
standard controllers execute in user context
 Visualforce pages depend on controllers for record access
Sharing/CRUD/FLS
FLS
Sharing
CRUD
Sharing Demo
1 Public with sharing Class MyController {
2 // Code enforces current user’s sharing rules
3 Public without sharing Class MyInnerClass {
4 // Code doesn’t enforce current user’s sharing rules
5 }
6 }
Enforcing Sharing in Apex
 Default behavior is without sharing
– Use with sharing keyword to enforce sharing
 If a class isn’t declared as either with or without sharing, the current
sharing rules remain in effect
 The sharing setting of the class where the method is defined is applied,
not of the class where the method is called
Sharing Fix
Let’s fix the vulnerability and demo the fix
Best Practices for Sharing
 Explicitly declare with sharing or without sharing for all
classes in your code
 If you must use without sharing, document the reasoning in
a comment block
 Sharing keywords don’t enforce CRUD and FLS
SOQL
SOQL vs SQL
Salesforce Object Query Language vs Structured Query Language
 SOQL is the query language used in the Salesforce
platform
 SOQL only allows the SELECT command portion SQL
 SOQL does not allow command execution, or wild card (*)
for fields
SQL Injection
 SQL Injection is an attack where user input is allowed to
modify the structure of an SQL query and perform
unexpected actions
 Sample SQL query subject to SQL injection:
 If un_iput= admin’-- and user input is not modified before
passing it to the query we get:
SOQL Injection
 SOQL Injection only occurs when dynamic SOQL queries
are used without proper manipulation of user input
 Sample code block:
 User input:
 Final query:
SOQL Injection Demo
SOQL Injection Mitigations
 Static query + bind variable:
 Wrap user input in string.escapeSingleQuotes()
– This will not prevent all the attacks.
– Sample query:
– User input that could bypass this defense mechanism
SOQL Injection Fix
Let’s fix the vulnerability and demo the fix
Summary
Developer practices for respecting authorization model
 CRUD
– Object-level permission. Should the user have access to this object?
 FLS
– Field-level permission. Should the user have access to this field?
 Sharing
– Record-level permission. Should the user have access to this
record?
 SOQL
– Salesforce Object Query Language. Is there injection?
Additional Resources
Security Implementation Guide
https://developer.salesforce.com/././securityImplGuide/ (full link hidden)
CRUD & FLS Enforcement Guide
https://developer.salesforce.com/page/Enforcing_CRUD_and_FLS
Using with sharing or without sharing Keywords
https://developer.salesforce.com/./././apex_classes_keywords_sharing (full link hidden)
SOQL Injection
http://sfdc.co/SOQLInjection
Secure Coding Guidelines
https://developer.salesforce.com/page/Secure_Coding_Guideline
Salesforce Developer Security Forum
https://developer.salesforce.com/forums
Salesforce World Tour @ CeBIT
Hannover, 14.-18. März 2016
Secure Development on the Salesforce Platform - Part I
Q & A
Share Your Feedback: http://bit.ly/securedevelopment
Join the conversation:
@salesforcedevs
@SecureCloudDev
Survey
Your feedback is crucial to the success
of our webinar programs. Thank you!
http://bit.ly/securedevelopment
Thank You

More Related Content

What's hot (20)

PPTX
Mastering Force.com: Advanced Visualforce
Salesforce Developers
 
PDF
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
PDF
Salesforce API Series: Integrating Applications with Force.com Webinar
Salesforce Developers
 
PPTX
Lightning Component - Components, Actions and Events
Durgesh Dhoot
 
PPTX
Integrating with salesforce
Mark Adcock
 
PPTX
Building apps faster with lightning and winter '17
Salesforce Developers
 
PDF
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce Developers
 
PPT
Elevate workshop programmatic_2014
David Scruggs
 
PDF
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
PPTX
Introduction to the Wave Platform API
Salesforce Developers
 
PDF
Lightning Design System and Components for Visualforce Developers
Salesforce Developers
 
PPTX
Process Automation on Lightning Platform Workshop
Salesforce Developers
 
PPTX
Coding Apps in the Cloud with Force.com - Part 2
Salesforce Developers
 
PPTX
Introduction to Apex for Developers
Salesforce Developers
 
PDF
SLDS and Lightning Components
Salesforce Developers
 
PPTX
Build and Package Lightning Components for Lightning Exchange
Salesforce Developers
 
PPTX
Using Apex for REST Integration
Salesforce Developers
 
PDF
Write bulletproof trigger code
Salesforce Developers
 
PDF
Local development with Open Source Base Components
Salesforce Developers
 
PPTX
Build Better Communities with Lightning
Salesforce Developers
 
Mastering Force.com: Advanced Visualforce
Salesforce Developers
 
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
Salesforce API Series: Integrating Applications with Force.com Webinar
Salesforce Developers
 
Lightning Component - Components, Actions and Events
Durgesh Dhoot
 
Integrating with salesforce
Mark Adcock
 
Building apps faster with lightning and winter '17
Salesforce Developers
 
Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce Developers
 
Elevate workshop programmatic_2014
David Scruggs
 
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
Introduction to the Wave Platform API
Salesforce Developers
 
Lightning Design System and Components for Visualforce Developers
Salesforce Developers
 
Process Automation on Lightning Platform Workshop
Salesforce Developers
 
Coding Apps in the Cloud with Force.com - Part 2
Salesforce Developers
 
Introduction to Apex for Developers
Salesforce Developers
 
SLDS and Lightning Components
Salesforce Developers
 
Build and Package Lightning Components for Lightning Exchange
Salesforce Developers
 
Using Apex for REST Integration
Salesforce Developers
 
Write bulletproof trigger code
Salesforce Developers
 
Local development with Open Source Base Components
Salesforce Developers
 
Build Better Communities with Lightning
Salesforce Developers
 

Similar to Secure Development on the Salesforce Platform - Part I (20)

PDF
Secure Salesforce: CRUD / FLS / Sharing
Salesforce Developers
 
PPTX
Secure Coding: Field-level Security, CRUD, and Sharing
Salesforce Developers
 
PPTX
Finding Security Issues Fast!
Salesforce Engineering
 
PPTX
Elevate Tel Aviv
sready
 
PDF
Intro to Apex Programmers
Salesforce Developers
 
PPTX
Security Boundaries in Apex
Salesforce Developers
 
PPTX
Force.com security
Vijay Naik
 
PPTX
Force.com Friday : Intro to Apex
Salesforce Developers
 
PPTX
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
PDF
Force.com Friday: Intro to Force.com
Salesforce Developers
 
PDF
Elevate london dec 2014.pptx
Peter Chittum
 
PDF
Introduction to Force.com
Salesforce Developers
 
PPTX
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
PDF
Winter 14 Release Developer Preview
Salesforce Developers
 
PPTX
Elevate Madrid Essentials - Advance Track
CarolEnLaNube
 
PDF
Five Developer Tips Every Admin Needs To Know
Salesforce Developers
 
PPTX
Salesforce Campus Tour - Developer Intro
James Ward
 
PPTX
Hands-On Workshop: Introduction to Development on Force.com for Developers
Salesforce Developers
 
PDF
Manage Development in Your Org with Salesforce Governance Framework
Salesforce Developers
 
PPTX
Apex for Admins: Beyond the Basics (Part 2)
Salesforce Developers
 
Secure Salesforce: CRUD / FLS / Sharing
Salesforce Developers
 
Secure Coding: Field-level Security, CRUD, and Sharing
Salesforce Developers
 
Finding Security Issues Fast!
Salesforce Engineering
 
Elevate Tel Aviv
sready
 
Intro to Apex Programmers
Salesforce Developers
 
Security Boundaries in Apex
Salesforce Developers
 
Force.com security
Vijay Naik
 
Force.com Friday : Intro to Apex
Salesforce Developers
 
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
Force.com Friday: Intro to Force.com
Salesforce Developers
 
Elevate london dec 2014.pptx
Peter Chittum
 
Introduction to Force.com
Salesforce Developers
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
Winter 14 Release Developer Preview
Salesforce Developers
 
Elevate Madrid Essentials - Advance Track
CarolEnLaNube
 
Five Developer Tips Every Admin Needs To Know
Salesforce Developers
 
Salesforce Campus Tour - Developer Intro
James Ward
 
Hands-On Workshop: Introduction to Development on Force.com for Developers
Salesforce Developers
 
Manage Development in Your Org with Salesforce Governance Framework
Salesforce Developers
 
Apex for Admins: Beyond the Basics (Part 2)
Salesforce Developers
 
Ad

More from Salesforce Developers (20)

PDF
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
PDF
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
PPTX
TrailheaDX India : Developer Highlights
Salesforce Developers
 
PDF
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
PPTX
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
PPTX
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
PPTX
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
PDF
Live coding with LWC
Salesforce Developers
 
PDF
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
PDF
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
PDF
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
PDF
Modern Development with Salesforce DX
Salesforce Developers
 
PDF
Get Into Lightning Flow Development
Salesforce Developers
 
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
PDF
Introduction to MuleSoft
Salesforce Developers
 
PDF
Modern App Dev: Modular Development Strategies
Salesforce Developers
 
PPTX
Dreamforce Developer Recap
Salesforce Developers
 
PDF
Vs Code for Salesforce Developers
Salesforce Developers
 
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
TrailheaDX India : Developer Highlights
Salesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
Live coding with LWC
Salesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
Modern Development with Salesforce DX
Salesforce Developers
 
Get Into Lightning Flow Development
Salesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
Introduction to MuleSoft
Salesforce Developers
 
Modern App Dev: Modular Development Strategies
Salesforce Developers
 
Dreamforce Developer Recap
Salesforce Developers
 
Vs Code for Salesforce Developers
Salesforce Developers
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Digital Circuits, important subject in CS
contactparinay1
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 

Secure Development on the Salesforce Platform - Part I

  • 1. March 10, 2016 Secure Salesforce Development on the Salesforce Platform
  • 2. Speakers Max Feldman Product Security Engineer Lehan Huang Web Application Security Engineer Vinayendra Nataraja Product Security Engineer @vinayendra
  • 3. Forward-Looking Statement Statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 4. Go Social! Salesforce Developers Salesforce Developers Salesforce Developers The video will be posted to YouTube & the webinar recap page (same URL as registration).This webinar is being recorded! @salesforcedevs / #forcewebinar
  • 5. ▪ Don’t wait until the end to ask your question! – Technical support will answer questions starting now. ▪ Respect Q&A etiquette – Please don’t repeat questions. The support team is working their way down the queue. ▪ Stick around for live Q&A at the end – Speakers will tackle more questions at the end, time- allowing. ▪ Head to Developer Forums – More questions? Visit developer.salesforce.com/forums Have Questions?
  • 6. Agenda 1. Roadmap for the year: – Four webinars, one per quarter 2. Plan for today: – SDL, CRUD/FLS, Sharing, SOQL, Q&A 3. Introductions: – Max – Lehan – Vinayendra
  • 7. Security and the Force.com Platform  Force.com was designed to be flexible and support delevoper and business needs  Force.com provides many built-in protections to protect developers and their user base  Salesforce protects end users by ensuring that all applications listed in the AppExchange undergo a security review
  • 8. Background  Principle of Least Privilege – Users should only have access to the minimum amount of information required to accomplish their duties – Their ability to take advantage of excess privilege purposefully or accidentally should be minimized  Context – User context: Enforces user permissions, field-level security, and sharing rules of the current user – System context: Ignores user permissions, field-level security, and rules of the current user
  • 9. Secure Development Lifecycle  Design – Plan your application with security in mind – https://developer.salesforce.com/page/Security_Design_Resources  Development – Follow best practicies for secure development, implement securely – https://developer.salesforce.com/page/Secure_Coding_Guideline  Testing – Test for security (as one would test functionality)  Release – Be prepared for the discovery of any security flaws – Staying secure is an ongoing process
  • 10. FourZip App  Display zip codes in 12345-1234 format – Read from Account object for the shipping address – Take the 5 digit zip and make an external call to retrieve the 4 digit extension – Display associated Opportunities
  • 11. Account Profiles  System Administrator – Default administrator profile – Has access to everything  ZipFour User – Cloned profile from standard user – Can access ZipFour app – Cannot see Account’s Annual Revenue field – Cannot see Opportunity
  • 12. FourZip  What will we develop today? – One VF page – One Apex controller – Mock API call for the external call • This will be covered in part 3 of the webinar series – External application/system integration best practices – Wrapper classes to hold the zip+4 information, plus opportunities – Let’s take a look at the code!
  • 15. CRUD
  • 16. What is CRUD? Create, Read, Update, Delete  Define user’s access for each object  Controlled on the profile and permission set
  • 17. CRUD  Apex classes do not enforce CRUD – Runs in system context  Visualforce pages enforce CRUD – Runs in user context
  • 19. <sObject>.sObjectType.getDescribe() • isCreateable() • isAccessible() • isUpdateable() • isDeletable() 1 Public Class MyController { 2 Public String getmyAccount { 3 if (!Account.sObjectType.getDescribe().isAccessible()) { 4 return ''; 5 } 6 } Enforcing CRUD in Apex
  • 20. Visualforce code patterns respect read in CRUD: 1. <apex:outputField value="{!sObject.Field__c}"/> 2. <apex:outputText value="{!sObject.Field__c}"/> 3. {!sObject.Field__c} Visualforce code pattern does not respect read: 1. <apex:outputText value="{!wObject.String}"/> 2. <apex:outputText value="{!someVariable}"/> Enforcing CRUD in Visualforce
  • 21. CRUD Fix Let’s fix the vulnerability and demo the fix
  • 22. Best Practices for CRUD  Always check CRUD permissions before performing the operation in apex classes  Not checking can give elevated access to users who should not have it
  • 23. FLS
  • 24. What is FLS? Field-Level Security  Define user’s access to fields on a given object  Controlled on the profile and permission sets
  • 25. FLS for Developers  Apex classes do not enforce FLS – Runs in system context  Visualforce pages enforce FLS – Runs in user context – Does not enforce FLS for dereferenced fields • {!Contact.Email} = yes • {!contact Email} = no
  • 27. Schema.sObjectType.<sObject>.fields.<field> • isAccessible() • isUpdateable() 1 Public Class MyController { 2 Public String getmyAccount { 3 if (!Schema.sObjectType.Account.fields.Name.isAccessible()) { 4 return ''; 5 } 6 ... 7 } Enforcing FLS in Apex
  • 28. When Sobject is assigned a primitive Apex: Random_Sensitive_Object_1__c r; // Salesforce sObject wRandom_Sensitive_Object_1 wR; // Custom wrapper object wR.Sensitive_Number = r.Sensitive_Number__c; Visualforce: <apex:OutputText value="{!r.Sensitive_Number__c}" /> <!-- FLS RESPECTED --> <apex:OutputText value="{!wR.Sensitive_Number}" /> <!-- FLS IGNORED --> When does the Platform stop respecting FLS?
  • 29. FLS Fix Let’s fix the vulnerability and demo the fix
  • 30. Best Practices for FLS  Use sObject references whenever possible  Iterate through your list of fields and check FLS for each field
  • 32. What is Sharing? Record-level access  Dictates which records of an object a user can see  Controlled outside the profile via org-defaults, roles, ownership, and sharing rules
  • 33. How is Sharing Enforced?  Apex classes do not enforce sharing by default – Runs in system context – Exceptions: anonymous code blocks, developer console, and standard controllers execute in user context  Visualforce pages depend on controllers for record access
  • 36. 1 Public with sharing Class MyController { 2 // Code enforces current user’s sharing rules 3 Public without sharing Class MyInnerClass { 4 // Code doesn’t enforce current user’s sharing rules 5 } 6 } Enforcing Sharing in Apex  Default behavior is without sharing – Use with sharing keyword to enforce sharing  If a class isn’t declared as either with or without sharing, the current sharing rules remain in effect  The sharing setting of the class where the method is defined is applied, not of the class where the method is called
  • 37. Sharing Fix Let’s fix the vulnerability and demo the fix
  • 38. Best Practices for Sharing  Explicitly declare with sharing or without sharing for all classes in your code  If you must use without sharing, document the reasoning in a comment block  Sharing keywords don’t enforce CRUD and FLS
  • 39. SOQL
  • 40. SOQL vs SQL Salesforce Object Query Language vs Structured Query Language  SOQL is the query language used in the Salesforce platform  SOQL only allows the SELECT command portion SQL  SOQL does not allow command execution, or wild card (*) for fields
  • 41. SQL Injection  SQL Injection is an attack where user input is allowed to modify the structure of an SQL query and perform unexpected actions  Sample SQL query subject to SQL injection:  If un_iput= admin’-- and user input is not modified before passing it to the query we get:
  • 42. SOQL Injection  SOQL Injection only occurs when dynamic SOQL queries are used without proper manipulation of user input  Sample code block:  User input:  Final query:
  • 44. SOQL Injection Mitigations  Static query + bind variable:  Wrap user input in string.escapeSingleQuotes() – This will not prevent all the attacks. – Sample query: – User input that could bypass this defense mechanism
  • 45. SOQL Injection Fix Let’s fix the vulnerability and demo the fix
  • 46. Summary Developer practices for respecting authorization model  CRUD – Object-level permission. Should the user have access to this object?  FLS – Field-level permission. Should the user have access to this field?  Sharing – Record-level permission. Should the user have access to this record?  SOQL – Salesforce Object Query Language. Is there injection?
  • 47. Additional Resources Security Implementation Guide https://developer.salesforce.com/././securityImplGuide/ (full link hidden) CRUD & FLS Enforcement Guide https://developer.salesforce.com/page/Enforcing_CRUD_and_FLS Using with sharing or without sharing Keywords https://developer.salesforce.com/./././apex_classes_keywords_sharing (full link hidden) SOQL Injection http://sfdc.co/SOQLInjection Secure Coding Guidelines https://developer.salesforce.com/page/Secure_Coding_Guideline Salesforce Developer Security Forum https://developer.salesforce.com/forums
  • 48. Salesforce World Tour @ CeBIT Hannover, 14.-18. März 2016
  • 50. Q & A Share Your Feedback: http://bit.ly/securedevelopment Join the conversation: @salesforcedevs @SecureCloudDev
  • 51. Survey Your feedback is crucial to the success of our webinar programs. Thank you! http://bit.ly/securedevelopment