Skip to content

Commit 05eb007

Browse files
committedDec 6, 2023
docs
1 parent e0264a2 commit 05eb007

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎README.md

+21
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ func main() {
681681
}
682682
```
683683

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+
684686
### Working with binary payload
685687
In addition to work with string payloads (typical use-case) `jose2go` supports
686688
encoding and decoding of raw binary data. `jose.DecodeBytes`, `jose.SignBytes`
@@ -940,6 +942,25 @@ One can use following methods to deregister any signing, encryption, key managem
940942

941943
All of them expecting alg name matching `jose` constants and returns implementation that have been deregistered.
942944

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
951+
952+
```Go
953+
token := "eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.NL_dfVpZkhNn4bZpCyMq5TmnXbT4yiyecuB6Kax_lV8Yq2dG8wLfea-T4UKnrjLOwxlbwLwuKzffWcnWv3LVAWfeBxhGTa0c4_0TX_wzLnsgLuU6s9M2GBkAIuSMHY6UTFumJlEeRBeiqZNrlqvmAzQ9ppJHfWWkW4stcgLCLMAZbTqvRSppC1SMxnvPXnZSWn_Fk_q3oGKWw6Nf0-j-aOhK0S0Lcr0PV69ZE4xBYM9PUS1MpMe2zF5J3Tqlc1VBcJ94fjDj1F7y8twmMT3H1PI9RozO-21R0SiXZ_a93fxhE_l_dj5drgOek7jUN9uBDjkXUwJPAyp9YPehrjyLdw"
954+
955+
key := Rsa.ReadPublic(....)
956+
957+
// we expecting 'RS256' alg here and if matching continue to decode with a key
958+
payload, header, err := jose.Decode(token, Alg(key, "RS256"))
959+
960+
// or match both alg and enc for decrypting scenarios
961+
payload, header, err := jose.Decode(token, Enc(key, "RSA-OAEP-256", "A192CBC-HS384"))
962+
```
963+
943964
### Customizing PBKDF2
944965
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.
945966

0 commit comments

Comments
 (0)
Please sign in to comment.