Skip to content

Commit 454e24c

Browse files
authored
Merge pull request hoisie#196 from hoisie/secure-cookie-crash
Secure cookie crash
2 parents 07b2986 + 0524586 commit 454e24c

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

examples/hello.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/hoisie/web"
55
)
66

7-
func hello(val string) string { return "hello " + val }
7+
func hello(val string) string { return "hello " + val + "\n" }
88

99
func main() {
1010
web.Get("/(.*)", hello)

examples/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
)
88

9-
func hello(val string) string { return "hello " + val }
9+
func hello(val string) string { return "hello " + val + "\n" }
1010

1111
func main() {
1212
f, err := os.Create("server.log")

examples/multiserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"github.com/hoisie/web"
55
)
66

7-
func hello1(val string) string { return "hello1 " + val }
7+
func hello1(val string) string { return "hello1 " + val + "\n" }
88

9-
func hello2(val string) string { return "hello2 " + val }
9+
func hello2(val string) string { return "hello2 " + val + "\n" }
1010

1111
func main() {
1212
var server1 web.Server

examples/tls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ gWrxykqyLToIiAuL+pvC3Jv8IOPIiVFsY032rOqcwSGdVUyhTsG28+7KnR6744tM
4747
-----END CERTIFICATE-----
4848
`
4949

50-
func hello(val string) string { return "hello " + val }
50+
func hello(val string) string { return "hello " + val + "\n" }
5151

5252
func main() {
5353
config := tls.Config{

web.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ func (ctx *Context) GetSecureCookie(name string) (string, bool) {
145145
}
146146

147147
parts := strings.SplitN(cookie.Value, "|", 3)
148+
if len(parts) != 3 {
149+
return "", false
150+
}
148151

149152
val := parts[0]
150153
timestamp := parts[1]

web_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,17 @@ func TestSecureCookie(t *testing.T) {
496496
}
497497
}
498498

499+
func TestEmptySecureCookie(t *testing.T) {
500+
mainServer.Config.CookieSecret = "7C19QRmwf3mHZ9CPAaPQ0hsWeufKd"
501+
cookies := makeCookie(map[string]string{"empty": ""})
502+
503+
resp2 := getTestResponse("GET", "/securecookie/get/empty", "", nil, cookies)
504+
505+
if resp2.body != "" {
506+
t.Fatalf("Expected an empty secure cookie")
507+
}
508+
}
509+
499510
func TestEarlyClose(t *testing.T) {
500511
var server1 Server
501512
server1.Close()

0 commit comments

Comments
 (0)