SlideShare a Scribd company logo
1 of 47
Download to read offline
Protect your data against malicious 
scripts 
Xiaoran Wang 
Senior Product Security Engineer 
@0x1a0ran
Safe Harbor 
Safe harbor 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.
Agenda 
• Background 
• HTML Parsing 
• URL Parsing 
• JavaScript Parsing 
• Parsing Order 
• Salesforce protections
Background
Background 
XSS 101 
• <html> Hello <%=userName> ! </html> 
– When username is “Cookie Monster <script>stealMyCookie();</script>” 
– <html>Hello Cookie Monster ! <script>stealMyCookie();</script> </html>
Background 
Introduction 
• Browser Parsings are complex 
– Several Parsers 
– Rounds of decodings 
• How do we know whether a particularly encoded script is going to execute in certain 
context?
Background 
Will this execute? 
<a href="&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;:%61 
%6c%65%72%74%28%32%29"></a> 
Charater entity encoded “javascript” and URL encoded “alert(2)” 
<a href=“javascript:alert(2)”></a>
Background 
Will this execute? 
<script>u0061u006cu0065u0072u0074(10);</script> 
Unicode Escape Sequence encoded alert 
<script>alert(10);</script>
Background 
Will this execute? 
<button onclick="confirm('7&#39;);">Button</button> 
Character Entity Encoded ‘ (single quote) 
<button onclick=“confirm(‘7’);”>Button</button>
Background 
Will this execute? 
<a 
href="&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x25; 
&#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33; 
&#x36;&#x25;&#x33;&#x31;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30; 
&#x25;&#x33;&#x30;&#x25;&#x33;&#x36;&#x25;&#x36;&#x33;&#x25;&#x35;&#x63;&#x25; 
&#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33;&#x36;&#x25;&#x33; 
&#x35;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30; 
&#x25;&#x33;&#x37;&#x25;&#x33;&#x32;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25; 
&#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33;&#x37;&#x25;&#x33;&#x34;&#x28;&#x31; 
&#x35;&#x29;"></a> 
????
HTML Parsing
HTML Parsing 
Basics 
• HTML parser works as a state machine 
• Recognize valid tags as tokens 
• “<“ make it go into Tag Open State 
• We don’t want arbitrary user data be treated as a token 
• Character entity encoding is here to help 
– ‘<‘ à ‘&lt;’ 
– ‘>’ à ‘&gt;’ 
– etc.
HTML Parsing 
States 
• Only three parsing states can contain character entities 
– Data state 
• <div>&lt;img src=x onerror=alert(123)&gt;</div> 
– Attribute value state 
• <div id=“&lt;img src=x onerror=alert(123)&gt;”></div> 
– RCDATA state 
• <title>&lt;img src=x onerror=alert(123)&gt;</title> 
• Any ‘<‘ decoded from ‘&lt;’ in these states will NOT be treated as token
HTML Parsing 
HTML Elements 
• Void elements 
– <area>, <base>, <br>, <img>, <input>, <keygen>, <link>, … 
– Cannot have any contents 
• Raw text elements 
– <script>, <style> 
– Text only 
• RCDATA elements 
– <textarea>, <title> 
– Text and character references 
• Foreign elements 
• Normal elements
HTML Parsing 
RCDATA state 
• When the parser is in <textarea> or <title> 
• Character entities will be decoded 
– <textarea>&lt;img src=x onerror=alert(123)&gt;</textarea> 
• Even open tags will NOT be trigger the “Open Tag State” 
– <textarea><img src=x onerror=alert(123)></textarea>
URL Parsing
URL Parsing 
Basics 
• URL parser works as a state machine 
• Decoding using UTF-8 
• URL scheme has to be in ASCII characters 
– U+0041-U+005A 
– U+0061-U+007A
URL Parsing 
Would it execute? 
<a href="%6a%61%76%61%73%63%72%69%70%74:alert(1)"></a> 
URL encoded “javascript” 
<a href=“javascript:alert(1)”></a>
URL Parsing 
Would it execute? NO 
<a href="%6a%61%76%61%73%63%72%69%70%74:alert(1)"></a> 
URL encoded “javascript” 
<a href=“javascript:alert(1)”></a> 
The scheme must not be encoded
JavaScript Parsing
JavaScript Parsing 
Basics 
• Context free language 
– Context free grammar for parsing 
• Error Intolerant 
• Located in <script> tags or inline 
– <script> is a RAW element thus not having HTML decoding
JavaScript Parsing 
Would it execute? 
<script>&#97;&#108;&#101;&#114;&#116&#40;&#57;&#41;&#59</script> 
Character entity encoded alert(9); 
<script>alert(9);</script>
JavaScript Parsing 
Would it execute? 
<script>&#97;&#108;&#101;&#114;&#116&#40;&#57;&#41;&#59</script> 
Character entity encoded alert(9); 
<script>alert(9);</script> 
NO
JavaScript Parsing 
Would it execute? 
<a href=“&#x6a;avascript:alert(9)”></a> 
Character encoded ‘j’ 
<a href=“javascript:alert(9)”></a>
JavaScript Parsing 
Would it execute? 
<a href=“&#x6a;avascript:alert(9)”></a> 
Character encoded ‘j’ 
<a href=“javascript:alert(9)”></a> 
YES
JavaScript Parsing 
Unicode Escape Sequence 
• uXXXX 
• If JavaScript is encoded using uXXXX, would it execute? 
– It depends on where the encoded content is located 
• In strings 
• In identifier names 
• In control characters
JavaScript Parsing 
Strings 
• alert(‘my string’); 
• String literals are surrounded by single or double quotes 
• Unicode escape sequence will not break out of the string context 
– alert(‘my stringu0027’); (u0027 is single quote) 
• ECMA-262 edition5.1 Rev 6, Clause 6 
– “a Unicode escape sequence occurring within a string literal in an ECMAScript program always 
contributes a Unicode character to the literal and is never interpreted as a line terminator or as a 
quote mark that might terminate the string literal.”
JavaScript Parsing 
Identifier names 
• alert(‘my string’); 
• Unicode escape sequence will be decoded in identifier names 
– u0061lert(‘my string’); (u0061 is ‘a’) 
• ECMA-262 edition5.1 Rev 6, Clause 6 
– "Unicode escape sequences are also permitted in an IdentifierName, where they contribute a 
single character to the IdentifierName, as computed by the CV of the UnicodeEscapeSequence 
(see 7.8.4). The  preceding the UnicodeEscapeSequence does not contribute a character to the 
IdentifierName. A UnicodeEscapeSequence cannot be used to put a character into an 
IdentifierName that would otherwise be illegal."
JavaScript Parsing 
Control characters 
• alert(‘my string’); 
• Unicode escape sequence will not be decoded as control characters 
– alertu0028‘my string’); (u0028 is ‘(’)
JavaScript Parsing 
Would it execute? 
<script>u0061u006cu0065u0072u0074(u0031u0032)</script> 
Unicode escape sequence encoded ‘alert(12)’ 
<script>alert(12)</script>
JavaScript Parsing 
Would it execute? NO 
<script>u0061u006cu0065u0072u0074(u0031u0032)</script> 
Unicode escape sequence encoded ‘alert(12)’ 
<script>alert(12)</script> 
u0031u0032 is not part of an identifier name or in a string literal
Parsing Order
Parsing Order 
Basics 
• All the parsers work together in an order 
• The order depends on the location of the content to parse 
• Each round of parsing will decode the content once 
• The content needs to be encoded in the reverse order
Parsing Order 
Example: Two rounds of encoding 
• <a href=”/foo?name=UserInput"></a> 
– HTML parser first decode the whole document (UserInput is HTML entity decoded) 
– HTML parser sees the href attributes 
– HTML parser ask URL parser to decode the URL 
– URL parser decode the href (UserInput is URL decoded) 
• In order to make the UserInput safe from XSS 
– URL encode the UserInput first 
– Then HTML entity encode the UserInput 
– <a href=“/foo?name=HTMLEncode(URLEncode(UserInput))”></a>
Parsing Order 
Example: Three rounds of encoding 
• <a href=# onclick=”window.open(‘/foo?name=UserInput’)"></a> 
– HTML parser first decode the whole document (UserInput is HTML entity decoded) 
– HTML parser sees the onclick attributes 
– HTML parser asks the JavaScript parser to handle the JavaScript 
– JavaScript parser decode the string in onclick (UserInput is JavaScript decoded) 
– JavaScript parser sees the window.open function, expecting a URL in the string 
– JavaScript parser ask URL parser to decode the URL 
– URL parser decode the string (UserInput is URL decoded) 
• In order to make the UserInput safe from XSS 
– <a href=# onclick=“window.open(‘/foo? 
name=HTMLEncode(JSEncode(URLEncode(UserInput)))’)”></a>
Parsing Order 
Example: more rounds of encoding 
• <a href="javascript:window.open('/foo?name=UserInput')"> 
• Advice: Don’t do this… because you have to encode it four times 
– <a 
href=“javascript:window.open(‘HTMLEncode(URLEncode(JSEncode(URLEncode(UserInput))))’)”> 
</a>
Salesforce Protections
Salesforce Protections 
Visualforce 
• All {!MergeFields} are html encoded automatically 
• Encoding functions available for complex contexts 
– HTMLENCODE 
– JSENCODE 
– URLENCODE 
– JSINHTMLENCODE 
• Use them in the correct order to properly escape your user input
Salesforce Protections 
Visualforce – Encoding Functions 
• HTMLENCODE 
– Encode characters in HTML context 
– <apex:outputText value=“{!HTMLENCODE(userInput)}” escape=“false”/> 
– This is anti-pattern, use escape automatically 
– <apex:outputText value=“{!userInput}” />
Salesforce Protections 
Visualforce – Encoding Functions 
• JSENCODE 
– Encode characters in JavaScript string literal context 
– <script>var string = “{!JSENCODE(userInput)}”;</script>
Salesforce Protections 
Visualforce – Encoding Functions 
• URLENCODE 
– Encode characters in URL context 
– <a href=“/foo?name={!URLENCODE(userInput)}”></a> 
– Developers need to make sure userInput has a expected scheme 
• userInput.startsWith(‘https’) 
• Make sure it is not a javascript: scheme
Salesforce Protections 
Visualforce – Encoding Functions 
• JSINHTMLENCODE 
– Encode characters in HTML tags in JavaScript 
– node.innerHTML = “<div id=‘” + {!JSINHTMLENCODE(userInput)} + “’>My Div</div>”;
Salesforce Protections 
Visualforce – Encoding Example 
– <a href=# onclick=”window.open(‘/foo?name={!userInput}’)"></a> 
– UNSAFE 
• <a href=# onclick=“window.open(‘/foo?name={! 
(JSENCODE(URLENCODE(userInput))}’)”></a> 
– SAFE
Other Salesforce security controls 
• Data protections 
– CRUD 
– FLS 
– Sharing 
– Encrypted custom fields 
– Etc. 
• Operation protections 
– Login IP Range 
– Login Hours 
– Two Factor Authentications 
– Audit Trails 
– Etc.
Questions?
Secure Development Sessions 
Secure Coding: Field-level Security, CRUD, and Sharing 
Monday, October 13 @ 11:00 a.m. - 11:40 a.m. 
Secure Coding: Storing Secrets in Your Salesforce Instance 
Monday, October 13 @ 2:00 p.m. - 2:40 p.m. 
Building Secure Mobile Apps 
Monday, October 13 @ 5:00 p.m. - 5:40 p.m. 
Protect Your Data Against Malicious Scripts 
Tuesday, October 14 @ 11:00 a.m. - 11:40 a.m. 
Secure Coding: External App Integration 
Wednesday, October 15 @ 9:00 a.m. - 9:40 a.m. 
Secure Coding: SSL, SOAP, and REST 
Thursday, October 16 @ 10:30 a.m. - 11:10 a.m. 
Announcements: 
Force.com Code Scanner now 
supports Salesforce1 and 
JavaScript! Try it here: 
http://bit.ly/SF1Scanner 
Chimera Web App Scanner 
alpha nominations are open. 
Partners apply at: 
http://bit.ly/SFChimera 
Live security office hours are 
available in the partner zone.
Protect your data with script security

