Commit Graph

9 Commits

Author SHA1 Message Date
ghosind
765c7e89b3 xsrftoken: create no padding base64 string by RawURLEncoding
The XSRF token generation function creates the padded base64 string by
base64.URLEncoding, then removes the padding. It is equivalent to the
base64.RawURLEncoding but with more costs.

Change-Id: I9cf5ad94e9cf3dca9bbfc1b6818ab07d41acf417
GitHub-Last-Rev: a8263b543c
GitHub-Pull-Request: golang/net#217
Reviewed-on: https://go-review.googlesource.com/c/net/+/599895
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Damien Neil <dneil@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-07-22 18:18:19 +00:00
Alexey Vilenski
59f7323070 xsrftoken: add custom timeout support for valid func
Added new function 'ValidFor' with custom token timeout support.
Function 'Valid' will use default token timeout.

Fixes golang/go#41438

Change-Id: I5cf0388aeed7ca34edcb0d3493c3e79c8ce19938
GitHub-Last-Rev: 3e3b581796
GitHub-Pull-Request: golang/net#86
Reviewed-on: https://go-review.googlesource.com/c/net/+/260317
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Filippo Valsorda <filippo@golang.org>
2020-10-08 22:28:04 +00:00
Gregory Man
aa69164e44 xsrftoken: escape colons
The current clean() replaces : with _ (colons are internally used as
separators).
This produce can produce same output for different inputs, for example
the user _foo_ can obtain valid tokens for user :foo:.

This CL replace colons with double colons instead of replacing them
with underscores.

Fixes golang/go#34308

Change-Id: I3e4148a0836e62fda1a5f0ba32b375121368afd3
Reviewed-on: https://go-review.googlesource.com/c/net/+/196457
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-23 16:28:16 +00:00
Martin Probst
0819898fb4 xsrftoken: panic for unsafe zero length keys
Passing a zero length key (or secret) gives no safety against XSRF
attacks. This is a relatively easy mistake to make, e.g. by passing
`make([]byte, 0, 1024)` to `rand.Read` instead of `make([]byte, 1024)`,
and currently fails open, silently.

This uses panic, as the API does not allow returning a structured error,
and catching this programming error is not worth breaking API
compatibility. Passing a zero length secret is also not an error
condition that API callers would handle, so there is little value in
returning a proper error.

Change-Id: Ib6457347675872188d51d2a220eee4b67900f79e
Reviewed-on: https://go-review.googlesource.com/42411
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-05-02 13:46:37 +00:00
Dmitri Shuralyov
5d997795f7 all: make copyright headers consistent with one space after period
Go policy has been single space after periods in comments for some time.

The copyright header template at:

	https://golang.org/doc/contribute.html#copyright

also uses a single space.

Make them all consistent.

This CL was generated with:

	perl -i -npe 's,^(// Copyright [0-9]+ The Go Authors\.)  (All rights reserved\.)$,$1 $2,' $(git grep -l -E '^// Copyright [0-9]+ The Go Authors\.  All rights reserved\.$')

Follows https://golang.org/cl/20111.

Change-Id: I66671dddf821f5dc027bc254e0196b3e3a2bdf3b
Reviewed-on: https://go-review.googlesource.com/32878
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-11-07 23:52:11 +00:00
Dave Day
17535f9440 xsrftoken: fix lint error in Timeout's comment.
Change-Id: I0c787256e5bae7796fb4b62253a43363b32313f2
Reviewed-on: https://go-review.googlesource.com/17790
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-12-14 00:16:29 +00:00
Dave Day
b0e2f54698 xsrftoken: add package import comment
Change-Id: I8548d0e7a9400fd7a02c761b0b339749b69fbe31
Reviewed-on: https://go-review.googlesource.com/17665
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-12-11 04:09:53 +00:00
Dave Day
da05ccad07 xsrftoken: update token implementation
This changes the behaviour of the XSRF tokens slightly:
  - timestamps are rounded up to the nearest ms (not ns)
  - the timestamp is appended to the taken after base64 encoding

Change-Id: Iaa32bd055bd76db77ef47f07b975e75c5ecaadf0
Reviewed-on: https://go-review.googlesource.com/17664
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-12-11 04:06:54 +00:00
Dave Day
f19fe602f5 xsrftoken: copy from code.google.com/p/xsrftoken
Change-Id: Idd7bad48e585289740327b00f692fde948a2eeb0
Reviewed-on: https://go-review.googlesource.com/17662
Reviewed-by: David Symonds <dsymonds@golang.org>
Run-TryBot: David Symonds <dsymonds@golang.org>
2015-12-11 03:17:20 +00:00