chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Oct 2012 18:25:33 +0000 (18:25 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Oct 2012 18:25:33 +0000 (18:25 +0000)
cgi-auth-hybrid.pm

index 7da7565fbabb9667f6584be13fc5382f3a2a04e8..f7b48aa1ef4ccbd96ff156a66036202196349221 100644 (file)
@@ -160,6 +160,82 @@ sub _check_core ($) {
            $nmutate = 0;
        }
     }
+
+# pages/param-sets are
+#   n normal non-mutating page
+#   r retrieval of information for JS, non-mutating
+#   m mutating page
+#   u update of information by JS, mutating
+#   i login
+#   o logout
+
+    # Case analysis, cookie mode, app promises re mutate:
+    # cook par meth  form
+    #                      
+    #  y   y   GET   nr       fine, show page or send data
+    #
+    #  y   -   GET   n        cross-site link
+    #                           show data
+    #  y1  y2  GET   n        intra-site link
+    #                           from session no longer known to browser
+    #                           do not revoke y2 as not a POST so not RESTful
+    #                           treat as cross-site link, show data
+    #  y   n   GET   n        intra-site link from stale session,
+    #                           treat as cross-site link, show data
+    #
+    #  y   -   GET    r       bug or attack, fail
+    #  y1  y2  GET    r       intra-site data request
+    #                           from session no longer known to browser
+    #                           do not revoke y2 as not a POST so not RESTful
+    #                           fail
+    #  y   n   GET    r       intra-site data request from stale session
+    #                           fail
+    #
+    #  -   y   GET   n           CLEAR COOKIES TO LOGOUT OPTION
+    #
+    #  -/n any GET   n        cross-site link but user not logged in
+    #                           show login form
+    #
+    #  -/n any GET    r       data request from stale session
+    #                           fail
+    #
+    #  any any GET     muoi   bug or attack, fail
+    #
+    #  y   y   POST  nrmu     mutation is OK, do operation
+    #  y   y   POST      o    logout
+    #  y   y   POST       i   login, redirect to GET of remaining params
+    #
+    #  any -   POST           bug or xsrf attack, fail
+    #
+    #  n/y1 y2 POST  r        intra-site form submission
+    #                           from session no longer known to browser
+    #                           revoke y2
+    #                           show "session interrupted"
+    #  n/y1 y2 POST    m      intra-site js operation
+    #                           from session no longer known to browser
+    #                           revoke y2
+    #                           fail
+    #  y   n   POST  r        intra-site form submission from stale session
+    #                           show "session interrupted"
+    #  y   n   POST    m      intra-site form submission from stale session
+    #                           fail
+    #
+    #  -   y2  GET            intra-site link or data request
+    #                           from session no longer known to browser
+    #                           fail
+
+    #  -   y2        any      req from old session y2, del y2, show login
+    #  y1  y2        any      req from old session y2, del y2, show y1 main
+
+    #  y1 any  GET   non-mut  cross-site link
+    #  y1 any  GET   non-mut  no mutation, show page providing new par
+    #
+    #  A   B         any      page from old session or cross-site request
+    #  any y2 POST  logout    do logout y2
+
+
+    #  any any GET   mutate   bug or attack, forbidden, call die
+
     my $dbh = $r->{Dbh};
     my ($nusername, $nlast) =
        $dbh->selectrow_array("SELECT username, last".
@@ -239,3 +315,58 @@ sub cookiea_cargs ($) {
     return (-name => $r->{S}{cookie_name},
            -value => hidden_val());
 }
+
+__END__
+
+=head1 NAME
+
+CGI::Auth::Hybrid - web authentication optionally using cookies
+
+=head1 SYNOPSYS
+
+ my $verifier = CGI::Auth::Hybrid->new_verifier(setting => value,...);
+ my $authreq = $verifier->new_request($cgi_request_object);
+
+ my $authreq = CGI::Auth::Hybrid->new_request($cgi_request_object,
+                                              setting => value,...);
+
+=head1 USAGE PATTERN FOR SIMPLE APPLICATIONS
+
+ if ( form submission is login request ) {
+     check login details, if wrong print error and quit
+     $authreq->record_login(...username...);
+ }
+ if ( form submission is logout request ) {
+     my $logged_out_user = $authreq->logout();
+     if (!defined $logged_out_user) {
+        print "you are not logged in" error and quit
+     } else {
+        print "goodbye $username you are now logged out" and quit
+     }
+ }
+ if ( !$authreq->check() ) {
+     display login form, quit
+
+
+=head1 USAGE PATTERN FOR FANCY APPLICATIONS
+
+ if ( form submission is login request ) {
+     check login details, if wrong print error and quit
+     $authreq->record_login(...username...);
+ }
+ if ( !$authreq->check() ) {
+     display login form, quit
+ if ( form submission is logout request ) {
+     die unless $authreq->mutate();
+     my $logged_out_user = $authreq->logout();
+     if (!defined $logged_out_user) {
+        print "you are not logged in" error and quit
+     } else {
+        print "goodbye $username you are now logged out" and quit
+     }
+ }
+
+
+advantages of cookie
+ - user can sort of log out by clearing cookies
+ - sophisticated applications can have get-requests