chiark / gitweb /
Introduce STALE divert kind
[cgi-auth-flexible.git] / caf.pod
1 # -*- fundamental -*-
2
3 =head1 NAME
4
5 CGI::Auth::Flexible - web authentication optionally using cookies
6
7 =head1 SYNOPSYS
8
9  my $verifier = CGI::Auth::Flexible->new_verifier(setting => value,...);
10  my $authreq = $verifier->new_request($cgi);
11
12  # simple applications
13  $authreq->check_ok() or return;
14
15  # sophisticated applications
16  my $divert_kind = $authreq->check_divert();
17  if ($divert_kind) { ... print diversion page and quit ... }
18
19  # while handling the request
20  $user = $authreq->get_username();
21  $authreq->check_mutate();
22
23 =head1 DESCRIPTION
24
25 CGI::Auth::Flexible is a library which you can use to add a
26 forms/cookie-based login facility to a Perl web application.
27
28 CGI::Auth::Flexible doesn't interfere with your application's URL path
29 namespace and just needs a few (configurable) form parameter and
30 cookie name(s) for its own use.  It tries to avoid making assumptions
31 about the implementation structure of your application.
32
33 Because CGI::Auth::Flexible is licenced under the AGPLv3, you will
34 probably need to provide a facility to allow users (even ones not
35 logged in) to download the source code for your web app.  Conveniently
36 by default CGI::Auth::Flexible provides (for pure Perl webapps) a
37 mechanism for users to get the source.
38
39 CGI::Auth::Flexible is designed to try to stop you accidentally
40 granting access by misunderstanding the API.  (Also it, of course,
41 guards against cross-site scripting.)  You do need to make sure to
42 call CGI::Auth::Flexible before answering AJAX requests as well as
43 before generating HTML pages, of course, and to call it in every
44 entrypoint to your system.
45
46 =head2 CHECKLIST
47
48 As a minimum you need to do all of the things on this checklist, where
49 applicable.  The items marked SECURITY are the ones that you might
50 forget: without them your application may appear to work, but will be
51 insecure.
52
53 =over
54
55 =item *
56
57 Call C<new_verifier> (once at application startup)
58
59 =item *
60
61 Call C<new_request> (once per request)
62
63 =item *
64
65 B<SECURITY>: Call C<check_ok> or C<check_divert> on every request, and
66 honour the return value.
67
68 =item *
69
70 If you're using C<check_ok>, implement either the
71 C<username_password_error> or C<login_ok> hook and provide it as
72 a setting to C<new_verifier>.
73
74 =item *
75
76 Provide the setting C<dir> (or provide absolute paths for all the
77 other relevant settings).
78
79 =item *
80
81 Call C<get_username> when you need to know who's logged in.
82
83 =item *
84
85 B<SECURITY>: Call C<check_mutate> or C<mutate_ok>, if you specified
86 C<promise_check_mutate>.
87
88 =item *
89
90 B<SECURITY>: Call C<check_nonpage> for every request which is not a page load
91 (if your application has any of those).
92
93 =item *
94
95 When generating URLs and forms (including AJAX requests), include the
96 hidden form parameter using C<secret_hidden_val> or
97 C<secret_hidden_html> when appropriate (see below).
98
99 =item *
100
101 B<SECURITY>: If you do not override the source provision facility (see
102 L</SOURCE CODE DOWNLOAD>), check that the assumptions it makes aren't
103 going to leak security-critical data.
104
105 =item *
106
107 Set up HTTPS on your webserver, or set the C<encrypted_only> setting
108 to a false value.
109
110 =back
111
112 These points will now be covered in more detail.
113
114 =head2 INITIALISATION
115
116 Your application should, on startup (eg, when it is loaded by
117 mod_perl) do
118 C<< $verifier = CGI::Auth::Flexible->new_verifier(settings...) >>.
119 This call can be expensive and is best amortised.
120
121 The resulting verifier object can be used to process individual
122 requests, in each case with
123 C<< $authreq = CGI::Auth::Flexible->new_request($cgi) >>.
124
125 See L</SETTINGS>.
126
127 =head2 CHECKING AND RESPONSE GENERATION
128
129 If the user is logged in, your application is to handle the request.
130 Otherwise, the user needs to be presented with a login form or error
131 message, as appropriate.  CGI::Auth::Flexible provides two alternative
132 interfaces for this:
133
134 =head3 Simple applications
135
136 The simplest usage is to call C<< $request->check_ok() >> which will
137 check the user's authentication.  If the user is not logged in it will
138 generate a login form (or redirection or other appropriate page) and
139 return false; your application should not then process that request
140 any further.  If the user is logged in it will return true.
141
142 Various hooks are provided to customise the responses generated by
143 C<check_ok>.
144
145 After C<check_ok> returns true you should go ahead and process the
146 request; you can use C<< $request->get_username >> to find out which
147 user the request came from.
148 You may also need to call C<check_mutate> and/or C<check_nonpage>
149 - see below.
150
151 =head3 Sophisticated applications
152
153 If you want to handle the control flow and to generate login forms,
154 redirections, etc., yourself, you can say
155 C<< $divert = $request->check_divert >>.  This returns undef if
156 the user is logged in, or a I<divert spec> if some kind of login
157 page or diversion should be generated.  See L</DIVERT SPEC> below for
158 details of how to deal with the return value.
159
160 =head2 MUTATING OPERATIONS AND EXTERNAL LINKS
161
162 =head3 Mutation-ignorant applications
163
164 By default CGI::Auth::Flexible does not permit external deep links
165 into your site.
166 All GET requests give a "click to continue" page which
167 submits a form which loads your app's main page.  In this
168 configuration all your application's forms and AJAX requests should
169 use C<POST>.
170
171 Such applications are also not able to provide user-specific CSS
172 stylesheets, javascript, favicons, etc.
173
174 This restriction arises from complicated deficiencies
175 in the web's security architecture.
176
177 =head3 Mutation-aware applications
178
179 The alternative is for your application to always make a special check
180 when the incoming request is going to do some kind of action (such as
181 modifying the user's setup, purchasing goods, or whatever) rather than
182 just retrieve and/or display information.  We term such requests
183 "mutating" requests.
184
185 Then non-mutating pages can be linked to from other, untrustworthy,
186 websites.
187
188 To support external links, and C<GET> requests, pass
189 C<< promise_check_mutate => 1 >> in I<settings>, and then call
190 C<< $authreq->check_mutate() >> before taking any actions.  If the
191 incoming request is not suitable then C<< $authreq->check_mutate() >>
192 will call C<die>.
193
194 There have to be no mutating C<GET> requests in your application (but
195 you shouldn't have any of those anyway); if there are, they won't
196 work.  (CGI::Auth::Flexible will spot them and cause them to fail,
197 rather than allow them to be insecure.)
198
199 =head2 GENERATING URLS, FORMS AND AJAX QUERIES
200
201 When you generate a URL, C<POST> form or AJAX request you may need to
202 include a secret hidden form parameter for the benefit of
203 CGI::Auth::Generic.  This form parameter will be checked by
204 C<check_ok>/C<check_divert> and should be ignored by your application.
205
206 By default the hidden parameter is called C<caf__assochash>.
207
208 After calling C<check_ok> or C<check_divert> the value to put in your
209 form can be obtained from C<secret_hidden_val>; C<secret_hidden_html>
210 will generate the whole HTML C<< <input...> >> element.
211
212 =head3 Mutation-ignorant applications
213
214 For mutation-ignorant applications (see above), all forms etc. should
215 include the hidden parameter (and as discussed, they must all use
216 POST rather than GET).
217
218 =head3 Mutation-aware applications
219
220 For mutation-aware applications, whether to include the secret
221 parameter depends on the kind of request.  CGI::Auth::Flexible knows
222 when it is necessary.  You should find out by calling
223 C<need_add_hidden>.
224
225 If it is inconvenient to call C<need_add_hidden> at runtime, you can
226 rely instead on the following promises:  All POST requests (which
227 includes all mutating requests) need the parameter.  The return value
228 of need_add_hidden depends only on the $method and $reqtype
229 parameters, so you can query it once and remember the answer.
230 HTML page load GETs do not need the parameter.  It is better to
231 err on the side of including the parameter.
232
233 If you really must, you can call C<need_add_hidden> "on the bench"
234 during development and bake the answer into your application code
235 structure.  However, if you do that and a new vulnerability was
236 discovered which is fixed by changing the answer, updating
237 CGI::Auth::Flexible wouldn't be sufficient to fix it.
238
239 =head3 Mutation-aware applications - non-page requests
240
241 If your mutation-aware application supports non-page resources (AJAX
242 and JSON requests, stylesheets, favicons, etc.) it must inform
243 CGI::Auth::Flexible when it is handling such a request, by calling
244 C<check_nonpage>.
245
246 Normally C<check_nonpage> will simply return (and you can ignore the
247 return value).  However, if there is an attack (or, perhaps, a bug) it
248 will die, stopping the attack.
249
250 (You do not need to call C<check_nonpage> for POST requests, but it is
251 harmless to do so.)
252
253 =head3 Mutation-aware applications - novel kinds of request
254
255 If you want to support a kind of request perhaps not yet known about
256 by CGI::Auth::Flexible, you can provide information about that new
257 request kind using C<update_get_need_add_hidden>.
258
259 =head2 DATA STORAGE
260
261 CGI::Auth::Flexible needs to store various information in plain files;
262 it does this in the directory specified by the C<dir> parameter.
263
264 =head1 SOURCE CODE DOWNLOAD
265
266 By default, CGI::Auth::Flexible provides a facility for users to
267 download the source code for the running version of your web
268 application.
269
270 This facility makes a number of important assumptions which you need
271 to check.  Note that if the provided facility is not sufficient
272 because your application is more sophisticated than it copes with (or
273 if you disable the builtin facility), you may need to implement a
274 functioning alternative to avoid violating the AGPLv3 licence.
275
276 Here are the most important (default) assumptions:
277
278 =over
279
280 =item *
281
282 Your app's source code is available by looking at @INC, $0 and
283 S<$ENV{'SCRIPT_FILENAME'}> (the B<source items>).  See
284 C<srcdump_listitems>.  Where these point to files or directories under
285 revision control, the source item is the whole containing vcs tree.
286
287 =item *
288
289 Specifically, there are no compiled or autogenerated Perl
290 files, Javascript resources, etc., which are not contained in one of
291 the source item directories.  (Files which came with your operating
292 system install don't need to be shipped as they fall under the system
293 library exception.)
294
295 =item *
296
297 You have not installed any modified versions of system
298 libraries (including system-supplied Perl modules) in C</usr> outside
299 C</usr/local>.  See C<srcdump_system_dir>.
300
301 =item *
302
303 For each source item in a dvcs, the entire dvcs history does
304 not contain anything confidential (or libellous).  Also, all files which
305 contain secrets are in the dvcs's I<.ignore> file.  See
306 C<srcdump_vcsscript_git> et al.
307
308 =item *
309
310 For each source item NOT in a dvcs, there are no confidential
311 files with the world-readable bit set (being in a world-inaccessible
312 directory is not sufficient).  See C<srcdump_excludes>.
313
314 =item *
315
316 You have none of your app's source code in C</etc>.
317
318 =item *
319
320 You don't regard pathnames on your server as secret.
321
322 =item *
323
324 You don't intentionally load Perl code by virtue of C<.>
325 being in C<@INC> by default.  (See C<srcdump_filter_cwd>.)
326
327 =back
328
329 =head1 MAIN FUNCTIONS AND METHODS
330
331 =over
332
333 =item C<< CGI::Auth::Flexible->new_verifier(setting => value, ...) >>
334
335 Initialises an instance and returns a verifier object.
336 The arguments are setting pairs like a hash initialiser.
337 See L</SETTINGS> below.
338
339 =item C<< $verifier->new_request($cgi) >>
340
341 Prepares to process a request.  I<$cgi> should normally
342 be the query object from L<CGI(3perl)>.  Most of the default
343 hook methods assume that it is; however if you replace enough of
344 the hook methods then you can pass any value you like and it
345 will be passed to your hooks.
346
347 The return value is the authentication request object (I<$authreq>)
348 which is used to check the incoming request and will contain
349 information about its credentials.
350
351 =item C<< $authreq->check_divert() >>
352
353 Checks whether the user is logged in.  Returns undef if the user is
354 logged in and we should service the request.  Otherwise returns a
355 divert spec (see L</DIVERT SPEC>) saying what should happen instead.
356
357 This method may die if it doesn't like the request, in which case
358 the request needs to be rejected.
359
360 =item C<< $authreq->check_ok() >>
361
362 Checks whether the user is logged in.  Returns true if the user is
363 logged in and we should service the request.
364
365 Otherwise it handles the request itself, generating any appropriate
366 redirect, login form, or continuation page.  It then returns false and
367 the application should not process the request further.
368
369 =item C<< $verifier->disconnect() >>
370
371 Discards the resources (open files, etc.) in the verifier object.
372
373 =back
374
375 =head1 REQUEST-RELATED FUNCTIONS AND METHODS
376
377 All of these are only valid after C<check_divert> or C<check_ok> has
378 been called.  (In the case of C<check_ok> it won't normally be sensible
379 to call these functions unless C<check_ok> returned true.)
380
381 =over
382
383 =item C<< $authreq->get_divert() >>
384
385 Returns the value previously returned by C<check_divert>.
386
387 =item C<< $authreq->get_username() >>
388
389 Returns the name of the logged-in user.  If the user was not logged
390 in (or their session had timed out, or something), returns undef.
391
392 =item C<< $authreq->check_mutate() >>
393
394 Declares to CGI::Auth::Generic that the request being handled will
395 "mutate".  That is, it will modify some server-side state (eg, adding
396 items to shopping baskets, posting messages to blogs, sending emails,
397 or whatever).
398
399 If you have set the setting C<promise_check_mutate> you must call
400 C<check_mutate> whenever appropriate.  If you haven't then it's
401 irrelevant.  See L<MUTATING OPERATIONS AND EXTERNAL LINKS>.
402
403 C<check_mutate> will either return successfully, indicating that all
404 is well and the request should proceed, or it will die.  If it dies
405 that means that the request was improper, which can only result from a
406 bug or an attack.  So an "internal server error" is a suitable
407 response.
408
409 =item C<< $authreq->check_nonpage($method, $reqtype) >>
410
411 Declares to CGI::Auth::Generic that the request is not a page request,
412 but rather a request of type I<$reqtype>.
413
414 If your application has set the setting C<promise_check_mutate>,
415 whenever it is handling anything except an HTML page loads, it must
416 call this function.  See L</REQUEST TYPES>, and
417 L<GENERATING URLS, FORMS AND AJAX QUERIES>.
418
419 C<check_nonpage> will either return successfully, indicating that all
420 is well and the request should proceed, or it will die, like
421 C<check_mutate>.
422
423 =back
424
425 =head1 RESPONSE-RELATED FUNCTIONS AND METHODS
426
427 =over
428
429 =item C<< $authreq->url_with_query_params($params, [$nonpagetype]) >>
430
431 Convenience function which returns a url for a GET request to this
432 application.
433
434 I<$params> is a hashref specifying the parameters and the PATH_INFO
435 (not including any parameters related to CGI::Auth::Flexible).
436 The keys are the parameter names, and the values are array refs with
437 the parameter value(s) (as strings, as yet unquoted).  (They are array
438 refs because it is possible to pass multiple values for the same
439 parameter in a single request; normally each arrayref would be a
440 singleton.)
441
442 The request path will be the path to the application.  If a parameter
443 with name C<< '' >> is supplied, it is taken as the PATH_INFO - its
444 value will be appended to the application path.  (It should normally
445 start with C<< / >>, and only one value should be supplied.)
446
447 =item C<< something->need_add_hidden($method, $reqtype) >>
448
449 Enquires whether a request of type I<$reqtype> using HTTP method
450 I<$method> needs the hidden form parameter.  See L</REQUEST TYPES>.
451
452 =item C<< something->secret_hidden_val() >>
453
454 Returns the value of the hidden form parameter.  This should be
455 included in all POST requests to your application (and thus be a
456 hidden form parameter in all forms).
457
458 It should also be in some (maybe all) GET requests.  If your
459 application is mutation-ignorant, it should be in all GET requests.
460 If you are mutation-aware, you need to consult C<need_add_hidden>.
461
462 The name of the hidden parameter is the setting C<assoc_param_name>,
463 C<caf_hassochash> by default.  xxx rename param and setting
464
465 =item C<< something->secret_hidden_html() >>
466
467 Returns the HTML for an C<INPUT> element specifying the hidden form
468 parameter.
469
470 =item C<< something->secret_cookie_val() >>
471
472 Returns the value of the secret cookie.  CGI::Auth::Flexible sets this
473 cookie in the forms generated by C<check_ok>.  You may also set it
474 yourself (and indeed you must do so if you use C<check_divert>).
475
476 =item C<< $authreq->_chain_params() >>
477
478 Returns a hash of the "relevant" parameters to this request, in a form
479 suitable for C<url_with_query_params>.  This is all of the query
480 parameters which are not related to CGI::Auth::Flexible.  The
481 PATH_INFO from the request is returned as the parameter C<< '' >>.
482
483 =back
484
485 =head1 OTHER FUNCTIONS AND METHODS
486
487 =over
488
489 =item C<< $verifier_or_authreq->hash($data) >>
490
491 Hashes the supplied data using the hash function specified by the
492 C<hash_algorithm> setting, and converts the result to a string of hex
493 digits.
494
495 =item C<< something->update_get_need_add_hidden($reqtype, $value, [$force]) >>
496
497 Updates CGI::Auth::Generic's knowledge about the various kinds of
498 request, and whether they need the hidden form parameter.  This
499 function applies only to GET requests - POST requests always use the
500 parameter.
501
502 I<$reqtype> is the request type (the value which will be passed to
503 C<check_nonpage> and C<need_add_hidden>.  If you are supporting a new
504 I<$reqtype> you shouuld coordinate with CGI::Auth::Flexible upstream,
505 or other users, to assign a unique request type name.
506
507 This method may be called on an authreq or a verifier, in which case
508 it will affect all authreqs using the same verifier.  Or it may be
509 called on the class as a whole, in which case it will affect the
510 global default list for all verifiers.
511
512 If I<$force> is supplied and true, this will override
513 CGI::Auth::Flexible's existing knowledge.  Otherwise this new setting
514 will be ignored if CGI::Auth::Flexible already knows about the request
515 type.  (When called on a verifier or authreq, it will ignore the
516 update in favour of existing knowledge recorded both globally in the
517 class or due to previous requests on the same verifier.)
518
519 See L</REQUEST TYPES>.
520
521 =item C<< CGI::Auth::Flexible::srcdump_dir_cpio($cgi,$verifier,$dumpdir,$dir,$outfn,$how,$script) >>
522
523 Helper function for implementing the C<srcdump_process_item> hook.
524 Generates a tarball using cpio and includes it in the prepared source
525 code distribution.
526
527 The arguments are mostly the same as for that hook.  C<$dir> is the
528 root directory at which to start the archive.  C<$how> is a short text
529 string which will be mentioned in the log.
530
531 C<$script> is a shell script fragment which must output a
532 nul-separated list of filenames (e.g. the output of C<find -print0>).
533 It is textually surrounded by C<( )> and will be executed with C<set -e>
534 in force.  Its cwd will be C<$dir>.
535
536 =item C<< $verifier_or_authreq->($data) | CGI::Auth::Flexible-> >>
537
538 Hashes the supplied data using the hash function specified by the
539 C<hash_algorithm> setting, and converts the result to a string of hex
540 digits.
541
542 =back
543
544 =head1 REQUEST TYPES
545
546 The C<$reqtype> values understood by C<check_nonpage> are strings.
547 They are:
548
549 =over
550
551 =item C<PAGE>
552
553 A top-level HTML page load.  May contain confidential information for
554 the benefit of the logged-in user.
555
556 =item C<FRAME>
557
558 An HTML frame.  May contain confidential information for
559 the benefit of the logged-in user.
560
561 =item C<IFRAME>
562
563 An HTML iframe.  May contain confidential information for
564 the benefit of the logged-in user.
565
566 =item C<SRCDUMP>
567
568 Source dump request, whether for the licence or actual source code
569 tarball; returned value is not secret.
570
571 =item C<STYLESHEET>
572
573 CSS stylesheet.  B<MUST NOT> contain any confidential data.  If the
574 stylesheet depends on the user, then attackers may be able to
575 determine what stylesheet the user is using.  Hopefully this is not a
576 problem.
577
578 =item C<FAVICON>
579
580 "Favicon" - icon for display in the browser's url bar etc.  We aren't
581 currently aware of a way that attackers can get a copy of this.
582
583 =item C<ROBOTS>
584
585 C<robots.txt>.  Should not contain any confidential data (obviously).
586
587 =item C<IMAGE>
588
589 Inline image, for an C<< <img src=...> >> element.
590
591 Unfortunately it is not possible to sensibly show top-level
592 confidential images (that is, have the user's browser directly visit a
593 url which resolves to an image rather than an HTML page with an inline
594 image).  This is because images need to have a per-session hidden form
595 parameter to avoid cross-site scripting, which breaks bookmarks etc.
596
597 =item C<SCRIPT>
598
599 JavaScript for a C<< <script> >> element.  (Possibly confidential for
600 the user.)
601
602 =item C<AJAX-XML>
603
604 C<< XMLHttpRequest >> returning XML data.  (Possibly
605 confidential for the user.)
606
607 =item C<AJAX-JSON>
608
609 C<< XMLHttpRequest >> returning JSON data.  (Possibly
610 confidential for the user.)
611
612 =item C<AJAX-OTHER>
613
614 C<< XMLHttpRequest >> returning data of some other kind.  (Possibly
615 confidential for the user.)
616
617 =back
618
619 =head1 DIVERT SPEC
620
621 The return value from C<check_divert> indicates how the request should
622 be handled.  It is C<undef> if all is well and the user is logged in.
623
624 Otherwise the return value is a hash ref with the following keys:
625
626 =over
627
628 =item C<Kind>
629
630 Scalar string indicating the kind of diversion required.
631
632 =item C<Message>
633
634 Scalar string for display to the user in relation to the diversion.
635 Has already been translated.  In HTML but normally does not contain
636 any tags.
637
638 =item C<CookieSecret>
639
640 The login cookie which should be set along with whatever response is
641 sent to the client.  The value in the hash is the actual value
642 of the cookie as a string.  C<undef> means no cookie setting header
643 should be sent; C<''> means the cookie should be cleared.
644
645 =item C<Params>
646
647 Provided with diversion kinds which involve
648 generating a redirection or indirection,
649 perhaps via a login form.
650
651 The extra hidden form parameters (and the C<PATH_INFO>) which should
652 be set when the subsequent request bounces back from the client, in
653 the form used by C<url_with_query_params>.
654
655 The contents of this hashref does not include the CAF-specific
656 parameters such as the secret cookie, those which follow from the kind
657 of diversion requested, etc.
658
659 It is correct to always include the contents of C<Params> as hidden
660 parameters in the urls for all redirections, and as hidden input
661 fields in all generated forms.  The specific cases where C<Params> is
662 currently relevant are also mentioned in the text for each divert
663 kind.
664
665 =back
666
667 The values of C<Kind> are:
668
669 =over
670
671 =item C<SRCDUMP->I<item>
672
673 We should respond by sending our application source code.  I<item>
674 (which will contain only word characters, and no lower case) is the
675 specific item to send, normally C<SOURCE> or C<LICENCE>.
676
677 =item C<REDIRECT-HTTPS>
678
679 We should respond with an HTTP redirect to the HTTPS instance of our
680 application.
681
682 =item C<REDIRECT-LOGGEDOUT>
683
684 We should redirect to a page showing that the user has been logged
685 out.  (Ie, to a url with one of the the C<loggedout_param_names> set.)
686
687 =item C<SMALLPAGE-LOGGEDOUT>
688
689 We should generate a page showing that the user has been logged out.
690 There can be a link on the page pointing to the login page so that the
691 user can log back in.
692
693 =item C<SMALLPAGE-NOCOOKIE>
694
695 We should generate a page reporting that the user does not have
696 cookies enabled.  It should probably contain a link pointing to the
697 login page with additionally all the parameters in C<Params>.  When
698 this divert spec is generated, C<Message> will explain the problem
699 with cookies so there is no need to do that again in the page body if
700 you include the contents of C<Message>.
701
702 =item C<LOGIN-STALE>
703
704 The user's session was stale (this is described in C<Message>).  We
705 should generate a login form.
706
707 =item C<LOGIN-BAD>
708
709 The user supplied bad login credentials.  The details are in
710 C<Message>.  We should generate a login form (with additionally the
711 parameters from C<Params> as hidden fields).
712
713 =item C<LOGIN-INCOMINGLINK>
714
715 We should generate a login form (with the specified parameters); the
716 user is entering the site via a cross-site link but is not yet logged
717 in.
718
719 =item C<LOGIN-FRESH>
720
721 We should generate a login form.  The user is not yet logged in.
722
723 =item C<REDIRECT-LOGGEDIN>
724
725 We should redirect to our actual application, with the specified
726 parameters.  (The user has just logged in.)
727
728 =item C<STALE>
729
730 The user is logged in but the incoming form submission looks like it
731 was from a stale login session.  Alternatively, it may have been
732 generated by an attacker's cross-site-scripting attack.
733
734 Naive applications should generate a small page with a form or link to
735 our own main page without any parameters.
736
737 A sophisticated application could infer from the submitted form
738 parameters what the user was allegedly trying to do.  We could then
739 generate a fresh page showing what the intended action was, with a
740 fresh form which (if the user confirm) would resubmit that action.
741 B<Great care> must be taken to avoid relying on the sanity and
742 coherence of the incoming form parameters.  We B<MUST NOT> simply
743 reproduce the incoming parameters in the new form.  It is essential
744 that the visual appearance of the generated form correctly shows to
745 the user what the action is that will be taken if the form is
746 submitted.  If that action is dangerous, the form should not look like
747 the kind of confirmation pages which the user is likely to simply
748 click through without thinking.
749
750 =item C<MAINPAGEONLY>
751
752 We should generate our main page but B<ignoring all form parameters>
753 and B<ignoring the path_info>.  Most applications will find this
754 difficult to implement.
755
756 An alternative is to generate a small page with a form or link which
757 submits our own main page without any parameters.
758
759 (Applications which set C<promise_check_mutate> do not see this divert
760 kind.)
761
762 =back
763
764 =head1 SETTINGS
765
766 C<new_verifier> and C<new_request> each take a list of settings, as
767 a list of pairs C<< key => value >> (like a Perl hash assignment).
768
769 The settings supplied to C<new_verifier> are stored in the verifier
770 and will apply to all authreqs made from it unless overridden in the
771 call to C<new_request>
772
773 When a setting is described as a hook function, it should be a
774 coderef.  The first argument will be the query object from
775 L<CGI(3perl)> (strictly, it will be whatever value was passed to
776 C<new_request>).  The second argument will be the authreq object (the
777 return value from C<new_request>).
778 Ie, C<< sub some_hook ($$...) { my ($cgi,$authreq,@stuff) = @_ ... >>
779
780 In bullet point headings, the hook functions are shown in the form
781 C<< some_hook($cgi,$authreq,@stuff) >> even though this would not be
782 legal syntax.  This should be read to mean that the
783 %implicit_settings_hash{'some_hook'}($cgi,$authreq,@stuff)
784 would be a legal call.  (However, the settings hash is not exposed.)
785
786 When a hook's default implementation is mentioned and named, that
787 function won't also be described in the section on the module's
788 functions.
789
790 =head2 GENERAL SETTINGS
791
792 =over
793
794 =item C<dir>
795
796 The directory CGI::Auth::Generic should use for its data storage.
797 This is actually just a default absolute path used when the other
798 path settings are relative values.
799
800 Must be an absolute filename.
801
802 =item C<db_dbh>
803
804 CGI::Auth::Flexible needs a database for recording users' login
805 session.  This database needs to be shared across all instances of the
806 web application, so in a multi-node cluster it needs to be your actual
807 database.
808
809 CGI::Auth::Flexible will create the table and index it needs if they
810 don't already exist, and will manage their contents.  You do not need
811 to integrate them into the rest of your webapp's data storage.  (In
812 particular, there is no need for transactional integrity across
813 changes made by CAF and your own application.)
814
815 By default, CAF uses a sqlite3 database stored on local disk in the
816 file named by C<db_path>.  This will be suitable for all
817 applications which run on a single host.
818
819 This value, if supplied, should be a DBI handle for the database.
820
821 =item C<db_dsn>
822
823 This is the DSN to pass to C<< DBI->connect >>.  Used only if
824 C<db_dbh> is not supplied.
825
826 =item C<db_path>
827
828 Path to the sqlite3 database used for CAF's session storage.  The
829 default is C<caf.db>.
830
831 Used only if neither C<db_dbh> or C<db_dsn> are supplied.
832
833 If this is a relative path, it is in C<dir>.
834
835 =item C<db_prefix>
836
837 Prefix for the SQL tables and indices to use (and to create, if
838 necessary).
839
840 See L</DATABASE TABLES>.
841
842 =item C<keys_path>
843
844 Path to the keys file used by CAF.  This arrangement will change in
845 the future.  See L</BUGS>.
846
847 =item C<random_source>
848
849 Special file to read random numbers from.  Should return
850 cryptographically secure (pseudo)-random bytes, unpredictable to
851 adversaries (even ones on the same machine).
852
853 On Linux, there is no device which is properly suitable.  This is a
854 bug in Linux.  You can use C</dev/random> which can block
855 unnecessarily even though the kernel PRNG has been properly seeded and
856 is fine, or C</dev/urandom> which might return values which attackers
857 can predict if the kernel PRNG has not been properly seeded.
858
859 The default is C</dev/urandom>.
860
861 =item C<secretbits>
862
863 Length of the assoc secret.  Defaults to 128.
864
865 =item C<hash_algorithm>
866
867 Must be a string suitable for use with C<new Digest>.
868 Defaults to C<SHA-256>.
869
870 =item C<login_timeout>
871
872 A user will be logged out this many seconds after they first logged
873 in.  Default: 86400 (one day).
874
875 =item C<login_form_timeout>
876
877 A login form becomes invalid this many seconds after it has been sent.
878 Default: 3600 seconds (one hour).
879
880 =item C<key_rollover>
881
882 The key used for generating assoc secrets is rolled over approximately
883 this often (in seconds).  Default: 86400.
884
885 =item C<assoc_param_name>
886
887 Name of the hidden form parameter.  Default: C<caf_assochash>.
888
889 =item C<cookie_name>
890
891 Name of the cookie used for login sessions.  Default:
892 C<caf_assocsecret>.
893
894 =item C<password_param_name>
895
896 Name of the password field in the login form.  Default: C<password>.
897
898 Used by C<login_ok_password> (the default C<login_ok> hook),
899 C<gen_plain_login_form> and the default C<is_login> hook.
900
901 =item C<username_param_names>
902
903 Arrayref of name(s) of username form parameters.
904
905 The first entry is used by C<login_ok_password> (the default
906 C<login_ok> hook) to pass to the C<username_password_error> hook and
907 used as the username if all is well.
908
909 All the entries are used by C<gen_plain_login_fork> (the default
910 C<gen_login_form> hook for C<check_ok>) to generate form entry fields.
911
912 The default is C<['username']>.
913
914 =item C<logout_param_names>
915
916 Arrayref of name(s) of form parameters indicating that the request is
917 a logout request.
918
919 Used by the default C<is_logout> hook.
920
921 If you want users to be able to explicitly log out, you need to
922 provide a logout button, something like
923 C<< <input type="submit" name="caf_logout" ... >>
924
925 The default is C<['caf_logout']>
926
927 =item C<logged_param_names>
928
929 Arrayref of name(s) of form parameters indicating that user has just
930 logged out.  (During the logout process, the actual logout action is a
931 POST request, whose response redirects to the "you have been logged
932 out" page; these form parameters are for this second page.)
933
934 Used by the default C<is_loggedout> hook.
935
936 The first entry is used by C<check_ok> to generate the redirection.
937
938 The default is C<['caf_loggedout']>
939
940 =item C<promise_check_mutate>
941
942 Boolean.  If true, is a declaration by the application that it is
943 mutatin-aware.  See L</MUTATING OPERATIONS AND EXTERNAL LINKS>.
944
945 The default is 0.
946
947 =item C<encrypted_only>
948
949 Boolean.  If true, CAF will insist that all transactions be done over
950 an encrypted http connection.  It will redirect unencrypted requests
951 to the https instance of the applicattion, and will set the encrypted
952 only flag on its cookie.
953
954 The default is 1.
955
956 =item C<< get_url($cgi,$authreq) >>
957
958 Hook which returns the URL of this web application.  By default, we
959 call C<< $cgi->url() >> for each request, but you can fix this if you
960 prefer.
961
962 =item C<< is_login,is_logout,is_loggedout($cgi,$authreq) >>
963
964 Hook which returns a boolean indicating whether the request was,
965 respectively: a login form submission (ie, username and password); a
966 logout request (submission resulting from the user pressing the
967 "logout" button); "logged out" page (redirection from the logout
968 POST).
969
970 The default is to check whether any of the corresponding request
971 parameters (C<< login_param_names >> etc.) was supplied, using the
972 C<get_param> hook.
973
974 =back
975
976 =head2 SETTINGS (HOOKS) RELATED TO THE CGI REQUEST OBJECT
977
978 =over
979
980 =item C<< get_param($cgi,$authreq,$param) >>
981
982 Returns the value of a single-valued form parameter.
983 The default is to call C<< $cgi->param($param) >>.
984 The semantics are the same as that of C<CGI::param>.
985
986 =item C<< get_params($cgi,$authreq) >>
987
988 Returns a hash of the parameters.  The return value is a hashref whose
989 keys are the parameter names and whose values are arrayrefs, one entry
990 in the arrayref for each value.
991
992 The default is to call C<< $cgi->Vars() >>, expect the
993 results to look like those from C<CGI::Vars>, and massage them into
994 the required form with split.
995
996 =item C<< get_path_info($cgi,$authreq) >>
997
998 Returns the PATH_INFO of the request.  The default is to
999 call C<< $cgi->path_info() >>.
1000
1001 =item C<< get_cookie($cgi,$authreq) >>
1002
1003 Returns the value of the CAF cookie sent with the request, or undef if
1004 none was supplied.  The default is to call C<<
1005 $cgi->cookie($cookie_name) >> (where C<$cookie_name> is from the
1006 setting of the same name).  The return value should be the scalar
1007 value of the cookie.
1008
1009 =item C<< get_method($cgi,$authreq) >>
1010
1011 Returns the HTTP method as a string.  The default is to call
1012 C<< $cgi->request_method() >>.
1013
1014 =item C<< is_https($cgi,$authreq) >>
1015
1016 Returns a boolean indicating whether the request was over an encrypted
1017 channel.  The default is C<< !!$cgi->https() >>.  See C<encrypted_only>.
1018
1019 =back
1020
1021 =head2 SETTINGS RELATED TO HTML GENERATION
1022
1023 These are only used if you call C<check_ok> (or other functions
1024 mentioned in this section).
1025
1026 Settings whose names are of the form C<gen_...> are hooks which each
1027 return an array of strings, normally HTML strings, for use by
1028 C<check_ok> (or, in turn, other hooks, or your application).  These
1029 are often documented simply by showing the output produced.  In many
1030 cases parts of the output are in turn obtained from other hooks.  In
1031 some cases the default implementations have been given names for
1032 convenient use by your application.  They will be called in array
1033 context.
1034
1035 We'll write C<gettext(something)> even though actually there is a hook
1036 to control the translation function used.
1037
1038 =over
1039
1040 =item C<handle_divert>($cgi,$authreq,$divert))
1041
1042 C<check_ok> calls this hook before producing output of its own.  If
1043 you want to handle some but not all diversions yourself, you may set
1044 this hook.  The hook should either do nothing and return false, or
1045 return true if it has handled the request (or arrange for the request
1046 to be handled).  If the hook returns true then C<check_ok> simply
1047 returns 0.
1048
1049 =item C<gen_login_form>($cgi,$authreq,$divert))
1050
1051 Default: a table (used mostly for layout) containing input fields for
1052 a login form.  Must be within a C<< <form> >> element, but doesn't
1053 generate it.  Has text fields for every entry in
1054 C<username_param_names> (in each case associated with a description
1055 C<< gettext(ucfirst $parameter_name) >>, a password field (with
1056 description C<gettext("Password")>, and a login submit button (with
1057 description C<gettext("Login")>.
1058
1059 Default is available as the module function C<gen_plain_login_form>.
1060
1061 =item C<gen_login_link>($cgi,$authreq))
1062
1063 Default:
1064
1065  <a href="http:...">gettext(Log in again to continue.)</a>
1066
1067 Default is available as the module function C<gen_plain_login_link>.
1068
1069 =item C<gen_postmainpage_form>($cgi,$authreq,$params))
1070
1071 Default: form contents (but not the C<< <form> >> element):
1072
1073 C<$params> (in the form returned by the C<get_params> hook) as hidden
1074 fields, and also:
1075
1076  <input type="submit" ... value=getext('Continue')>
1077
1078 Default is available as the module function C<gen_postmainpage_form>.
1079
1080 =item C<gen_start_html>($cgi,$authreq,$title)
1081
1082 Default: C<$cgi->start_html($title)>
1083
1084 =item C<gen_end_html>($cgi,$authreq,$title)
1085
1086 Default: C<$cgi->end_html($title)>
1087
1088 =item C<gen_footer_html>($cgi,$authreq)>
1089
1090 Default:
1091
1092  <hr><address>
1093  Powered by Free / Libre / Open Source Software
1094  according to the [gen_licence_link_html].
1095  [gen_source_link_html].
1096  </address>
1097
1098 Default is available as the module function C<gen_plain_footer_html>.
1099
1100 =item C<gen_licence_link_html>($cgi,$authreq)>
1101
1102 Default: uses C<url_with_query_params> to generate a URL for
1103 downloading the licence, and returns:
1104   <a href="...">GNU Affero GPL</a>
1105
1106 Default is available as the module function C<gen_plain_licence_link_html>.
1107
1108 =item C<gen_source_link_html>($cgi,$authreq)>
1109
1110 Default: uses C<url_with_query_params> to generate a URL for
1111 downloading the source, and returns:
1112   <a href="...">Source available</a>
1113
1114 Default is available as the module function C<gen_plain_source_link_html>.
1115
1116 =item C<form_entry_size>
1117
1118 Size of generated text entry fields.  Default is 60.
1119
1120 =item C<dummy_param_name_prefix>
1121
1122 Some of CAF's HTML-generating functions need to invent form parameter
1123 names.  They will all start with this string.  Default: C<caf__>.
1124
1125 =back
1126
1127 =head2 SETTINGS FOR SOURCE CODE DOWNLOAD FACILITY
1128
1129 =over
1130
1131 =item C<srcdump_param_name>
1132
1133 Form parameter name used to indicate that this is a source download
1134 request.  If this parameter is supplied, C<check_ok> and
1135 C<check_divert> will arrange for the applicaton source code to be
1136 delivered as the response (in C<check_ok>'s case by doing it itself
1137 and in C<check_divert>'s case by asking your application to do so.
1138
1139 Default is C<caf_srcdump>.
1140
1141 =item C<srcdump_path>
1142
1143 Path to the directory used for storing pre-prepared source downloads.
1144 Defaults to C<caf-srcdump>.
1145
1146 If this is a relative path, it is in C<dir>.
1147
1148 =item C<srcdump_dump($cgi,$authreq,$srcobj)>
1149
1150 Dump the source code (C<$srcobj='source'> or licence data
1151 (C<$srcobj='licence'>).  The default implementation checks that
1152 C<$srcobj> has reasonable syntax and uses the files C<$srcobj.data>
1153 and C<$srcobj.ctype> with the C<dump> hook.
1154
1155 =item C<dump($cgi,$authreq,$contenttype,$datafilehandle)>
1156
1157 Responds to the request by sending the contents of $datafilehandle
1158 (which should just have been opened) and specifying a content type of
1159 $contenttype.
1160
1161 The default implmentation uses the C<print> hook, and also calls
1162 C<$cgi->header('-type' => $contenttype>, and is available as the
1163 module function C<dump_plain>.
1164
1165 =item C<srcdump_prepare($cgi,$verifier)>
1166
1167 Prepares the source code for download when requested.  Invoked by
1168 C<new_verifier>, always, immediately before it returns the
1169 just-created verifier object.
1170
1171 The default implementation is the module function
1172 C<srcdump_dirscan_prepare>, which prepares a manifest, licence file
1173 and source code tarball of tarballs, as follows:
1174
1175 It processes each entry in the return value from C<srcdump_listitems>.
1176 These are the software's include directories and any other directories
1177 containing source code.  It handles C<.> specially (see
1178 C<srcdump_filter_cwd>).
1179
1180 For each entry it looks, relative to that, for the licence as a file
1181 with a name mentioned in C<srcdump_licence_files>.  The first such
1182 file found is considered to be the licence.  It then calls the hook
1183 C<srcdump_process_item> for the entry.
1184
1185 The licence, a manifest file, and all the outputs generated by the
1186 calls to C<srcdump_process_item>, are tarred up and compressed as a
1187 single source tarball.
1188
1189 It uses the directory named by C<srcdump_path> as its directory for
1190 working and output files.  It uses the filename patterns
1191 C<generate.*>, C<licence.*>, C<s.[a-z][a-z][a-z].*>, C<manifest.*>,
1192 C<source.*> in that directory.
1193
1194 =item C<srcdump_process_item>($cgi,$verifier,$dumpdir,$item,\&outfn,\$needlicence,\%dirsdone)>
1195
1196 Processes a single include directory or software entry, so as to
1197 include the source code found there.  Called only by the default
1198 implementation of C<srcdump_prepare>.
1199
1200 C<$dumpdir> is the directory for working and output files.  C<$item>
1201 is the real (no symlinks) absolute path to the item.
1202
1203 C<\$needlicence> is a ref to a scalar: this scalar is undef if we have
1204 already found the licence file; otherwise it is the filename to which
1205 the licence should be copied.  If the referent is undef on entry,
1206 C<srcdump_process_item> needs to see if it finds the licence; if it
1207 does it should copy it to the named file and then set the scalar to
1208 undef.
1209
1210 C<\%dirsdone> is a ref to the hash used by C<srcdump_prepare> to avoid
1211 including a single directory more than once.  If
1212 C<srcdump_process_item> decides to process a directory other than
1213 C<$item> it should check this hash with the real absolute path of the
1214 other directoy as a key: if the hash entry is true, it has already
1215 been done and should be skipped; otherwise the hash entry should be set.
1216
1217 C<\&outfn> is a coderef which C<srcdump_process_item> should call each
1218 time it wants to generate a file which should be included as part of
1219 the source code.  It should be called using one of these patterns:
1220    $outfn->("message for manifest");
1221    $outfile = $outfn->("message for manifest", "extension");
1222 The former simply prints the message into the manifest in the form
1223   none: message for manifest
1224 The latter generates and returns a filename which should then
1225 be created and filled with some appropriate data.  C<"extension">
1226 should be a string for the file extension, eg C<"txt">.  The output
1227 can be written directly to the named file: there is no need to
1228 write to a temporary file and rename.  C<$outfn> writes the filename
1229 and the message to the manifest, in the form
1230   filename leaf: message
1231 In neither case is the actual name of C<$dir> on the system
1232 disclosed per se although of course some of the contents of some of
1233 the files in the source code dump may mention it.
1234
1235 The default implementation is the module function
1236 C<srcdump_process_item>.
1237
1238 It skips directories for which C<srcdump_system_dir> returns true.
1239
1240 It then searches the item and its parent
1241 directories for a vcs metadata directory (one of the names in
1242 C<srcdump_vcs_dirs>); if found, it calls the C<srcdump_byvcs> hook
1243 (after checking and updaeing C<%dirsdone>).
1244 Otherwise it calls the C<srcdump_novcs> hook.
1245
1246 =item C<srcdump_novcs($cgi,$verifier,$dumpdir,$item,$outfn)>
1247
1248 Called by the default implementation of C<srcdump_process_item>, with
1249 the same arguments, if it doesn't find vcs metadata.
1250
1251 The default implementation is the module function C<srcdump_novcs>.
1252
1253 If C<$item> is a directory, it uses C<srcdump_dir_cpio> to prepare a
1254 tarball of all the files under C<$item> which have the world read bit
1255 set.  Directories are not included (and their permissions are
1256 disregarded).  The contents of C<srcdump_excludes> are excluded.
1257
1258 If it's a plain file it uses C<srcdump_file> to include the file.
1259
1260 =item C<srcdump_byvcs($cgi,$verifier,$dumpdir,$item,$outfn,$vcs)>
1261
1262 Called by the default implementation of C<srcdump_process_item>, with
1263 the same arguments, if it finds vcs metadata.  The additional argument
1264 C<$vcs> is derived from the entry of C<srcump_vcs_dirs> which was
1265 used: it's the first sequence of word characters, lowercased.
1266
1267 The default implementation is the module function C<srcdump_byvcs>.
1268 It simply calls C<srcdump_dir_cpio> with a script from the setting
1269 C<srcdump_vcsscript>.
1270
1271 =item C<srcdump_vcs_dirs>
1272
1273 Array ref of leaf names of vcs metadata directories.  Used by the
1274 default implementation of C<srcdump_process_item>.  The default value
1275 is C<['.git','.hg','.bzr','.svn']>.
1276
1277 =item C<srcdump_vcs_script>
1278
1279 Hash ref of scripts for generating vcs metadata.  Used by the default
1280 implementation of C<srcdump_byvcs>.  The keys are values of C<$vcs>
1281 (see C<srcdump_byvcs>); the values are scripts as for
1282 C<srcdump_dir_cpio>.
1283
1284 The default has an entry only for C<git>:
1285   git ls-files -z
1286   git ls-files -z --others --exclude-from=.gitignore
1287   find .git -print0
1288
1289 =item C<srcdump_excludes>
1290
1291 Array ref of exclude glob patterns, used by the default implementation
1292 of C<srcdump_novcs>.  The default value is C<['*~','*.bak','*.tmp','#*#']>.
1293
1294 Entries must not contain C<'> or C<\>.
1295
1296 =item C<srcdump_listitems($cgi,$verifier)>
1297
1298 Returns an array of directories which might contain source code of the
1299 web application and which should be therefore be considered for
1300 including in the source code delivery.
1301
1302 Used by the default implementation of C<srcdump_prepare>.
1303
1304 Entries must be directories, plain files, or nonexistent; they may
1305 also be symlinks which resolve to one of those.
1306
1307 If C<.> is included it may be treated specially - see
1308 C<srcdump_filter_cwd>.
1309
1310 The default implementation returns 
1311 C<(@INC, $ENV{'SCRIPT_FILENAME'}, $0)>.
1312
1313 =item C<srcdump_system_dir($cgi,$verifier,$dir)>
1314
1315 Determines whether C<$dir> is a "system directory", in which any
1316 source code used by the application should nevertheless not be
1317 included in the source code dump.
1318
1319 Used by the default implementation of C<srcdump_item>.
1320
1321 The default implementation is as follows: Things in C</etc/> are
1322 system directories.  Things in C</usr/> are too, unless they are in
1323 C</usr/local/> or C</usr/lib/cgi*>.
1324
1325 =item C<srcdump_filter_cwd>
1326
1327 Boolean which controls the handling of C<.> if it appears in the
1328 return value from C<srcdump_listitems>.  Used only by the default
1329 implementation of C<srcdump_prepare>.
1330
1331 If set to false, C<.> is treated normally and no special action is
1332 taken.
1333
1334 However often the current directory may be C</>, or a data directory,
1335 or some other directory containing data which is confidential, or
1336 should not be included in the public source code distribution for
1337 other reasons.  And for historical reasons Perl has C<@INC> containing
1338 C<.> by default (which is arguably dangerous and wrong).
1339
1340 So the default this setting is true, which has the following effects:
1341
1342 C<.> is not searched for source code even if it appears in C<@INC>.
1343 C<.> is removed from C<@INC> and C<%INC> is checked to see if any
1344 modules appear to have already been loaded by virtue of C<.> appearing
1345 in C<@INC> and if they have it is treated as a fatal error.
1346
1347 Only the literal string C<.> is affected.  If the cwd is included by
1348 any other name it is not treated specially regardless of this setting.
1349
1350 =back
1351
1352 =head1 DATABASE TABLES
1353
1354 In a simple application, you do not need to worry about this.  But if
1355 your application runs on multiple frontend hosts with a shared
1356 database, you may need to create for yourself the tables and indices
1357 used by CGI::Auth::Flexible.
1358
1359 By default, every time CAF starts up, it attempts to execute certain
1360 fixed database statements to create the tables and indices it needs.
1361 These are run with C<$dbh->{PrintError}> set to 0.  The effect with
1362 sqlite (the default database) is that the tables and indices are
1363 created iff they do not already exist, and that no spurious errors are
1364 reported anywhere.
1365
1366 If you use a different database, or just prefer to do things
1367 differently, you can set up the tables yourself and/or disable or
1368 modify the default setup statements, via the C<db_setup_stmts>
1369 setting.
1370
1371 The tables needed are:
1372
1373
1374 xxx document _db_setup_do
1375 xxx make _db_setup_do explicitly overrideable
1376
1377
1378 xxx remaining settings
1379  db_password
1380  username_password_error
1381  login_ok
1382  get_cookie_domain
1383  gettext
1384  print
1385  debug
1386
1387 xxx document cookie usage
1388 xxx document construct_cookie fn
1389
1390 xxx document @default_db_setup_statements
1391
1392 xxx bugs wrong default random on Linux
1393
1394 xxx bugs wrong default random on *BSD
1395
1396 xxx bugs keys not shared should be in db
1397
1398 xxx rename caf_assocsecret default cookie name
1399
1400 xxx mention relationship between login_timeout and cookies