Skip to content

Commit 9eb7f58

Browse files
authored
validator: remove timestamp validation (#86)
Fixes #83
1 parent d5d6129 commit 9eb7f58

File tree

2 files changed

+0
-41
lines changed

2 files changed

+0
-41
lines changed

attributioncode/validator.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import (
66
"encoding/base64"
77
"encoding/hex"
88
"net/url"
9-
"strconv"
109
"time"
1110

12-
"github.com/mozilla-services/stubattribution/stubservice/metrics"
1311
"github.com/pkg/errors"
1412
"github.com/sirupsen/logrus"
1513
)
@@ -66,13 +64,6 @@ func (v *Validator) Validate(code, sig string) (string, error) {
6664
}
6765
}
6866

69-
if since, err := v.validateTimestamp(vals.Get("timestamp")); err != nil {
70-
if since > 0 {
71-
logEntry = logEntry.WithField("timestamp_age", since.Seconds())
72-
}
73-
logEntry.WithError(err).WithField("code_ts", vals.Get("timestamp")).Error("could not validate timestamp")
74-
return "", err
75-
}
7667
vals.Del("timestamp")
7768

7869
// all keys are valid
@@ -106,26 +97,6 @@ func (v *Validator) validateSignature(code, sig string) error {
10697
return checkMAC([]byte(v.HMACKey), []byte(code), sigBytes)
10798
}
10899

109-
func (v *Validator) validateTimestamp(ts string) (since time.Duration, err error) {
110-
if ts == "" {
111-
return since, nil
112-
}
113-
114-
tsInt, err := strconv.ParseInt(ts, 10, 64)
115-
if err != nil {
116-
return since, errors.Wrap(err, "Atoi")
117-
}
118-
119-
t := time.Unix(tsInt, 0)
120-
since = time.Since(t)
121-
metrics.Statsd.Histogram("attributioncode.validator.timestamp.age", since.Seconds())
122-
if since > v.Timeout {
123-
return since, errors.Errorf("Timestamp: %s is older than timeout: %v", t.UTC(), v.Timeout)
124-
}
125-
126-
return since, nil
127-
}
128-
129100
func checkMAC(key, msg, msgMAC []byte) error {
130101
mac := hmac.New(sha256.New, key)
131102
mac.Write(msg)

attributioncode/validator_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ import (
99
"time"
1010
)
1111

12-
func TestValidateTimeStamp(t *testing.T) {
13-
v := NewValidator("", 10*time.Minute)
14-
15-
ts := "1481143345"
16-
if since, err := v.validateTimestamp(ts); err.Error() != "Timestamp: 2016-12-07 20:42:25 +0000 UTC is older than timeout: 10m0s" {
17-
if since < 1 {
18-
t.Errorf("Expected since > 0: since: %s", since)
19-
}
20-
t.Errorf("Expected error: %s", err)
21-
}
22-
}
23-
2412
func TestValidateSignature(t *testing.T) {
2513
t.Run("static tests", func(t *testing.T) {
2614
v := NewValidator("testkey", 10*time.Minute)

0 commit comments

Comments
 (0)