You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+91-6
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,11 @@ Extensively unit tested and cross tested (100+ tests) for compatibility with [jo
12
12
13
13
14
14
## Status
15
-
Used in production. GA ready. Current version is 1.5.
15
+
Used in production. GA ready. Current version is 1.6.
16
16
17
17
## Important
18
+
v1.6 security tuning options
19
+
18
20
v1.5 bug fix release
19
21
20
22
v1.4 changes default behavior of inserting `typ=JWT` header if not overriden. As of 1.4 no
@@ -250,7 +252,7 @@ func main() {
250
252
//go use token
251
253
fmt.Printf("\ntoken = %v\n",token)
252
254
}
253
-
}
255
+
}
254
256
```
255
257
256
258
#### AES Key Wrap key management family of algorithms
@@ -330,7 +332,7 @@ func main() {
330
332
//go use token
331
333
fmt.Printf("\ntoken = %v\n",token)
332
334
}
333
-
}
335
+
}
334
336
```
335
337
336
338
#### PBES2 using HMAC SHA with AES Key Wrap key management family of algorithms
@@ -482,7 +484,7 @@ func main() {
482
484
//and/or use headers
483
485
fmt.Printf("\nheaders = %v\n",headers)
484
486
}
485
-
}
487
+
}
486
488
```
487
489
488
490
**RSA-OAEP-256**, **RSA-OAEP** and **RSA1_5** key management algorithms expecting `*rsa.PrivateKey` private key of corresponding length:
@@ -522,7 +524,7 @@ func main() {
522
524
//and/or use headers
523
525
fmt.Printf("\nheaders = %v\n",headers)
524
526
}
525
-
}
527
+
}
526
528
```
527
529
528
530
**PBES2-HS256+A128KW, PBES2-HS384+A192KW, PBES2-HS512+A256KW** key management algorithms expects `string` passpharase as a key
@@ -679,6 +681,8 @@ func main() {
679
681
}
680
682
```
681
683
684
+
Two phase validation can be used for implementing additional things like strict `alg` or `enc` validation, see [Customizing library for security](#customizing-library-for-security) for more information.
685
+
682
686
### Working with binary payload
683
687
In addition to work with string payloads (typical use-case) `jose2go` supports
684
688
encoding and decoding of raw binary data. `jose.DecodeBytes`, `jose.SignBytes`
@@ -776,7 +780,7 @@ func main() {
776
780
//go use token
777
781
fmt.Printf("\ntoken = %v\n",token)
778
782
}
779
-
}
783
+
}
780
784
```
781
785
### Dealing with keys
782
786
**jose2go** provides several helper methods to simplify loading & importing of elliptic and rsa keys. Import `jose2go/keys/rsa` or `jose2go/keys/ecc` respectively:
@@ -925,7 +929,88 @@ func main() {
925
929
### More examples
926
930
Checkout `jose_test.go` for more examples.
927
931
932
+
## Customizing library for security
933
+
In response to ever increasing attacks on various JWT implementations, `jose2go` as of version v1.6 introduced number of additional security controls to limit potential attack surface on services and projects using the library.
934
+
935
+
### Deregister algorithm implementations
936
+
One can use following methods to deregister any signing, encryption, key management or compression algorithms from runtime suite, that is considered unsafe or simply not expected by service.
937
+
938
+
-`func DeregisterJwa(alg string) JwaAlgorithm`
939
+
-`func DeregisterJwe(alg string) JweEncryption`
940
+
-`func DeregisterJws(alg string) JwsAlgorithm`
941
+
-`func DeregisterJwc(alg string) JwcAlgorithm`
942
+
943
+
All of them expecting alg name matching `jose` constants and returns implementation that have been deregistered.
944
+
945
+
### Strict validation
946
+
Sometimes it is desirable to verify that `alg` or `enc` values are matching expected before attempting to decode actual payload.
947
+
`jose2go` provides helper matchers to be used within [Two-phase validation](#two-phase-validation) precheck:
948
+
949
+
-`jose.Alg(key, alg)` - to match alg header
950
+
-`jose.Enc(key, alg)` - to match alg and enc headers
As it quite easy to abuse PBES2 family of algorithms via forging header with extra large p2c values, jose-jwt library introduced iteration count limits in v1.6 to reduce runtime exposure.
966
+
967
+
By default, maxIterations is set according to [OWASP PBKDF2](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2) Recomendations:
968
+
969
+
```
970
+
PBES2-HS256+A128KW: 1300000
971
+
PBES2-HS384+A192KW: 950000
972
+
PBES2-HS512+A256KW: 600000
973
+
```
974
+
975
+
, while minIterations kept at 0 for backward compatibility.
976
+
977
+
If it is desired to implement different limits, register new implementation with new parameters:
In case you can't upgrade to latest version, but would like to have protections against PBES2 abuse, it is recommended to stick with [Two-phase validation](#two-phase-validation) precheck before decoding:
0 commit comments