More Related Content

Similar to Protect your data with script security

Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2Salesforce Developers
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web AppsFrank Kim
 
Secure Salesforce: Code Scanning with Checkmarx
Secure Salesforce: Code Scanning with CheckmarxSecure Salesforce: Code Scanning with Checkmarx
Secure Salesforce: Code Scanning with CheckmarxSalesforce Developers
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsSalesforce Developers
 
From Developer to Production, Promoting your Webservices
From Developer to Production, Promoting your WebservicesFrom Developer to Production, Promoting your Webservices
From Developer to Production, Promoting your Webserviceskingsfleet
 
Avoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might thinkAvoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might thinkErlend Oftedal
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesCarol McDonald
 
Security Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramSecurity Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramOpenDNS
 
Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Mark Adcock
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Salesforce Developers
 
7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce PagesSalesforce Developers
 
Force.com Friday: Intro to Force.com
Force.com Friday: Intro to Force.comForce.com Friday: Intro to Force.com
Force.com Friday: Intro to Force.comSalesforce Developers
 
Visualforce Hack for Junction Objects
Visualforce Hack for Junction ObjectsVisualforce Hack for Junction Objects
Visualforce Hack for Junction ObjectsRitesh Aswaney
 
Hca advanced developer workshop
Hca advanced developer workshopHca advanced developer workshop
Hca advanced developer workshopDavid Scruggs
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformIhor Uzhvenko
 
