DEV340.NET Framework Security Best Practices Sebastian Lange Program Manager Common Language Runtime Microsoft Corporation.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation.
WEB401 Security Practices for Web Services (Part 2) Keith Ballinger Program Manager XML Messaging Microsoft Corporation.
DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
Introduction to Evidence-based security in.NET Framework Brad Merrill Program Manager.NET Frameworks Integration.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Security and the.NET Framework. Code Access Security Enforces security policy on code  Regardless of user running the code  Regardless of whether the.
Understanding Active Directory
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
1 Developing Rules Driven Workflows in Windows Workflow Foundation Jurgen Willis COM318 Program Manager Microsoft Corporation.
OFC302 Building Smart Document Solutions in Word & Excel Martin Sawicki Lead Program Manager.
S ECURITY T OOLS F OR S OFTWARE D EVELOPMENT F X C OP 10.0 David Angulo Rubio.
OFC 322 Building Office Research Web Services: Exposing Corporate Data Through Office Brian Jones Program Manager Authoring Services Martin Sawicki Lead.
DEV334 Creating Application Starting Points & Sharing Best Practices with Enterprise Templates Marc Gusmano Director of Emerging Technologies The Information.
Introduction to .Net Framework
DEV302 - Visual Studio Team System Building Robust and Reliable Software Eric Lee Program Manager Microsoft Corporation.
Module 1: Introduction to C# Module 2: Variables and Data Types
DEV343.NET Application and Library Versioning Juval Löwy
OFC304 Excel 2003 Overview: XML Support Joseph Chirilov Program Manager.
DEV290 Building Office Solutions with Visual Studio Eric Carter Lead Developer Developer Platform & Evangelism Microsoft Corporation.
SEC303 Assessing and Managing Privacy in the Enterprise JC Cannon Privacy Strategist.
Java Security Pingping Ma Nov 2 nd, Overview Platform Security Cryptography Authentication and Access Control Public Key Infrastructure (PKI)
OFC 303 Advanced Word XML: Customer-Defined Schemas Brian Jones Program Manager Authoring Services.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
OFC290 Information Rights Management in Microsoft Office 2003 Lauren Antonoff Group Program Manager.
DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design
DEP350 Windows ® Rights Management (Part 1): Introduction, Concepts, And Technology Marco DeMello Group Program Manager Windows Trusted Platforms & Infrastructure.
OFC 307 Office 2003 Solution Case Studies Ray Stephenson Smart Client Technical Evangelist
.Net Security and performance
Web 310 XML Schema : What You Need to Know and Why Yasser Shohoud Program Manager XML Messaging Microsoft Corporation.
Introduction to Exception Handling and Defensive Programming.
DEV337 Modeling Distributed Enterprise Applications Using UML in Visual Studio.NET David Keogh Program Manager Visual Studio Enterprise Tools.
SECURITY ISSUES. Introduction The.NET Framework includes a comprehensive set of security tools –Low-level classes and an overall framework –Managing code.
DEV333 Instrumenting Applications for Manageability with the Enterprise Instrumentation Framework David Keogh Program Manager Visual Studio Enterprise.
Presented By: Ahmed ALSUM PhD Student CS 895:.Net Security Old Dominion University College of Science Department of Computer Science.
Windows Role-Based Access Control Longhorn Update
Programming in Java CSCI-2220 Object Oriented Programming.
.NET Security and MSIL Tom Roeder CS fa. MSIL Common intermediate language really CIL in ECMA standard MSIL is common name Very close to C# (and.
DEV303 ASP.NET: Leveraging Visual Studio.NET For Web Projects Tony Goodhew Product Manager Microsoft Corp.
System.Security.Permissions namespace By Venkata Krishna Date: Instructor 06/19/2007 Dr. Ravi Mukkamala.
DEV240 Fundamentals of Code Access Security Sebastian Lange Program Manager Common Language Runtime Microsoft Corporation.
DEV391 Security and Deployment of Office Solutions Built with Visual Studio.NET Eric Carter Lead Developer Visual Studio Microsoft Corporation.
DEV396 Windows Forms: No Touch Deployment Tips and Tricks Jamie Cool Program Manager.NET Client Microsoft Corporation.
DEV395 No Touch Deployment for Windows Forms Jamie Cool Program Manager.NET Client Microsoft Corporation.
DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation
DEV332 Programming for the Middle Tier in Visual Basic.NET Billy Hollis Author / Consultant.
DEV394.NET Framework: Migrating To Managed Code Adam Nathan QA Lead Richard Lander Program Manager Microsoft Corporation.
DEVC02.NET Framework Security Best Practices Sebastian Lange Program Manager Common Language Runtime Microsoft Corporation.
Understanding.NET Framework Security David LeBlanc Microsoft Office.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
DEV221 Windows Forms in Visual Studio 2005: An Overview Saurabh Pant Program Manager Microsoft Corporation.
Chapter 7. Permissions Programming.Net Security, O’Reilly Publishers.
MPUG Global December 2 nd 2004 Portland, Oregon Brian Smith, Microsoft Corporation.
SQL Server 2005:.NET Framework Programming in the Database Tim Sneath Architectural Engineer, Microsoft
Windows Vista Configuration MCTS : Internet Explorer 7.0.
ClickOnce Deployment (One-click Deployment)
.NET Security and MSIL Tom Roeder CS fa.
Building Secure Client Applications In Windows "Longhorn"
Visual Studio Tools for Office 2005
C# and the .NET Framework
Security mechanisms and vulnerabilities in .NET
Security in Windows Store apps
Security & .NET 12/1/2018.
1/14/ :03 PM Session Code: arc340
TechEd /22/2019 9:22 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /27/ :51 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
ClickOnce Deployment (One-click Deployment)
IS 135 Business Programming
Presentation transcript:

