X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=cgi-auth-flexible.git;a=blobdiff_plain;f=cgi-auth-flexible.pm;h=1197f868fa2fce022a5f06b83e661a92360a3626;hp=954b0218c17b10357e0ab927c708378024cbc279;hb=53d4ed13ee06c55dad8337aa556eb631afddd8ae;hpb=103380f163dd8ee94d530e7469b71eba811fd761 diff --git a/cgi-auth-flexible.pm b/cgi-auth-flexible.pm index 954b021..1197f86 100644 --- a/cgi-auth-flexible.pm +++ b/cgi-auth-flexible.pm @@ -17,8 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -die "need to fix js hijacking"; - use strict; use warnings FATAL => 'all'; @@ -79,10 +77,11 @@ sub has_a_param ($$) { sub get_params ($) { my ($r) = @_; - my %p; my $c = $r->{Cgi}; - foreach my $name ($c->param()) { - $p{$name} = [ $c->param($name) ]; + my $vars = $c->Vars(); + my %p; + foreach my $name (keys %$vars) { + $p{$name} = [ split "\0", $vars->{$name} ]; } return \%p; } @@ -181,8 +180,9 @@ sub gen_plain_login_link ($$) { sub gen_srcdump_link_html ($$$$) { my ($c,$r,$anchor,$specval) = @_; my %params = ($r->{S}{srcdump_param_name} => [ $specval ]); - return ''. - $anchor.""; + return ''.$anchor.""; } sub gen_plain_licence_link_html ($$) { my ($c,$r) = @_; @@ -282,8 +282,9 @@ sub srcdump_novcs ($$$$$) { sub srcdump_byvcs ($$$$$$) { my ($c, $v, $dumpdir, $dir, $outfn, $vcs) = @_; #print STDERR "BYVCS GIT $dir\n"; - return srcdump_dir_cpio($c,$v,$dumpdir,$dir,$outfn,$vcs, - $v->{S}{"srcdump_vcsscript_$vcs"}); + my $script = $v->{S}{"srcdump_vcsscript"}{$vcs}; + die "no script for vcs $vcs" unless defined $script; + return srcdump_dir_cpio($c,$v,$dumpdir,$dir,$outfn,$vcs,$script); } sub srcdump_file ($$$$) { @@ -447,14 +448,13 @@ sub new_verifier { get_path_info => sub { $_[0]->path_info() }, get_cookie => sub { $_[0]->cookie($_[1]->{S}{cookie_name}) }, get_method => sub { $_[0]->request_method() }, - check_https => sub { !!$_[0]->https() }, + is_https => sub { !!$_[0]->https() }, get_url => sub { $_[0]->url(); }, is_login => sub { defined $_[1]->_rp('password_param_name') }, login_ok => \&login_ok_password, username_password_error => sub { die }, is_logout => sub { $_[1]->has_a_param('logout_param_names') }, is_loggedout => sub { $_[1]->has_a_param('loggedout_param_names') }, - is_page => sub { return 1 }, handle_divert => sub { return 0 }, do_redirect => \&do_redirect_cgi, # this hook is allowed to throw cookie_path => "/", @@ -478,16 +478,12 @@ sub new_verifier { $_[2] =~ m#^/etc/|^/usr/(?!local/)(?!lib/cgi)#; }, srcdump_process_item => \&srcdump_process_item, - srcdump_vcs_dirs => [qw(.git .hg .bzr .svn CVS)], - srcdump_vcsscript_git => " + srcdump_vcs_dirs => [qw(.git .hg .bzr .svn)], + srcdump_vcsscript => [git => " git ls-files -z git ls-files -z --others --exclude-from=.gitignore find .git -print0 - ", - srcdump_vcsscript_hg => "false hg", - srcdump_vcsscript_bzr => "false bzr", - srcdump_vcsscript_svn => "false svn", - srcdump_vcsscript_cvs => "false cvs", + "], srcdump_byvcs => \&srcdump_byvcs, srcdump_novcs => \&srcdump_novcs, srcdump_excludes => [qw(*~ *.bak *.tmp), '#*#'], @@ -500,7 +496,9 @@ sub new_verifier { }; my ($k,$v); while (($k,$v,@_) = @_) { - die "unknown setting $k" unless exists $verifier->{S}{$k}; + die "unknown setting $k" unless + $k =~ m/^promise_/ or + exists $verifier->{S}{$k}; $verifier->{S}{$k} = $v; } bless $verifier, $class; @@ -666,9 +664,9 @@ my @ca = (-name => $r->{S}{cookie_name}, # pages/param-sets are # n normal non-mutating page -# r retrieval of information for JS, non-mutating +# r retrieval of information for JS etc., non-mutating # m mutating page -# u update of information by JS, mutating +# u update of information by JS etc., mutating # i login # o logout # O "you have just logged out" page load @@ -788,7 +786,7 @@ sub _check_divert_core ($) { my $cooks = $r->_ch('get_cookie'); - if ($r->{S}{encrypted_only} && !$r->_ch('check_https')) { + if ($r->{S}{encrypted_only} && !$r->_ch('is_https')) { return ({ Kind => 'REDIRECT-HTTPS', Message => $r->_gt("Redirecting to secure server..."), CookieSecret => undef, @@ -834,7 +832,7 @@ sub _check_divert_core ($) { " enabled. You must enable cookies". " as we use them for login."), CookieSecret => $r->_fresh_secret(), - Params => $r->chain_params() }) + Params => $r->_chain_params() }) } if (!$cookt || $cookt eq 'n' || $cookh ne $parmh) { $r->_db_revoke($cookh); @@ -852,13 +850,13 @@ sub _check_divert_core ($) { return ({ Kind => 'LOGIN-BAD', Message => $login_errormessage, CookieSecret => $cooks, - Params => $r->chain_params() }) + Params => $r->_chain_params() }) } $r->_db_record_login_ok($parmh,$username); return ({ Kind => 'REDIRECT-LOGGEDIN', Message => $r->_gt("Logging in..."), CookieSecret => $cooks, - Params => $r->chain_params() }); + Params => $r->_chain_params() }); } if ($cookt eq 't') { $cookt = ''; @@ -878,7 +876,7 @@ sub _check_divert_core ($) { return ({ Kind => 'LOGIN-INCOMINGLINK', Message => $r->_gt("You need to log in."), CookieSecret => $news, - Params => $r->chain_params() }); + Params => $r->_chain_params() }); } else { $r->_db_revoke($parmh); return ({ Kind => 'LOGIN-FRESH', @@ -905,13 +903,21 @@ sub _check_divert_core ($) { die unless $parmt eq 'y'; die unless $cookh eq $parmh; } + $r->{ParmT} = $parmt; $r->{AssocSecret} = $cooks; $r->{UserOK} = $cooku; #print STDERR "C-D-C OK\n"; return undef; } -sub chain_params ($) { +sub _chain_params ($) { +# =item C<< $authreq->_chain_params() >> +# +# Returns a hash of the "relevant" parameters to this request, in a form +# used by C. This is all of the query parameters +# which are not related to CGI::Auth::Flexible. The PATH_INFO from the +# request is returned as the parameter C<< '' >>. + my ($r) = @_; my %p = %{ $r->_ch('get_params') }; foreach my $pncn (keys %{ $r->{S} }) { @@ -1034,12 +1040,16 @@ sub get_username ($) { return $r->{UserOK}; } -sub url_with_query_params ($$) { - my ($r, $params) = @_; +sub url_with_query_params ($$;$) { + my ($r, $params, $nonpagetype) = @_; #print STDERR "PARAMS ",Dumper($params); my $uri = URI->new($r->_ch('get_url')); $uri->path($uri->path() . $params->{''}[0]) if $params->{''}; - $uri->query_form(flatten_params($params)); + my @flatparams = flatten_params($params); + if (defined $nonpagetype && $r->need_add_hidden('GET',$nonpagetype)) { + push @flatparams, $r->{S}{assoc_param_name}, $r->secret_hidden_val(); + } + $uri->query_form(@flatparams); return $uri->as_string(); } @@ -1071,7 +1081,7 @@ sub check_ok ($) { } if ($kind =~ m/^REDIRECT-/) { - # for redirects, we honour stored NextParams and SetCookie, + # for redirects, we honour stored Params and Cookie, # as we would for non-divert if ($kind eq 'REDIRECT-LOGGEDOUT') { $params->{$r->{S}{loggedout_param_names}[0]} = [ 1 ]; @@ -1279,11 +1289,39 @@ sub check_mutate ($) { $r->_must_be_post(); } -sub mutate_ok ($) { - my ($r) = @_; +our %_resource_get_needs_secret_hidden = + (map { $_ => 0 } qw(PAGE FRAME IFRAME SRCDUMP STYLESHEET FAVICON ROBOTS), + map { $_ => 1 } qw(IMAGE SCRIPT AJAX-XML AJAX-JSON AJAX-OTHER)); + +sub update_get_need_add_hidden ($$;$) { + my ($r, $reqtype, $value, $force) = @_; + my $hash = ref $r + ? ($r->{GetNeedsSecretHidden} ||= { }) + : \%_resource_get_needs_secret_hidden; + return if !$force && + (exists $_resource_get_needs_secret_hidden{$reqtype} || + exists $hash->{$reqtype}); + $hash->{$reqtype} = $value; +} + +sub need_add_hidden ($$) { + my ($r, $method, $reqtype) = @_; + return 1 if $method ne 'GET'; + if (ref $r) { + my $ent = $r->{GetNeedsSecretHidden}{$reqtype}; + return $ent if defined $ent; + } + my $ent = $_resource_get_needs_secret_hidden{$reqtype}; + return $ent if defined $ent; + die "unsupported nonpage GET type $reqtype"; +} + +sub check_nonpage ($$) { + my ($r, $reqtype) = @_; $r->_assert_checked(); - die if $r->{Divert}; - return $r->_is_post(); + return unless $r->resource_get_needs_secret_hidden($nonpagetype); + return if $r->{ParmT}; + die "missing hidden secret parameter on nonpage request $nonpagetype"; } #---------- output ----------