33
Dr. Mustafa Cem Kasapbaşı Security in ASP.NET

Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Embed Size (px)

Citation preview

Page 1: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Dr. Mustafa Cem Kasapbaşı

Security in ASP.NET

Page 2: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Determining Security RequirementsRestricted File Types

Page 3: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Security ConceptsAuthentication: determining a user’s identity and

forcing users to prove Authorization: has sufficient permissions to perform a

given actionImpersonation: all code runs under a fixed account

defined in the machine.config file. Impersonation allows a portion of your code to run under a different identity, with a different set of Windows permissions.

Page 4: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

The ASP.NET Security Model

Page 5: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Not in Asp.net worldIIS attempts to authenticate the user. Generally, IIS

allows requests from all anonymous users and automatically logs them in under the IUSR_[ServerName] account. IIS security settings are configured on a per-directory basis.

If IIS authenticates the user successfully, it attempts to send the user the appropriate HTML file. The operating system performs its own security checks to verify that the authenticated user (typically IUSR_[ServerName]) is allowed access to the specified file and directory.

Page 6: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

İn ASP.NET IIS attempts to authenticate the user. Generally, IIS allows

requests from all anonymous users and automatically logs them in under the IUSR_[ServerName] account.

If IIS authenticates the user successfully, it passes the request to ASP.NET with additional information about the authenticated user. ASP.NET can then use its own security services, depending on the settings in the web.config file and the page that was requested.

If ASP.NET authenticates the user, it allows requests to the .aspx page or .asmx web service. Your code can perform additional custom security checks (for example, manually asking for another password before allowing a specific operation).

When the ASP.NET code requests resources (for example, tries to open a file or connect to a database), the operating system performs its own security checks. All ASP.NET code runs under a fixed account that’s defined in the machine.config fileHowever, if you enable impersonation, these system operations will be performed under the account of the authenticated user (or a different account you specify).

Page 7: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types
Page 8: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types
Page 9: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Security StrategiesAllow anonymous users but use ASP.NET’s forms

authentication model to secure parts of your site. Forbid anonymous users, and use IIS authentication to

force every user to log in using Basic, Digest, or Integrated Windows authentication. This system requires all users have Windows user accounts on the server (although users could share accounts).

Page 10: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Certificatescertificates and SSL (Secure Sockets Layer)

Page 11: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Forms AuthenticationA common approach was to insert a little snippet of

code at the beginning of every secure page. This code would check for the existence of a custom cookie.

ASP.NET uses the same approach in its forms authentication model

Page 12: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types
Page 13: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

The three steps:Set the authentication mode in the web.config file (or

use the WAT).Restrict anonymous users from a specific page or

directory in your application.Create the login page.

Page 14: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Web.config Settings

Page 15: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Authorization Rules

Page 16: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

?????????????

Page 17: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Controlling Access to Specific Directories

İn the <configuration>

Page 18: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Controlling Access for Specific Users

Page 19: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

The WAT website administration toolselect Website ASP.NET Configuration from the ➤

menu.

Page 20: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

The Login PageASP.NET provides a special FormsAuthentication

class in the System.Web.Security namespace, which provides static methods that help manage the process

Page 21: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types
Page 22: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types
Page 23: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

The secret

The first sets the name of the user

Page 24: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

the second is a Boolean variable that creates a persistent forms authentication cookie when set to true or an ordinary forms authentication cookie when set to false. A persistent cookie will be stored on the user’s hard drive with an expiration date set to 50 years in the future.

Page 25: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Windows AuthenticationIf your virtual directory uses the default settings, users will

be authenticated under the anonymous IUSER_[ServerName] account.

To implement Windows-based security with known users, you need to follow three steps:Set the authentication mode in the web.config file (or use the

WAT).Disable anonymous access for a directory by using an

authorization rule (or by disabling access in IIS Manager). You can also choose the protocol that will be used to transmit the user name and password information with IIS Manager.

3. Configure the Windows user accounts on your web server (if they aren’t already present)

Page 26: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

IIS Settingsdisable anonymous access

Then right-click a virtual directory or a subdirectory inside a virtual directory, and choose Properties. Select the Directory Security tab

Page 27: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Web config setting

Page 28: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Programmatical role controlSystem.Security.Principal.WindowsBuiltInRole

Page 29: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

A Windows Authentication Test

Page 30: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Impersination

Page 31: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Programmatic Impersonation To use programmatic impersonation, you need to use Windows

authentication by disabling anonymous access for the virtual directory. You also need to make sure impersonation is disabled for your web application.

Page 32: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

MembershipUser record managementSecurity controls:Role-based security:

The Membership Data Store

Page 33: Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types

Membership with SQL Server 2005 Express