The Enterprise Architecture You Always Wanted
The Enterprise Architecture You Always WantedThe Enterprise Architecture You Always Wanted
The Enterprise Architecture You Always WantedThoughtworks
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
Secure Salesforce: Common Secure Coding Mistakes
Secure Salesforce: Common Secure Coding MistakesSecure Salesforce: Common Secure Coding Mistakes
Secure Salesforce: Common Secure Coding MistakesSalesforce Developers
 
OData: A Standard API for Data Access
OData: A Standard API for Data AccessOData: A Standard API for Data Access
OData: A Standard API for Data AccessPat Patterson
 

Similar to Protect your data with script security (20)

Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
Secure Salesforce: Code Scanning with Checkmarx
Secure Salesforce: Code Scanning with CheckmarxSecure Salesforce: Code Scanning with Checkmarx
Secure Salesforce: Code Scanning with Checkmarx
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard Problems
 
From Developer to Production, Promoting your Webservices
From Developer to Production, Promoting your WebservicesFrom Developer to Production, Promoting your Webservices
From Developer to Production, Promoting your Webservices
 
Avoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might thinkAvoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might think
 
Web Application Defences
Web Application DefencesWeb Application Defences
Web Application Defences
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Security Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramSecurity Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training Program
 
Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17
 
7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages7 Habits of Highly Efficient Visualforce Pages
7 Habits of Highly Efficient Visualforce Pages
 
