Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
59a5afab
Commit
59a5afab
authored
May 02, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fastcgi: Prepend missing leading slash when matching paths (see #1645)
httpserver: More path matching tests
parent
d8fb2ddc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
5 deletions
+56
-5
caddyhttp/fastcgi/fastcgi.go
caddyhttp/fastcgi/fastcgi.go
+19
-3
caddyhttp/httpserver/path_test.go
caddyhttp/httpserver/path_test.go
+37
-2
No files found.
caddyhttp/fastcgi/fastcgi.go
View file @
59a5afab
...
@@ -36,9 +36,25 @@ type Handler struct {
...
@@ -36,9 +36,25 @@ type Handler struct {
// ServeHTTP satisfies the httpserver.Handler interface.
// ServeHTTP satisfies the httpserver.Handler interface.
func
(
h
Handler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
func
(
h
Handler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
for
_
,
rule
:=
range
h
.
Rules
{
for
_
,
rule
:=
range
h
.
Rules
{
// First requirement: Base path must match request path. If it doesn't,
// First requirement: Base path must match and the path must be allowed.
// we check to make sure the leading slash is not missing, and if so,
if
!
httpserver
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
rule
.
Path
)
||
!
rule
.
AllowedPath
(
r
.
URL
.
Path
)
{
// we check again with it prepended. This is in case people forget
// a leading slash when performing rewrites, and we don't want to expose
// the contents of the (likely PHP) script. See issue #1645.
hpath
:=
httpserver
.
Path
(
r
.
URL
.
Path
)
if
!
hpath
.
Matches
(
rule
.
Path
)
{
if
strings
.
HasPrefix
(
string
(
hpath
),
"/"
)
{
// this is a normal-looking path, and it doesn't match; try next rule
continue
}
hpath
=
httpserver
.
Path
(
"/"
+
string
(
hpath
))
// prepend leading slash
if
!
hpath
.
Matches
(
rule
.
Path
)
{
// even after fixing the request path, it still doesn't match; try next rule
continue
}
}
// The path must also be allowed (not ignored).
if
!
rule
.
AllowedPath
(
r
.
URL
.
Path
)
{
continue
continue
}
}
...
...
caddyhttp/httpserver/path_test.go
View file @
59a5afab
...
@@ -5,7 +5,7 @@ import "testing"
...
@@ -5,7 +5,7 @@ import "testing"
func
TestPathMatches
(
t
*
testing
.
T
)
{
func
TestPathMatches
(
t
*
testing
.
T
)
{
for
i
,
testcase
:=
range
[]
struct
{
for
i
,
testcase
:=
range
[]
struct
{
reqPath
Path
reqPath
Path
rulePath
string
rulePath
string
// or "base path" as in Caddyfile docs
shouldMatch
bool
shouldMatch
bool
caseInsensitive
bool
caseInsensitive
bool
}{
}{
...
@@ -48,7 +48,42 @@ func TestPathMatches(t *testing.T) {
...
@@ -48,7 +48,42 @@ func TestPathMatches(t *testing.T) {
},
},
{
{
reqPath
:
""
,
reqPath
:
""
,
rulePath
:
"/"
,
// a lone forward slash means to match all requests (see issue #1645)
rulePath
:
"/"
,
// a lone forward slash means to match all requests (see issue #1645) - many future test cases related to this issue
shouldMatch
:
true
,
},
{
reqPath
:
"foobar.php"
,
rulePath
:
"/"
,
shouldMatch
:
true
,
},
{
reqPath
:
""
,
rulePath
:
""
,
shouldMatch
:
true
,
},
{
reqPath
:
"/foo/bar"
,
rulePath
:
""
,
shouldMatch
:
true
,
},
{
reqPath
:
"/foo/bar"
,
rulePath
:
""
,
shouldMatch
:
true
,
},
{
reqPath
:
"no/leading/slash"
,
rulePath
:
"/"
,
shouldMatch
:
true
,
},
{
reqPath
:
"no/leading/slash"
,
rulePath
:
"/no/leading/slash"
,
shouldMatch
:
false
,
},
{
reqPath
:
"no/leading/slash"
,
rulePath
:
""
,
shouldMatch
:
true
,
shouldMatch
:
true
,
},
},
}
{
}
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment