Version 2 (modified by smagi, 11 years ago) |
---|
Clavis: Security, Type-safe URLs for ASP.NET
Clavis is a simple class library for use with ASP.NET. It provides primitives for secure parameter passing between pages, with compiler-verified taint-checking for any insecure parameters. For an overview of the rationale or the operational details behind Clavis, see the Clavis blog posts.
You need only understand a few concepts to use Clavis:
- IContinuation for specifying page parameter types
- Unsafe<T> for specifying unsafe/insecure page parameters
- Continuation.ToUrl? overloads for generating URLs from continuations + arguments
- Continuation.TryParseX for parsing page parameters
Typed Page Parameters
A typed page parameter list is specified via an IContinuation<...> declaration, like so:
public class SomePage : System.Web.Page, IContinuation<int, string> { ... }
This declares a page that accepts a protected Int32 as the first argument, and a protected string as the second argument. By default, all types specified in an IContinuation<...> declaration will be protected, which means they cannot be changed by clients. If you wish to declare that a certain page parameter is unprotected, then you need only wrap it with Unsafe<T>. For instance, suppose the integer argument from the above example should be unprotected:
public class SomePage : System.Web.Page, IContinuation<Unsafe<int>, string> { ... }
Any type can appear as an argument to IContinuation<...>, not just primitive values. In fact, it's good practice in Clavis not to use primitive types since parameter names are generated from the class name by default:
public class SomePage : System.Web.Page, IContinuation<Unsafe<Project>, Customer> { ... }
Clavis can also handle lists of values by specifying IEnumerable<T> as a parameter type:
public class SomePage : System.Web.Page, IContinuation<IEnumerable<Project>, Customer> { ... }
IEnumerable<T> and Unsafe<T> can also be nested, so you can have an unsafe list of objects as a parameter:
public class SomePage : System.Web.Page, IContinuation<Unsafe<IEnumerable<Project>>, Customer> { ... }