From 29d40192ed3dc0085b5e513ec071c81e03e95d3b Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 23 Mar 2006 13:25:09 +0000 Subject: Reorganized quickstart tutorial. --- .../quickstart/protected/pages/Advanced/Auth.page | 92 ++++++++++++++++++++++ .../protected/pages/Advanced/Security.page | 79 +++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 demos/quickstart/protected/pages/Advanced/Auth.page create mode 100644 demos/quickstart/protected/pages/Advanced/Security.page (limited to 'demos/quickstart/protected/pages/Advanced') diff --git a/demos/quickstart/protected/pages/Advanced/Auth.page b/demos/quickstart/protected/pages/Advanced/Auth.page new file mode 100644 index 00000000..ec876f54 --- /dev/null +++ b/demos/quickstart/protected/pages/Advanced/Auth.page @@ -0,0 +1,92 @@ + + +

Authentication and Authorization

+

+Authentication is a process of verifying whether someone is who he claims he is. It usually involves a username and a password, but may include any other methods of demonstrating identity, such as a smart card, fingerprints, etc. +

+

+Authorization is finding out if the person, once identified, is permitted to manipulate specific resources. This is usually determined by finding out if that person is of a particular role that has access to the resources. +

+ +

How PRADO Auth Framework Works

+

+PRADO provides an extensible authentication/authorization framework. As described in application lifecycles, TApplication reserves several lifecycles for modules responsible for authentication and authorization. PRADO provides the TAuthManager module for such purposes. Developers can plug in their own auth modules easily. TAuthManager is designed to be used together with TUserManager module, which implements a read-only user database. +

+

+When a page request occurs, TAuthManager will try to restore user information from session. If no user information is found, the user is considered as an anonymous or guest user. To facilitate user identity verification, TAuthManager provides two commonly used methods: login() and logout(). A user is logged in (verified) if his username and password entries match a record in the user database managed by TUserManager. A user is logged out if his user information is cleared from session and he needs to re-login if he makes new page requests. +

+

+During Authorization application lifecycle, which occurs after Authentication lifecycle, TAuthManager will verify if the current user has access to the requested page according to a set of authorization rules. The authorization is role-based, i.e., a user has access to a page if 1) the page explicitly states that the user has access; 2) or the user is of a particular role that has access to the page. If the user does not have access to the page, TAuthManager will redirect user browser to the login page which is specified by LoginPage property. +

+ +

Using PRADO Auth Framework

+

+To enable PRADO auth framework, add the TAuthManager module and TUserManager module to application configuration, +

+ +<service id="page" class="TPageService"> + <modules> + <module id="auth" class="System.Security.TAuthManager" + UserManager="users" LoginPage="UserLogin" /> + <module id="users" class="System.Security.TUserManager" + PasswordMode="Clear"> + <user name="demo" password="demo" /> + <user name="admin" password="admin" /> + </module> + </modules> +</service> + +

+In the above, the UserManager property of TAuthManager is set to the users module which is TUserManager. Developers may replace it with a different user management module that is derived from TUserManager. +

+

+Authorization rules for pages are specified in page configurations as follows, +

+ +<authorization> + <allow pages="PageID1,PageID2" + users="User1,User2" + roles="Role1" /> + <deny pages="PageID1,PageID2" + users="?" + verb="post" /> +</authorization> + +

+An authorization rule can be either an allow rule or a deny rule. Each rule consists of four optional properties: +

+ + +

+When a page request is being processed, a list of authorization rules may be available. However, only the first effective rule matching the current user will render the authorization result. +

+ +

+In the above example, anonymous users will be denied from posting to PageID1 and PageID2, while User1 and User2 and all users of role Role1 can access the two pages (in both get and post methods). +

+ +

Using TUserManager

+

+As aforementioned, TUserManager implements a read-only user database. The user information are specified in either application configuration or an external XML file. +

+

+We have seen in the above example that two users are specified in the application configuration. Complete syntax of specifying the user and role information is as follows, +