Force.com Friday: Intro to Force.com
Force.com Friday: Intro to Force.comForce.com Friday: Intro to Force.com
Force.com Friday: Intro to Force.com
 
Visualforce Hack for Junction Objects
Visualforce Hack for Junction ObjectsVisualforce Hack for Junction Objects
Visualforce Hack for Junction Objects
 
Hca advanced developer workshop
Hca advanced developer workshopHca advanced developer workshop
Hca advanced developer workshop
 
Hackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platformHackazon realistic e-commerce Hack platform
Hackazon realistic e-commerce Hack platform
 
The Enterprise Architecture You Always Wanted
The Enterprise Architecture You Always WantedThe Enterprise Architecture You Always Wanted
The Enterprise Architecture You Always Wanted
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Secure Salesforce: Common Secure Coding Mistakes
Secure Salesforce: Common Secure Coding MistakesSecure Salesforce: Common Secure Coding Mistakes
Secure Salesforce: Common Secure Coding Mistakes
 
OData: A Standard API for Data Access
OData: A Standard API for Data AccessOData: A Standard API for Data Access
OData: A Standard API for Data Access
 

More from Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

More from Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 

Recently uploaded

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 

Protect your data with script security

  • 1. Protect your data against malicious scripts Xiaoran Wang Senior Product Security Engineer @0x1a0ran
  • 2. Safe Harbor Safe harbor 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.
  • 3. Agenda • Background • HTML Parsing • URL Parsing • JavaScript Parsing • Parsing Order • Salesforce protections
  • 5. Background XSS 101 • <html> Hello <%=userName> ! </html> – When username is “Cookie Monster <script>stealMyCookie();</script>” – <html>Hello Cookie Monster ! <script>stealMyCookie();</script> </html>
  • 6. Background Introduction • Browser Parsings are complex – Several Parsers – Rounds of decodings • How do we know whether a particularly encoded script is going to execute in certain context?
  • 7. Background Will this execute? <a href="&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;:%61 %6c%65%72%74%28%32%29"></a> Charater entity encoded “javascript” and URL encoded “alert(2)” <a href=“javascript:alert(2)”></a>
  • 8. Background Will this execute? <script>u0061u006cu0065u0072u0074(10);</script> Unicode Escape Sequence encoded alert <script>alert(10);</script>
  • 9. Background Will this execute? <button onclick="confirm('7&#39;);">Button</button> Character Entity Encoded ‘ (single quote) <button onclick=“confirm(‘7’);”>Button</button>
  • 10. Background Will this execute? <a href="&#x6a;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3a;&#x25; &#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33; &#x36;&#x25;&#x33;&#x31;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30; &#x25;&#x33;&#x30;&#x25;&#x33;&#x36;&#x25;&#x36;&#x33;&#x25;&#x35;&#x63;&#x25; &#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33;&#x36;&#x25;&#x33; &#x35;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25;&#x33;&#x30;&#x25;&#x33;&#x30; &#x25;&#x33;&#x37;&#x25;&#x33;&#x32;&#x25;&#x35;&#x63;&#x25;&#x37;&#x35;&#x25; &#x33;&#x30;&#x25;&#x33;&#x30;&#x25;&#x33;&#x37;&#x25;&#x33;&#x34;&#x28;&#x31; &#x35;&#x29;"></a> ????
  • 12. HTML Parsing Basics • HTML parser works as a state machine • Recognize valid tags as tokens • “<“ make it go into Tag Open State • We don’t want arbitrary user data be treated as a token • Character entity encoding is here to help – ‘<‘ à ‘&lt;’ – ‘>’ à ‘&gt;’ – etc.
  • 13. HTML Parsing States • Only three parsing states can contain character entities – Data state • <div>&lt;img src=x onerror=alert(123)&gt;</div> – Attribute value state • <div id=“&lt;img src=x onerror=alert(123)&gt;”></div> – RCDATA state • <title>&lt;img src=x onerror=alert(123)&gt;</title> • Any ‘<‘ decoded from ‘&lt;’ in these states will NOT be treated as token
  • 14. HTML Parsing HTML Elements • Void elements – <area>, <base>, <br>, <img>, <input>, <keygen>, <link>, … – Cannot have any contents • Raw text elements – <script>, <style> – Text only • RCDATA elements – <textarea>, <title> – Text and character references • Foreign elements • Normal elements
  • 15. HTML Parsing RCDATA state • When the parser is in <textarea> or <title> • Character entities will be decoded – <textarea>&lt;img src=x onerror=alert(123)&gt;</textarea> • Even open tags will NOT be trigger the “Open Tag State” – <textarea><img src=x onerror=alert(123)></textarea>
  • 17. URL Parsing Basics • URL parser works as a state machine • Decoding using UTF-8 • URL scheme has to be in ASCII characters – U+0041-U+005A – U+0061-U+007A
  • 18. URL Parsing Would it execute? <a href="%6a%61%76%61%73%63%72%69%70%74:alert(1)"></a> URL encoded “javascript” <a href=“javascript:alert(1)”></a>
  • 19. URL Parsing Would it execute? NO <a href="%6a%61%76%61%73%63%72%69%70%74:alert(1)"></a> URL encoded “javascript” <a href=“javascript:alert(1)”></a> The scheme must not be encoded
  • 21. JavaScript Parsing Basics • Context free language – Context free grammar for parsing • Error Intolerant • Located in <script> tags or inline – <script> is a RAW element thus not having HTML decoding
  • 22. JavaScript Parsing Would it execute? <script>&#97;&#108;&#101;&#114;&#116&#40;&#57;&#41;&#59</script> Character entity encoded alert(9); <script>alert(9);</script>
  • 23. JavaScript Parsing Would it execute? <script>&#97;&#108;&#101;&#114;&#116&#40;&#57;&#41;&#59</script> Character entity encoded alert(9); <script>alert(9);</script> NO
  • 24. JavaScript Parsing Would it execute? <a href=“&#x6a;avascript:alert(9)”></a> Character encoded ‘j’ <a href=“javascript:alert(9)”></a>
  • 25. JavaScript Parsing Would it execute? <a href=“&#x6a;avascript:alert(9)”></a> Character encoded ‘j’ <a href=“javascript:alert(9)”></a> YES
  • 26. JavaScript Parsing Unicode Escape Sequence • uXXXX • If JavaScript is encoded using uXXXX, would it execute? – It depends on where the encoded content is located • In strings • In identifier names • In control characters
  • 27. JavaScript Parsing Strings • alert(‘my string’); • String literals are surrounded by single or double quotes • Unicode escape sequence will not break out of the string context – alert(‘my stringu0027’); (u0027 is single quote) • ECMA-262 edition5.1 Rev 6, Clause 6 – “a Unicode escape sequence occurring within a string literal in an ECMAScript program always contributes a Unicode character to the literal and is never interpreted as a line terminator or as a quote mark that might terminate the string literal.”
  • 28. JavaScript Parsing Identifier names • alert(‘my string’); • Unicode escape sequence will be decoded in identifier names – u0061lert(‘my string’); (u0061 is ‘a’) • ECMA-262 edition5.1 Rev 6, Clause 6 – "Unicode escape sequences are also permitted in an IdentifierName, where they contribute a single character to the IdentifierName, as computed by the CV of the UnicodeEscapeSequence (see 7.8.4). The preceding the UnicodeEscapeSequence does not contribute a character to the IdentifierName. A UnicodeEscapeSequence cannot be used to put a character into an IdentifierName that would otherwise be illegal."
  • 29. JavaScript Parsing Control characters • alert(‘my string’); • Unicode escape sequence will not be decoded as control characters – alertu0028‘my string’); (u0028 is ‘(’)
  • 30. JavaScript Parsing Would it execute? <script>u0061u006cu0065u0072u0074(u0031u0032)</script> Unicode escape sequence encoded ‘alert(12)’ <script>alert(12)</script>
  • 31. JavaScript Parsing Would it execute? NO <script>u0061u006cu0065u0072u0074(u0031u0032)</script> Unicode escape sequence encoded ‘alert(12)’ <script>alert(12)</script> u0031u0032 is not part of an identifier name or in a string literal
  • 33. Parsing Order Basics • All the parsers work together in an order • The order depends on the location of the content to parse • Each round of parsing will decode the content once • The content needs to be encoded in the reverse order
  • 34. Parsing Order Example: Two rounds of encoding • <a href=”/foo?name=UserInput"></a> – HTML parser first decode the whole document (UserInput is HTML entity decoded) – HTML parser sees the href attributes – HTML parser ask URL parser to decode the URL – URL parser decode the href (UserInput is URL decoded) • In order to make the UserInput safe from XSS – URL encode the UserInput first – Then HTML entity encode the UserInput – <a href=“/foo?name=HTMLEncode(URLEncode(UserInput))”></a>
  • 35. Parsing Order Example: Three rounds of encoding • <a href=# onclick=”window.open(‘/foo?name=UserInput’)"></a> – HTML parser first decode the whole document (UserInput is HTML entity decoded) – HTML parser sees the onclick attributes – HTML parser asks the JavaScript parser to handle the JavaScript – JavaScript parser decode the string in onclick (UserInput is JavaScript decoded) – JavaScript parser sees the window.open function, expecting a URL in the string – JavaScript parser ask URL parser to decode the URL – URL parser decode the string (UserInput is URL decoded) • In order to make the UserInput safe from XSS – <a href=# onclick=“window.open(‘/foo? name=HTMLEncode(JSEncode(URLEncode(UserInput)))’)”></a>
  • 36. Parsing Order Example: more rounds of encoding • <a href="javascript:window.open('/foo?name=UserInput')"> • Advice: Don’t do this… because you have to encode it four times – <a href=“javascript:window.open(‘HTMLEncode(URLEncode(JSEncode(URLEncode(UserInput))))’)”> </a>
  • 38. Salesforce Protections Visualforce • All {!MergeFields} are html encoded automatically • Encoding functions available for complex contexts – HTMLENCODE – JSENCODE – URLENCODE – JSINHTMLENCODE • Use them in the correct order to properly escape your user input
  • 39. Salesforce Protections Visualforce – Encoding Functions • HTMLENCODE – Encode characters in HTML context – <apex:outputText value=“{!HTMLENCODE(userInput)}” escape=“false”/> – This is anti-pattern, use escape automatically – <apex:outputText value=“{!userInput}” />
  • 40. Salesforce Protections Visualforce – Encoding Functions • JSENCODE – Encode characters in JavaScript string literal context – <script>var string = “{!JSENCODE(userInput)}”;</script>
  • 41. Salesforce Protections Visualforce – Encoding Functions • URLENCODE – Encode characters in URL context – <a href=“/foo?name={!URLENCODE(userInput)}”></a> – Developers need to make sure userInput has a expected scheme • userInput.startsWith(‘https’) • Make sure it is not a javascript: scheme
  • 42. Salesforce Protections Visualforce – Encoding Functions • JSINHTMLENCODE – Encode characters in HTML tags in JavaScript – node.innerHTML = “<div id=‘” + {!JSINHTMLENCODE(userInput)} + “’>My Div</div>”;
  • 43. Salesforce Protections Visualforce – Encoding Example – <a href=# onclick=”window.open(‘/foo?name={!userInput}’)"></a> – UNSAFE • <a href=# onclick=“window.open(‘/foo?name={! (JSENCODE(URLENCODE(userInput))}’)”></a> – SAFE
  • 44. Other Salesforce security controls • Data protections – CRUD – FLS – Sharing – Encrypted custom fields – Etc. • Operation protections – Login IP Range – Login Hours – Two Factor Authentications – Audit Trails – Etc.
  • 46. Secure Development Sessions Secure Coding: Field-level Security, CRUD, and Sharing Monday, October 13 @ 11:00 a.m. - 11:40 a.m. Secure Coding: Storing Secrets in Your Salesforce Instance Monday, October 13 @ 2:00 p.m. - 2:40 p.m. Building Secure Mobile Apps Monday, October 13 @ 5:00 p.m. - 5:40 p.m. Protect Your Data Against Malicious Scripts Tuesday, October 14 @ 11:00 a.m. - 11:40 a.m. Secure Coding: External App Integration Wednesday, October 15 @ 9:00 a.m. - 9:40 a.m. Secure Coding: SSL, SOAP, and REST Thursday, October 16 @ 10:30 a.m. - 11:10 a.m. Announcements: Force.com Code Scanner now supports Salesforce1 and JavaScript! Try it here: http://bit.ly/SF1Scanner Chimera Web App Scanner alpha nominations are open. Partners apply at: http://bit.ly/SFChimera Live security office hours are available in the partner zone.