Skip to content

Commit

Permalink
Do not allow path parent path refs in file hook
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Oct 20, 2013
1 parent 3127ba0 commit aadd5da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hooks/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ package hooks
import (
"os"
"io"
"regexp"
)

var pathEscape = regexp.MustCompile("\\.\\.\\/")

var FileHook = HookComponents{
func (path string) (io.ReadCloser, error) {
file, err := os.Open(path)
Expand All @@ -15,6 +18,6 @@ var FileHook = HookComponents{
return file, nil
},
func (s string) string{
return s
return pathEscape.ReplaceAllLiteralString(s, "")
},
}
9 changes: 9 additions & 0 deletions hooks/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func TestHooks(t *testing.T) {
"filecontents",
noError,
},
{
&config.HookDef{
Regexp: ".*",
FileTemplate: "$0",
},
"../file_fixture.txt",
"filecontents",
noError,
},
{
&config.HookDef{
Regexp: "^extension:(.*)$",
Expand Down

0 comments on commit aadd5da

Please sign in to comment.