58

Building trustworthy Windows Store apps – from d esign to servicing

  • Upload
    benjy

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

Building trustworthy Windows Store apps – from d esign to servicing. Tiller Beauchamp Senior SDET. Why build trustworthy apps?. Trust and reputation are integral. Your reputation is at the fingertips of the user. Bad reputation may lead to low app acquisition. - PowerPoint PPT Presentation

Citation preview

Page 1: Building trustworthy Windows Store apps – from  d esign to servicing
Page 2: Building trustworthy Windows Store apps – from  d esign to servicing

Building trustworthy Windows Store apps – from design to servicing

Tiller BeauchampSenior SDET

Page 3: Building trustworthy Windows Store apps – from  d esign to servicing

Why build trustworthy apps?• Trust and reputation are integral.• Your reputation is at the fingertips of the user.• Bad reputation may lead to low app

acquisition.

Protect your customers data, privacy, and credentials.

Trust, like reputation, must be built and maintained.

Page 4: Building trustworthy Windows Store apps – from  d esign to servicing

Delivering confidence to customersTrust is part of developing customer confidence.

Three pillars to delivering confidence:Platform• App isolation, capability model, compiler features.

Windows Store• Onboarding, ratings and reviews, telemetry.

App developers• Follow best practices to design, implement, test, and service

apps.

Users can try and buy apps with confidence.

Page 5: Building trustworthy Windows Store apps – from  d esign to servicing

Building trustworthy appsTrustworthy apps are built by following best practices throughout the development lifecycle.

• Design• Implementation• Verification• Servicing

Trustworthiness cannot be obtained with an implementation requirement or a test case.

Page 6: Building trustworthy Windows Store apps – from  d esign to servicing

Key Design Decisions

Page 7: Building trustworthy Windows Store apps – from  d esign to servicing

Many aspects can influence your choice of language.

Language choice also determines the classes of issues you must protect against.

Choosing a languageProblem class C/C++ C# JavaScriptDesign and logic issues Yes Yes YesMemory corruption (buffer overflows)

Yes - -

Malicious script injection - - Yes

Page 8: Building trustworthy Windows Store apps – from  d esign to servicing

Leveraging 3rd party frameworks• Existing frameworks can be leveraged in your

app.• Beware that frameworks may be built with

different security assumptions.• Favor frameworks that advertise compatibility

with Windows Store apps. Ex: JQuery 2.0

Good resources to review before including a framework• Microsoft Interoperability blog.• MSDN Windows Store App samples.• Visual Studio Gallery templates and samples.

Page 9: Building trustworthy Windows Store apps – from  d esign to servicing

Managing user credentialsMany policy choices for managing authentication. Eg.• Session timeout lengths.• Handling login after app suspension and termination.

Windows.Security.Authentication.Web • Broker for Oauth, OpenID

Windows.Security.Credentials.PasswordVault • Provides app-specific secure storage for passwords

and tokens.• Roamed across the users trusted devices.

If you must directly handle user credentials remember to only transmit them over secure channels.

Page 10: Building trustworthy Windows Store apps – from  d esign to servicing

Minimize exploit valueApps with more privileges are more valuable to attackers.

Declare only the capabilities your app needs.• Use file picker instead of declaring library capabilities.• At design time, identify the capabilities that will be

needed. • If capabilities must be added during implementation,

re-evaluate if new threats will be introduced.

Don’t expose WinRT functionality to the web.

The more capabilities you declare, the more valuable your app is to an attacker.

Page 11: Building trustworthy Windows Store apps – from  d esign to servicing