DEV340.NET Framework Security Best Practices Sebastian Lange Program Manager Common Language Runtime Microsoft Corporation

Agenda Quick Code Access Security (CAS) Review Building a Secure Shared Library Using Verifiable Code Allowing Partially-trusted Callers Proper use of Assert() Protecting Exposed Resources Sealing Access to Methods Common security programming mistakes

CAS Review A New Paradigm Goal: Enable “Partial Trust” Primary Security Identity: Code (Assembly) Authentication: Information collected about code (Evidence) Authorization: Code identity based policy system grants rights to access resources Enforcement: Verification, Validation, Stackwalks

CAS Review Infrastructure Validation Ensures correctness of file format Verification Ensures Type Safety Policy System Set of admin-defined rules that assign trust to assemblies Input: Evidence Output: Granted Permissions Enforcement Developers protect access to resources with Permissions CLR enforces protection through stack walks

Creating Secure Libraries Categorize your Library Decide on your general approach up front Unsafe: Cannot be called in semi-trusted scenarios Security Neutral: Does not need any special permissions to run Uses Native Resources: Uses COM interop or PInvoke internally Exposes Security Relevant Resources Be aware of “Secure Coding Guidelines” Link provided on “Resources” slide

Creating Secure Libraries Exposing Security Relevant Resources Exposes a Resource an Admin may want to control Examples: File system, speakers, screen, network Most common library type Follow Secure Coding Guidelines #1: Use Permissions to protect access to your resources!

Creating Secure Libraries Write Verifiable Code Helps to ensure that CLR can enforce security Helps reduce buffer overruns Verifiability depends on the language compiler and features used Visual Basic®.NET verifiable C# verifiable Except “unsafe” keyword C++ is generally not verifiable Addressed in future release

The NoiseMaker Library demo demo Scenario: Secure library that exposes Sound API’s Intranet Apps can play Sounds Internet Apps cannot

Creating Secure Libraries Allowing Partially-trusted Callers Default: Code that calls your library must have Full Trust Limits use scenarios today, even more in the future AllowPartiallyTrustedCallersAttribute Provides an opt-in mechanism for allowing potentially dangerous code to call library Specified per-assembly Do Security Reviews per Secure Coding Guidelines

Allowing Partially Trusted Callers demo demo

Creating Secure Libraries Using Assert() Asserts() put the burden on you! Demands() put the burden on the system Pairing Asserts() with Demands() reduces your burden Common pattern Note: Demand first, then Assert Demand a more constrained permission Assert what’s needed to access the resource

Using Assert() demo demo

Creating Secure Libraries Protecting Access to Resources Resources Protected with “Demand” for a Permission Consideration: Use existing permission or write a new one? Leverage existing permission when appropriate Feature aligns with philosophy of existing permission Don’t overload their use Define a new permission class if needed New Permissions should be sealed

Creating Secure Libraries Protecting Access to Resources Consider the Admin Model: What must an Admin control? Ex: File access to c:\*, speaker access, etc. Always allow permission to be turned off completely What should be in Default Policy? Picture the most conservative Admin

Creating Secure Libraries Protecting Access to Resources Prefer full Demands, not Link Demands All callers checked every call Demand only what is required May be stated either “Declaratively” or “Imperatively”

