Skip to content

Commit b1c057e

Browse files
committed
Merge pull request cbonello#7 from iassic/replace/glogWithRevelLogs
replacing calls to glog with revel.TRACE Next release of revel is supposed to use glob (see https://github.com/robfig/revel/tree/v1). That's why we moved from revel.TRACE to glob about 3 months ago. But v1 is still in development... We'll move back to glob when v1 is released.
2 parents 9a98863 + 9c84e88 commit b1c057e

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

csrf.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package csrf
55

66
import (
77
"crypto/subtle"
8-
"github.com/golang/glog"
98
"github.com/robfig/revel"
109
"net/url"
1110
"regexp"
@@ -36,13 +35,13 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
3635
realToken = generateNewToken(c)
3736
} else {
3837
realToken = tokenCookie
39-
glog.V(2).Infof("REVEL-CSRF: Session's token: '%s'", realToken)
38+
revel.TRACE.Printf("REVEL-CSRF: Session's token: '%s'\n", realToken)
4039
if len(realToken) != lengthCSRFToken {
4140
// Wrong length; token has either been tampered with, we're migrating
4241
// onto a new algorithm for generating tokens, or a new session has
4342
// been initiated. In any case, a new token is generated and the
4443
// error will be detected later.
45-
glog.V(2).Infof("REVEL_CSRF: Bad token length: found %d, expected %d",
44+
revel.TRACE.Printf("REVEL_CSRF: Bad token length: found %d, expected %d",
4645
len(realToken), lengthCSRFToken)
4746
realToken = generateNewToken(c)
4847
}
@@ -53,7 +52,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
5352
// See http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods
5453
unsafeMethod := !safeMethods.MatchString(r.Method)
5554
if unsafeMethod && !IsExempted(r.URL.Path) {
56-
glog.V(2).Infof("REVEL-CSRF: Processing unsafe '%s' method...", r.Method)
55+
revel.TRACE.Printf("REVEL-CSRF: Processing unsafe '%s' method...", r.Method)
5756
if r.URL.Scheme == "https" {
5857
// See [OWASP]; Checking the Referer Header.
5958
referer, err := url.Parse(r.Header.Get("Referer"))
@@ -81,7 +80,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
8180
// Get CSRF token from form.
8281
sentToken = c.Params.Get(fieldName)
8382
}
84-
glog.V(2).Infof("REVEL-CSRF: Token received from client: '%s'", sentToken)
83+
revel.TRACE.Printf("REVEL-CSRF: Token received from client: '%s'", sentToken)
8584

8685
if len(sentToken) != len(realToken) {
8786
c.Result = c.Forbidden(errBadToken)
@@ -92,7 +91,7 @@ var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
9291
c.Result = c.Forbidden(errBadToken)
9392
return
9493
}
95-
glog.V(2).Infoln("REVEL-CSRF: Token successfully checked.")
94+
revel.TRACE.Println("REVEL-CSRF: Token successfully checked.")
9695
}
9796

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

exemptions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ package csrf
55

66
import (
77
"fmt"
8-
"github.com/golang/glog"
98
pathPackage "path"
109
"sync"
10+
11+
"github.com/robfig/revel"
1112
)
1213

1314
// I'm not cetain that we need a mutex because exempted routes are generally
@@ -34,7 +35,7 @@ func IsExempted(path string) bool {
3435
_, found := exemptionsFullPath.list[path]
3536
exemptionsFullPath.RUnlock()
3637
if found {
37-
glog.V(2).Infof("REVEL-CSRF: Ignoring exempted route '%s'...", path)
38+
revel.TRACE.Printf("REVEL-CSRF: Ignoring exempted route '%s'...\n", path)
3839
return true
3940
}
4041

@@ -47,7 +48,7 @@ func IsExempted(path string) bool {
4748
panic(fmt.Sprintf("REVEL-CSRF: malformed glob pattern: %#v", err))
4849
}
4950
if found {
50-
glog.V(2).Infof("REVEL-CSRF: Ignoring exempted route '%s'...", path)
51+
revel.TRACE.Printf("REVEL-CSRF: Ignoring exempted route '%s'...", path)
5152
return true
5253
}
5354
}
@@ -56,7 +57,7 @@ func IsExempted(path string) bool {
5657

5758
// ExemptedFullPath exempts one exact path from CSRF checks.
5859
func ExemptedFullPath(path string) {
59-
glog.V(2).Infof("REVEL-CSRF: Adding exemption '%s'...", path)
60+
revel.TRACE.Printf("REVEL-CSRF: Adding exemption '%s'...\n", path)
6061
exemptionsFullPath.Lock()
6162
exemptionsFullPath.list[path] = struct{}{}
6263
exemptionsFullPath.Unlock()
@@ -72,7 +73,7 @@ func ExemptedFullPaths(paths ...string) {
7273
// ExemptedGlob exempts one path from CSRF checks using pattern matching.
7374
// See http://golang.org/pkg/path/#Match
7475
func ExemptedGlob(path string) {
75-
glog.V(2).Infof("REVEL-CSRF: Adding exemption GLOB '%s'...", path)
76+
revel.TRACE.Printf("REVEL-CSRF: Adding exemption GLOB '%s'...\n", path)
7677
exemptionsGlobs.Lock()
7778
exemptionsGlobs.list = append(exemptionsGlobs.list, path)
7879
exemptionsGlobs.Unlock()

tokengen.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/rand"
66
"encoding/base64"
77
"fmt"
8-
"github.com/golang/glog"
98
"github.com/robfig/revel"
109
"io"
1110
)
@@ -24,7 +23,7 @@ func generateNewToken(c *revel.Controller) (token string) {
2423
// Due to base64 encoding, CSRF tokens cannot have null bytes and therefore
2524
// can safely be used as session values in Revel.
2625
token = base64.StdEncoding.EncodeToString(bytes)
27-
glog.V(2).Infof("REVEL-CSRF: Generated new Token: '%s'", token)
26+
revel.TRACE.Printf("REVEL-CSRF: Generated new Token: '%s'\n", token)
2827
c.Session[cookieName] = token
2928
return
3029
}

0 commit comments

Comments
 (0)