Changeset 1221 for trunk/core/lib/Foswiki.pm
- Timestamp:
- 12/09/08 18:16:48 (3 years ago)
- File:
-
- 1 edited
-
trunk/core/lib/Foswiki.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/lib/Foswiki.pm
r1206 r1221 407 407 $regex{anchorRegex} = qr/\#[$regex{mixedAlphaNum}_]+/o; 408 408 $regex{abbrevRegex} = qr/[$regex{upperAlpha}]{3,}s?\b/o; 409 409 $regex{topicNameRegex} = 410 qr/(?:(?:$regex{wikiWordRegex})|(?:$regex{abbrevRegex}))/o; 410 411 # Simplistic email regex, e.g. for WebNotify processing - no i18n 411 412 # characters allowed … … 724 725 } 725 726 726 =begin TML 727 728 ---++ StaticMethod isRedirectSafe($redirect) => $ok 729 730 tests if the $redirect is an external URL, returning false if AllowRedirectUrl is denied 731 732 =cut 733 734 sub isRedirectSafe { 727 # Tests if the $redirect is an external URL, returning false if 728 # AllowRedirectUrl is denied 729 sub _isRedirectSafe { 735 730 my $redirect = shift; 736 731 … … 758 753 } 759 754 760 # _getRedirectUrl() => redirectURL set from the parameter 761 # Reads a redirect url from CGI parameter 'redirectto'. 762 # This function is used to get and test the 'redirectto' cgi parameter, 763 # and then the calling function can set its own reporting if there is a 764 # problem. 765 sub _getRedirectUrl { 766 my $session = shift; 767 768 my $query = $session->{request}; 769 my $redirecturl = $query->param('redirectto'); 770 return '' unless $redirecturl; 755 =begin TML 756 757 ---++ ObjectMethod redirectto($url) -> $url 758 Gets a redirect url from CGI parameter 'redirectto', if present on the query. 759 760 If the redirectto CGI parameter specifies a valid redirection target it is 761 returned; otherwise the original URL passed in the parameter is returned. 762 763 Conditions for a valid redirection target are: 764 * The target matches the linkProtocolPattern regex, and redirection 765 to the url _isRedirectSafe 766 * The target specified a topic, or a Web.Topic (redirect will be to 767 'view') 768 769 =cut 770 771 sub redirectto { 772 my ($this, $url) = @_; 773 ASSERT($url); 774 775 my $redirecturl = $this->{request}->param('redirectto'); 776 return $url unless $redirecturl; 771 777 772 778 if ( $redirecturl =~ m#^$regex{linkProtocolPattern}://#o ) { 773 779 774 780 # assuming URL 775 if ( isRedirectSafe($redirecturl) ) {781 if ( _isRedirectSafe($redirecturl) ) { 776 782 return $redirecturl; 777 783 } 778 784 else { 779 return '';785 return $url; 780 786 } 781 787 } … … 783 789 # assuming 'web.topic' or 'topic' 784 790 my ( $w, $t ) = 785 $session->normalizeWebTopicName( $session->{webName}, $redirecturl ); 786 $redirecturl = $session->getScriptUrl( 1, 'view', $w, $t ); 787 return $redirecturl; 788 } 789 790 =begin TML 791 792 ---++ ObjectMethod redirect( $url, $passthrough, $action_redirectto ) 791 $this->normalizeWebTopicName( $this->{webName}, $redirecturl ); 792 return $this->getScriptUrl( 1, 'view', $w, $t ); 793 } 794 795 =begin TML 796 797 ---++ ObjectMethod redirect( $url, $passthrough ) 793 798 794 799 * $url - url or topic to redirect to 795 * $passthrough - (optional) parameter to **FILLMEIN** 796 * $action_redirectto - (optional) redirect to where ?redirectto= 797 points to (if it's valid) 800 * $passthrough - (optional) parameter to pass through current query 801 parameters (see below) 798 802 799 803 Redirects the request to =$url=, *unless* 800 804 1 It is overridden by a plugin declaring a =redirectCgiQueryHandler=. 801 805 1 =$session->{request}= is =undef= or 802 1 $query->param('noredirect') is set to a true value.803 806 Thus a redirect is only generated when in a CGI context. 804 807 … … 820 823 821 824 sub redirect { 822 my ( $this, $url, $passthru, $action_redirectto ) = @_; 825 my ( $this, $url, $passthru ) = @_; 826 ASSERT(defined $url); 823 827 824 828 my $query = $this->{request}; … … 826 830 # if we got here without a query, there's not much more we can do 827 831 return unless $query; 828 829 # SMELL: if noredirect is set, don't generate the redirect, throw an830 # exception instead. This is a HACK used to support TWikiDrawPlugin.831 # It is deprecated and must be replaced by REST handlers in the plugin.832 if ( $query->param('noredirect') ) {833 die "ERROR: $url";834 return;835 }836 837 if ($action_redirectto) {838 my $redir = _getRedirectUrl($this);839 $url = $redir if ($redir);840 }841 832 842 833 if ( $passthru && defined $query->method() ) { … … 872 863 # do this check as late as possible to catch _any_ last minute hacks 873 864 # TODO: this should really use URI 874 if ( ! isRedirectSafe($url) ) {865 if ( !_isRedirectSafe($url) ) { 875 866 876 867 # goto oops if URL is trying to take us somewhere dangerous … … 962 953 my ($name) = @_; 963 954 964 return isValidWikiWord(@_) || isValidAbbrev(@_); 965 } 966 967 =begin TML 968 969 ---++ StaticMethod isValidAbbrev( $name ) -> $boolean 970 971 Check for a valid ABBREV (acronym) 972 973 =cut 974 975 sub isValidAbbrev { 976 my $name = shift || ''; 977 return ( $name =~ m/^$regex{abbrevRegex}$/o ); 955 return ( $name =~ m/^$regex{topicNameRegex}$/o ); 978 956 } 979 957 … … 1148 1126 while ( my $p = shift @args ) { 1149 1127 if ( $p eq '#' ) { 1150 $anchor .= '#' . shift(@args);1128 $anchor .= '#' . urlEncode( shift(@args) ); 1151 1129 } 1152 1130 else { … … 3859 3837 # Issues multi-valued parameters as separate hiddens 3860 3838 my $value = $this->{request}->param($name); 3839 $value = '' unless defined $value; 3861 3840 $name = _encode( $encoding, $name ); 3862 3841 $value = _encode( $encoding, $value );
Note: See TracChangeset
for help on using the changeset viewer.