Creating Secure Libraries Declarative Demands Specified using Custom Attributes Stored in the assembly’s metadata Permission State must be known at compile time Can be viewed with PermView SDK Tool [FileIOPermission(SecurityAction.Demand, Write = "c:\\temp")] public void foo() { // class does something with c:\temp }

Creating Secure Libraries Imperative Demands Allows Security Checks to Vary by Control Flow or Method State Initiated with call to Demand() public File(String fileName) { //Fully qualify the path for the security check String fullPath = Directory.GetFullPathInternal(fileName); new FileIOPermission(FileIOPermissionAccess.Read, fullPath).Demand(); //The above call will either pass or throw a //SecurityException //[…rest of function…] }

Protecting Resources demo demo

Creating Secure Libraries Sealing Access to Members Use Link Time Demands For cryptographically strong identity Checks only immediate caller Checks only the first call Occurs when method is JIT’ed Specified using Custom Attributes Performs better than a full Demand

Creating Secure Libraries Sealing Access to Members Link time demands are great because: Seals off access to areas of your library Reduces your security exposure No stack walk = smaller perf impact Link time demands are bad because: Vulnerable to luring attacks JIT uses the static type of the caller, not the runtime type Watch out for overrides!

Creating Secure Libraries Sealing Access to Members For public sealed classes: For public classes, abstract classes and interfaces: [StrongNameIdentity(SecurityAction.LinkDemand, Name=“A1”, PublicKey=“0x…………”)] public sealed class Foo {} [StrongNameIdentity(SecurityAction.InheritanceDemand, Name=“A1”, PublicKey=“0x…………”)] [StrongNameIdentity(SecurityAction.LinkDemand, Name=“A1”, PublicKey=“0x………”)] public class Foo {} [StrongNameIdentity(SecurityAction.InheritanceDemand, Name=“A1”, PublicKey=“0x…………”)] [StrongNameIdentity(SecurityAction.LinkDemand, Name=“A1”, PublicKey=“0x………”)] public class Foo {}

Security Programming Gotcha’s Check your arguments Code generation bugs Think about race conditions Watch out for readonly Pass Evidence when dynamically generating code

Argument Checking Ex: Malicious WSDL that uses special characters to insert extra method calls base.ConfigureProxy(this.GetType(), " Handler=Default"); SomeClass.SomeMethod("Some Params here"); base.ConfigureProxy(this.GetType(), " Handler=Default"); SomeClass.SomeMethod("Some Params here"); < soap:address location= ' Handler=Default"); SomeClass.SomeMethod(" Some Params here'/> < soap:address location= ' Handler=Default"); SomeClass.SomeMethod(" Some Params here'/>

Race Conditions public unsafe int ReadByte() { if (!_isOpen) __Error.StreamIsClosed(); if (_position >= _length) return -1; return _mem[_position++]; } public unsafe int ReadByte() { if (!_isOpen) __Error.StreamIsClosed(); if (_position >= _length) return -1; return _mem[_position++]; } Thread1 Thread2 Thread1

Race Conditions Solution public unsafe int ReadByte() { if (!_isOpen) __Error.StreamIsClosed(); int pos = _position; if (pos >= _length) return -1; _position = pos + 1; return _mem[pos]; } public unsafe int ReadByte() { if (!_isOpen) __Error.StreamIsClosed(); int pos = _position; if (pos >= _length) return -1; _position = pos + 1; return _mem[pos]; }

When readonly isn’t read only The readonly keyword applies to locations, not instances Can be changed using: Prints: “BooBar” Never use readonly instances of mutable types public static readonly StringBuilder Value = new StringBuilder ("Boo"); MyClass.Value.Append("Bar"); Console.WriteLine(MyClass.Value);

Dynamic Code Generation Without care, dynamically generated code gets the permissions of YOUR library Carefully scrutinize all usages of: AppDomain.DefineDynamicAssembly Assembly.Load(Byte[], …) Always use the overloads that allow you to pass Evidence Pass the minimum Evidence possible

Key Takeaways CAS is based on code identity Augments Windows Security Model Partial trust scenarios will continue to get more prevalent Always use Permissions to protect your resources Remember the Admin when designing new permissions Be familiar with: Secure Coding Guidelines Common Security Programming Mistakes

Additional Resources “Secure Coding Guidelines” recode/bestpractices/default.aspx?pull=/libra ry/en-us/dnnetsec/html/seccodeguide.asp “.NET Framework Security”, Addison- Wesley MSDN Security Site DEV240 “Fundamentals of Code Access Security”

Community Resources MS Community Sites List of newsgroups microsoft.public.dotnet.general microsoft.public.dotnet.framework microsoft.public.dotnet.clr microsoft.public.dotnet.security ListServs ADVANCED-DOTNET DOTNET-CLR DOTNET-ROTOR Attend a free chat or webcast Locate a local user groups Community sites

Community Resources Most Valuable Professional (MVP) Newsgroups Converse online with Microsoft Newsgroups, including Worldwide User Groups Meet and learn with your peers

evaluations evaluations

© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.