+ +<user name="demo" password="demo" roles="demo,admin" /> +<role name="admin" users="demo,demo2" /> + +

+where the roles attribute in user element is optional. User roles can be specified in either the user element or in a separate role element. +

+
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Advanced/Security.page b/demos/quickstart/protected/pages/Advanced/Security.page new file mode 100644 index 00000000..b6de7251 --- /dev/null +++ b/demos/quickstart/protected/pages/Advanced/Security.page @@ -0,0 +1,79 @@ + + +

Security

+ +

Viewstate Protection

+

+Viewstate lies at the heart of PRADO. Viewstate represents data that can be used to restore pages to the state that is last seen by end users before making the current request. By default, PRADO uses hidden fields to store viewstate information. +

+

+It is extremely important to ensure that viewstate is not tampered by end users. Without protection, malicious users may inject harmful code into viewstate and unwanted instructions may be performed when page state is being restored on server side. +

+

+To prevent viewstate from being tampered, PRADO enforces viewstate HMAC (Keyed-Hashing for Message Authentication) check before restoring viewstate. Such a check can detect if the viewstate has been tampered or not by end users. Should the viewstate is modified, PRADO will stop restoring the viewstate and return an error message. +

+

+HMAC check requires a private key that should be secret to end users. Developers can either manually specify a key or let PRADO automatically generate a key. Manually specified key is useful when the application runs on a server farm. To do so, configure TSecurityManager in application configuration, +

+ +<modules> + <module id="security" + class="TSecurityManager" + ValidationKey="my private key" /> +</modules> + +

+HMAC check does not prevent end users from reading the viewstate content. An added security measure is to encrypt the viewstate information so that end users cannot decipher it. To enable viewstate encryption, set the EnableStateEncryption of pages to true. This can be done in page configurations or in page code. Note, encrypting viewstate may degrade the application performance. A better strategy is to store viewstate on the server side, rather than the default hidden field. +

+ +

Cross Site Scripting Prevention

+

+Cross site scripting (also known as XSS) occurs when a web application gathers malicious data from a user. Often attackers will inject JavaScript, VBScript, ActiveX, HTML, or Flash into a vulnerable application to fool other application users and gather data from them. For example, a poorly design forum system may display user input in forum posts without any checking. An attacker can then inject a piece of malicious JavaScript code into a post so that when other users read this post, the JavaScript runs unexpectedly on their computers. +

+

+One of the most important measures to prevent XSS attacks is to check user input before displaying them. One can do HTML-encoding with the user input to achieve this goal. However, in some situations, HTML-encoding may not be preferrable because it disables all HTML tags. +

+

+PRADO incorporates the work of SafeHTML and provides developers with a useful component called TSafeHtml. By enclosing content within a TSafeHtml component tag, the enclosed content are ensured to be safe to end users. In addition, the commonly used TTextBox has a SafeText property which contains user input that are ensured to be safe if displayed directly to end users. +

+ +

Cookie Attack Prevention

+

+Protecting cookies from being attacked is of extreme important, as session IDs are commonly stored in cookies. If one gets hold of a session ID, he essentially owns all relevant session information. +

+

+There are several countermeasures to prevent cookies from being attacked. +

+ +

+Prado implements a cookie validation scheme that prevents cookies from being modified. In particular, it does HMAC check for the cookie values if cookie validation is enable. +

+

+Cookie validation is disabled by default. To enable it, configure the THttpRequest module as follows, +

+ + + + + +

+To make use of cookie validation scheme provided by Prado, you also need to retrieve cookies through the Cookies collection of THttpRequest by using the following PHP statements, +

+ +foreach($this->Request->Cookies as $cookie) + // $cookie is of type THttpCookie + +

+To send cookie data encoded with validation information, create new THttpCookie objects and add them to the Cookies collection of THttpResponse, +

+ +$cookie=new THttpCookie($name,$value); +$this->Response->Cookies[]=$cookie; + + +
\ No newline at end of file -- cgit v1.2.3