Skip to content

Commit e747101

Browse files
committed
Updated to support Revel release 0.21.0, revel.TRACE is deprecated.
1 parent d058342 commit e747101

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

csrf.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
2929

3030
// [OWASP]; General Recommendation: Synchronizer Token Pattern:
3131
// CSRF tokens must be associated with the user's current session.
32-
tokenCookie, found := c.Session[cookieName]
32+
tokenCookie, found := c.Session[cookieName].(string)
3333
realToken := ""
3434
if !found {
3535
realToken = generateNewToken(c)
3636
} else {
3737
realToken = tokenCookie
38-
revel.TRACE.Printf("REVEL-CSRF: Session's token: '%s'\n", realToken)
38+
revel.AppLog.Debugf("REVEL-CSRF: Session's token: '%s'\n", realToken)
3939
if len(realToken) != lengthCSRFToken {
4040
// Wrong length; token has either been tampered with, we're migrating
4141
// onto a new algorithm for generating tokens, or a new session has
4242
// been initiated. In any case, a new token is generated and the
4343
// error will be detected later.
44-
revel.TRACE.Printf("REVEL_CSRF: Bad token length: found %d, expected %d",
44+
revel.AppLog.Debugf("REVEL_CSRF: Bad token length: found %d, expected %d",
4545
len(realToken), lengthCSRFToken)
4646
realToken = generateNewToken(c)
4747
}
@@ -52,7 +52,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
5252
// See http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods
5353
unsafeMethod := !safeMethods.MatchString(r.Method)
5454
if unsafeMethod && !IsExempted(r.URL.Path) {
55-
revel.TRACE.Printf("REVEL-CSRF: Processing unsafe '%s' method...", r.Method)
55+
revel.AppLog.Debugf("REVEL-CSRF: Processing unsafe '%s' method...", r.Method)
5656
if r.URL.Scheme == "https" {
5757
// See [OWASP]; Checking the Referer Header.
5858
referer, err := url.Parse(r.Header.Get("Referer"))
@@ -80,7 +80,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
8080
// Get CSRF token from form.
8181
sentToken = c.Params.Get(fieldName)
8282
}
83-
revel.TRACE.Printf("REVEL-CSRF: Token received from client: '%s'", sentToken)
83+
revel.AppLog.Debugf("REVEL-CSRF: Token received from client: '%s'", sentToken)
8484

8585
if len(sentToken) != len(realToken) {
8686
c.Result = c.Forbidden(errBadToken)
@@ -91,7 +91,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
9191
c.Result = c.Forbidden(errBadToken)
9292
return
9393
}
94-
revel.TRACE.Println("REVEL-CSRF: Token successfully checked.")
94+
revel.AppLog.Debugf("REVEL-CSRF: Token successfully checked.")
9595
}
9696

9797
fc[0](c, fc[1:])

exemptions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func IsExempted(path string) bool {
3535
_, found := exemptionsFullPath.list[path]
3636
exemptionsFullPath.RUnlock()
3737
if found {
38-
revel.TRACE.Printf("REVEL-CSRF: Ignoring exempted route '%s'...\n", path)
38+
revel.AppLog.Debugf("REVEL-CSRF: Ignoring exempted route '%s'...\n", path)
3939
return true
4040
}
4141

@@ -48,7 +48,7 @@ func IsExempted(path string) bool {
4848
panic(fmt.Sprintf("REVEL-CSRF: malformed glob pattern: %#v", err))
4949
}
5050
if found {
51-
revel.TRACE.Printf("REVEL-CSRF: Ignoring exempted route '%s'...", path)
51+
revel.AppLog.Debugf("REVEL-CSRF: Ignoring exempted route '%s'...", path)
5252
return true
5353
}
5454
}
@@ -57,7 +57,7 @@ func IsExempted(path string) bool {
5757

5858
// ExemptedFullPath exempts one exact path from CSRF checks.
5959
func ExemptedFullPath(path string) {
60-
revel.TRACE.Printf("REVEL-CSRF: Adding exemption '%s'...\n", path)
60+
revel.AppLog.Debugf("REVEL-CSRF: Adding exemption '%s'...\n", path)
6161
exemptionsFullPath.Lock()
6262
exemptionsFullPath.list[path] = struct{}{}
6363
exemptionsFullPath.Unlock()
@@ -73,7 +73,7 @@ func ExemptedFullPaths(paths ...string) {
7373
// ExemptedGlob exempts one path from CSRF checks using pattern matching.
7474
// See http://golang.org/pkg/path/#Match
7575
func ExemptedGlob(path string) {
76-
revel.TRACE.Printf("REVEL-CSRF: Adding exemption GLOB '%s'...\n", path)
76+
revel.AppLog.Debugf("REVEL-CSRF: Adding exemption GLOB '%s'...\n", path)
7777
exemptionsGlobs.Lock()
7878
exemptionsGlobs.list = append(exemptionsGlobs.list, path)
7979
exemptionsGlobs.Unlock()

tokengen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func generateNewToken(c *revel.Controller) (token string) {
2323
// Due to base64 encoding, CSRF tokens cannot have null bytes and therefore
2424
// can safely be used as session values in Revel.
2525
token = base64.StdEncoding.EncodeToString(bytes)
26-
revel.TRACE.Printf("REVEL-CSRF: Generated new Token: '%s'\n", token)
26+
revel.AppLog.Debugf("REVEL-CSRF: Generated new Token: '%s'\n", token)
2727
c.Session[cookieName] = token
2828
return
2929
}

0 commit comments

Comments
 (0)