Vulnerability example: exposing WinRT to the webWinJS.xhr({url:”http://contoso.com/fetchcmd”}).done( function fulfilled(result) { var cmd = JSON.parse(result.responseText); eval(cmd.evalMe); }}

Page 12: Building trustworthy Windows Store apps – from  d esign to servicing

Vulnerability example: exposing WinRT to the webWinJS.xhr({url:”http://contoso.com/fetchcmd”}).done( function fulfilled(result) { var cmd = JSON.parse(result.responseText); switch(cmd.apiNum) { case 0: localFolder.createFileAsync(cmd.filename).then(function (f){ windows.Storage.FilIO.writeTextAsync(f,cmd.content); } case 1: …

Page 13: Building trustworthy Windows Store apps – from  d esign to servicing

Analyzing the Design

Page 14: Building trustworthy Windows Store apps – from  d esign to servicing

App attack surface• Attack surface can be understood by the data

flows in and out of the app.

• Windows Store app inputs and outputs are more structured and consistent than classic apps.

• Attack surface of a Windows Store app can be inferred by capability usage, app contracts, and app extensions.

Attack surface is simply the portions of your app that are exposed to abuse or attack.

Page 15: Building trustworthy Windows Store apps – from  d esign to servicing

Plan to mitigate common threats Most security issues in apps arise from:• Assuming input is trusted when it isn’t.• Failing to protect data in flight or in storage.• Turning off built-in protections.

These issues can be easily avoided by evaluating the attack surface of your app and planning mitigations.

A threat is a potential attack against your app.

Page 16: Building trustworthy Windows Store apps – from  d esign to servicing

A simple app hasno attack surface.

Page 17: Building trustworthy Windows Store apps – from  d esign to servicing

Attack surface is introducedwhen a capability or appcontract is added.

Page 18: Building trustworthy Windows Store apps – from  d esign to servicing

Threat modeling process• Enumerate threats that apply to the

attack surface.• Identify existing mitigations to those

threats.• Design mitigations for unaddressed

threats.• Validate mitigations.

Threat taxonomies like S.T.R.I.D.E exist to help organize threat enumeration.

Page 19: Building trustworthy Windows Store apps – from  d esign to servicing

Common attack surface of apps• Opening files – files from documents library

should be considered untrusted.• The web – consuming remote content.• Contracts – share, actions, search• Extensions

Protocol activation – ex: myApp://action/.File activation – ex: somefile.myapp

Page 20: Building trustworthy Windows Store apps – from  d esign to servicing
Page 21: Building trustworthy Windows Store apps – from  d esign to servicing

Local context has much higher privilege than web context.

Local context vs. web contextFeature Local context Web contextWindows Runtime andcapabilities

Yes No

Cross-domain XHR requests Yes No

External script references No YesAutomatic toStaticHTML validation

Yes No

Page 22: Building trustworthy Windows Store apps – from  d esign to servicing

Attack surface, threat, mitigation example

• Attack Surface: App implements custom URI scheme contosoapp://savecontent?URI={foo}.

• Threat: Malicious webpage invokes contosoapp:// URI to cause untrusted content to be saved to the app.

• Mitigation: content is only saved if URI parameter has domain = contoso.com or proseware.com.

Page 23: Building trustworthy Windows Store apps – from  d esign to servicing

Threat modeling is a brainstorming exercise

Consider each element and dataflow on the attack surface.

What could possibly go wrong?• Assume unencrypted traffic can be read/modify by an

attacker.• Assume remote data sources are malicious.

Goal is to ensure that the design is resilient to attack.

Page 24: Building trustworthy Windows Store apps – from  d esign to servicing

Implementing a trustworthy app

Page 25: Building trustworthy Windows Store apps – from  d esign to servicing

Build testable codeFollow a pattern that produces well factored code.• Model view ViewModel (MVVM).• Test driven development.

Visual Studio Test Explorer for unit testing.• Built-in unit test sample projects.• Visual Studio gallery has additional unit test

extensions and frameworks.

Avoid minifying JavaScript code.

Following established patterns can produce code that’s easier to test and debug.

Page 26: Building trustworthy Windows Store apps – from  d esign to servicing

Leverage built-in mitigationsCompile with latest version Visual Studio.• /GS, ASLR, DEP, SeHOP on by default.

Automatic script injection protections in WWAs.• Do not disable this protections with

execUnsafeLocalFunction.

Page 27: Building trustworthy Windows Store apps – from  d esign to servicing

Treat remote data as untrusted• Files in documents library can be malformed.• Brokers pass data directly from other sources.• Data can be tampered with when transferred

unencrypted.

• Improper handling can lead to:Script injection in WWAs.Classic memory corruption flaws in native apps.

When handling data from remote sources, assume that the format might have been tampered with or malformed.

Page 28: Building trustworthy Windows Store apps – from  d esign to servicing

Sources of untrusted data• Files (libraries, file picker, file

activation)• Protocol activation• Sharing sources• Actions sources• Web content• Messages from iframes and webviews

Only trust data packaged with your app.

Page 29: Building trustworthy Windows Store apps – from  d esign to servicing

Handling untrusted data• Leverage platform APIs for handling

files, parsing XML and Json.• Validate or restrict source of data where

possible.• Sanitize or verify format.• Use a convention to indicate untrusted

dataVariable naming or comments

Only trust data packaged with your app.

Page 30: Building trustworthy Windows Store apps – from  d esign to servicing

Validate source of postMessage event// Secure message handler, validates message domain origin window.addEventListener('message', function (e) {

if (e.origin === 'http://data.contoso.com') { div.innerHTML = window.toStaticHTML(e.data);

}}, false);

Page 31: Building trustworthy Windows Store apps – from  d esign to servicing

Sanitizing HTML from share sourceif(shareOperation.data.contains(StandardDataFormats.html)) {

shareOperation.data.getHtmlFormatAsync().then(function (ut_html) { if (ut_html !== null) { var s_htmlFragment = HtmlFormatHelper.getStaticFragment(ut_html); var myDiv = document.getElementById("htmlContent"); myDiv.innerHTML = s_htmlFragment; }});

Page 32: Building trustworthy Windows Store apps – from  d esign to servicing

Navigating to saved HTML content• You can now navigate a WebView directly to

saved content in your AppData directory.

• The domain for saved content is based on the directory.

• Preserve same-origin policy.Save HTML content from different domains to

different directories.

Page 33: Building trustworthy Windows Store apps – from  d esign to servicing

Vulnerability: SOP violation (pseudo code)page1 = xhr(“http://contoso.com/page1.html”); page2 = xhr(“http://adnetwork.net/1-78235-872.html”);Windows.Storage.ApplicationData.current.localFolder.createFolderAsync(“MySaved”);// save page1 and page2 content to files in MySaved folder// navigate to page2.htmlmyWebView.navigate(“ms-appdata:///local/MySaved/page2.html”)// page2 can access contents of page 1.

Page 34: Building trustworthy Windows Store apps – from  d esign to servicing

Using self-signed certs in apps• Create your self signed certificate• Install private key and cert on server• Package your certificate with your app• Declare certificate extension in app manifest

You cert will be installed in a certificate store specific to your app.

Page 35: Building trustworthy Windows Store apps – from  d esign to servicing

Adding custom cert in Visual Studio

Page 36: Building trustworthy Windows Store apps – from  d esign to servicing

Custom certificate in the app manifest<Extensions><Extension Category="windows.certificates"> <Certificates> <Certificate StoreName="Root" Content="myroot.cer" /> <Certificate StoreName="CA" Content="mystandca.cer"/> <TrustFlags ExclusiveTrust="true" /> <SelectionCriteria AutoSelect="true"/> </Certificates> </Extension> </Extensions>

Page 37: Building trustworthy Windows Store apps – from  d esign to servicing

Other TipsEncrypt sensitive data using WinRT API• Windows.Security.Cryptography.DataProtectio

n

Use XDomainRequest instead of XHR when cookies are not needed

See MSDN documentation and links in resources for more details.

Page 38: Building trustworthy Windows Store apps – from  d esign to servicing

Verification

Page 39: Building trustworthy Windows Store apps – from  d esign to servicing

Principles of effective testing• Complete coverage

Coverage of all attack surfaces and functional scenarios

Include testing of mitigations.

• RepeatableAutomate test cases as much as possible.

• Easy to extendAdded app functionality means new tests.

Page 40: Building trustworthy Windows Store apps – from  d esign to servicing

Validate mitigations• Identify mitigations that were planned up

front• Execute on test cases to validate

Ensure that mitigations:• function properly• cannot be bypassed

Page 41: Building trustworthy Windows Store apps – from  d esign to servicing

Validate mitigation exampleContosoapp://savecontent?URI=http://contoso.com/inappcontent/en-us/1234

Implement a test app to invoke the URI scheme.Create list of cases that attempt to bypass the check.

http://evil.com/contoso.com/inappcontent...http://evil.com/&http://contoso.com/inappcontent...evil.com/http://contoso.com/inappcontent……

Mitigation was to validate domain of URI against a white list.

Page 42: Building trustworthy Windows Store apps – from  d esign to servicing

Review attack surfaceAttack surface is wholly defined in appxmanifest.xml

• Capabilities: Network, Libraries and removable storage

• Contracts: File save picker, Search, Share, Actions• Extensions: Autoplay, File activation, Protocol

activation

Review the manifest file and confirm the attack surface matches the initial design.

Planned attack surface may not be the final attack surface.

Page 43: Building trustworthy Windows Store apps – from  d esign to servicing

Put on your adversarial hat.Forget what you know of the design.

Tips:• Use a web proxy to tamper with traffic to your app.• Inspect captured traffic for any sensitive customer

data sent unencrypted.• Can a customer configure insecure settings in your

app?• Use malformed inputs in search and share contracts.

Follow a black box approach and pretend you are the attacker.

Hack your app

Page 44: Building trustworthy Windows Store apps – from  d esign to servicing

Perform code reviewSearch the source code and review usage of dangerous APIs.• eval should never be called on untrusted data• execUnsafeLocalFunction should not wrap DOM

manipulation functions that operate on untrusted data

• scriptNotify/postMessage handlers should not expose WinRT functionality

• SDL Banned API list. Ex: strcpy, memcpy, sprintf, etc.

Review usage of sanitizing functions like toStaticHTML, to ensure their code path cannot be skipped.

Page 45: Building trustworthy Windows Store apps – from  d esign to servicing

Fuzz test native code parsersCustom parsing could be:• Media file formats, video streams• Network protocols

Well isolated parsing code can be fuzzed using API fuzzing approach. File fuzzing is another approach.

Favor API fuzzing approach when possible.

Fuzz testing is an effective approach to finding bugs in native code parsers.

Page 46: Building trustworthy Windows Store apps – from  d esign to servicing

Document resultsDocument what was tested, test cases, and results.

You cannot improve without understanding what you’ve done in the past.

Page 47: Building trustworthy Windows Store apps – from  d esign to servicing

• Run Windows App Certification Kit• Remove private networking capability if you

had added it for local testing.• Strip EXIF data from images (ex: geo

coordinates).• Remove debug code.• Do not ship minified scripts or obfuscated

code.

Checklist before onboarding

Page 48: Building trustworthy Windows Store apps – from  d esign to servicing

Servicing

Page 49: Building trustworthy Windows Store apps – from  d esign to servicing

Many reasons to update your app• Add new features.• Address customer feedback.• Improve reliability and security.• Include updated versions of third-party frameworks.

Updating your app

Page 50: Building trustworthy Windows Store apps – from  d esign to servicing

Windows Store developer dashboard provides telemetry data on JavaScript exceptions, crash rate, and hangs.

Page 51: Building trustworthy Windows Store apps – from  d esign to servicing

Crashes might indicate a security problem

• For native apps, pay attention to crashes due to memory corruption, such as write and read access violations.

• For JavaScript apps, watch out for exceptions regarding dynamic content injection.

• Only the top occurring issues for your app are reported. Fixing these issues causes less common issues to bubble up.

Page 52: Building trustworthy Windows Store apps – from  d esign to servicing

Follow updates for 3rd party frameworks

• Frameworks you package may have their own bug fixes.

• Subscribe to framework announcement lists.

• Plan to update your app with new version of frameworks.

Page 53: Building trustworthy Windows Store apps – from  d esign to servicing

Security response• Coordinate a vulnerability disclosure.• Publish contact for security reports.• Respond in timely matter.• Allocate resources to triage and fix

reported issues.

Page 54: Building trustworthy Windows Store apps – from  d esign to servicing

Security response• Third-party researchers or Microsoft may

become aware of security or privacy issues in your app.

• Microsoft can coordinate communication between you and the finder.

• If you are contacted about a vulnerability in your app that also affects a Microsoft product, please contact [email protected].

Page 55: Building trustworthy Windows Store apps – from  d esign to servicing

ConclusionDesign

Key choices: language, auth, frameworks, exploit value

Analysis: Attack surface, threats, mitigationsImplement

Build testable code, built-in mitigationsHandling untrusted data, other tips.

VerifyTest mitigations, hack your app, code review, fuzz

testService

Leverage telemetry, security response, update frameworks

Page 56: Building trustworthy Windows Store apps – from  d esign to servicing

ResourcesDelivering reliable and trustworthy apps

http://blogs.msdn.com/b/b8/archive/2012/05/17/delivering-reliable-and-trustworthy-metro-style-apps.aspx

Security best practices for building Windows Store apps

http://blogs.msdn.com/b/windowsappdev/archive/2012/12/18/security-best-practices-for-building-windows-store-apps.aspx

Uncover Security Design Flaws Using The STRIDE Approach

http://msdn.microsoft.com/en-us/magazine/cc163519.aspx

Page 57: Building trustworthy Windows Store apps – from  d esign to servicing

Resources (cont.)Features and Restrictions by context (Windows Store apps using JavaScript and HTML)

http://msdn.microsoft.com/en-us/library/windows/apps/hh465373.aspxDeveloping secure apps

http://msdn.microsoft.com/en-us/library/windows/apps/hh849625.aspx

Page 58: Building trustworthy Windows Store apps – from  d esign to servicing

© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.