Skip to content

Commit a1b0f66

Browse files
author
thisisaaronland
committed
update to reflect memguard related changes to go-http-cookie
1 parent d7729b4 commit a1b0f66

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ module github.com/sfomuseum/go-http-oauth2
33
go 1.12
44

55
require (
6-
github.com/aaronland/go-http-cookie v0.3.0
6+
github.com/aaronland/go-http-cookie v0.3.1
77
github.com/aaronland/go-http-crumb v0.1.0
88
github.com/aaronland/go-http-sanitize v0.0.4
99
github.com/aaronland/go-string v0.1.2
10+
github.com/awnumar/memguard v0.22.2
1011
github.com/sfomuseum/go-flags v0.1.0
1112
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
1213
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/aaronland/go-http-cookie v0.2.0 h1:DXJ4jJ7lRwOGP1rUn68K3n24r6dGOO/3Pd
77
github.com/aaronland/go-http-cookie v0.2.0/go.mod h1:fGP679ZUdWY+ISTL26BcHG6q7T8GT7rklpZJ/eHC7yo=
88
github.com/aaronland/go-http-cookie v0.3.0 h1:mB4CZ+KAddyucQ/nURv7RSuGl0AJZqZJT9cgtE86vd4=
99
github.com/aaronland/go-http-cookie v0.3.0/go.mod h1:x8CK9UF7W+Audtu+CyBKjVfGEmysK4wr8+pA9WLk7iU=
10+
github.com/aaronland/go-http-cookie v0.3.1 h1:+eNNvou/5mhgJa/VbwvhlKBJT7mqpTa+V32r/nkIt9s=
11+
github.com/aaronland/go-http-cookie v0.3.1/go.mod h1:x8CK9UF7W+Audtu+CyBKjVfGEmysK4wr8+pA9WLk7iU=
1012
github.com/aaronland/go-http-crumb v0.0.5 h1:ZhBkvWUW9wsw+KYnOu0sHAeRpsfY9kj0wh7yA8qGA0M=
1113
github.com/aaronland/go-http-crumb v0.0.5/go.mod h1:tzp6zHKE/pojVXQhcS1J5x5qQkhhxOTvJS2N7S1VVuY=
1214
github.com/aaronland/go-http-crumb v0.0.6 h1:R+hGU1SdkKxLqKIuabBwXpemo7VqFaCVYg4YK13JOnw=

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# github.com/aaronland/go-http-cookie v0.3.0
1+
# github.com/aaronland/go-http-cookie v0.3.1
22
github.com/aaronland/go-http-cookie
33
# github.com/aaronland/go-http-crumb v0.1.0
44
github.com/aaronland/go-http-crumb

www/cookie.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/aaronland/go-http-cookie"
88
"github.com/aaronland/go-http-sanitize"
99
"github.com/sfomuseum/go-http-oauth2"
10+
"github.com/awnumar/memguard"
1011
goog_oauth2 "golang.org/x/oauth2"
1112
_ "log"
1213
"net/http"
@@ -173,12 +174,11 @@ func OAuth2AccessTokenCookieHandler(opts *oauth2.Options) (http.Handler, error)
173174
return
174175
}
175176

176-
str_token := string(enc_token)
177+
buf_token := memguard.NewBufferFromBytes(enc_token)
177178

178179
// https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1
179180

180181
http_cookie := &http.Cookie{
181-
Value: str_token,
182182
SameSite: http.SameSiteLaxMode,
183183
// SameSite: http.SameSiteStrictMode, // I can not make this work... (20200416/thisisaaronland)
184184
Expires: tok.Expiry,
@@ -191,7 +191,7 @@ func OAuth2AccessTokenCookieHandler(opts *oauth2.Options) (http.Handler, error)
191191
http_cookie.Secure = true
192192
}
193193

194-
err = ck.SetCookie(rsp, http_cookie)
194+
err = ck.SetWithCookie(rsp, buf_token, http_cookie)
195195

196196
if err != nil {
197197
http.Error(rsp, err.Error(), http.StatusInternalServerError)
@@ -282,19 +282,19 @@ func GetOAuth2TokenFromCookie(opts *oauth2.Options, req *http.Request) (*goog_oa
282282
return nil, err
283283
}
284284

285-
str_token, err := ck.Get(req)
285+
buf_token, err := ck.Get(req)
286286

287287
if err != nil && err != http.ErrNoCookie {
288288
return nil, err
289289
}
290290

291-
if str_token == "" {
291+
if buf_token == nil {
292292
return nil, http.ErrNoCookie
293293
}
294294

295295
var token *goog_oauth2.Token
296296

297-
err = json.Unmarshal([]byte(str_token), &token)
297+
err = json.Unmarshal(buf_token.Bytes(), &token)
298298

299299
if err != nil {
300300
return nil, err

0 commit comments

Comments
 (0)