-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
headers: validate CWT claims #210
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Pranjal Kole <pranjal.kole7@gmail.com>
@veraison/go-cose-maintainers, can we get some 👀's on this? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
- Coverage 92.35% 90.00% -2.36%
==========================================
Files 12 12
Lines 1622 2041 +419
==========================================
+ Hits 1498 1837 +339
- Misses 68 141 +73
- Partials 56 63 +7 ☔ View full report in Codecov by Sentry. |
aud, hasAud := claims[3] | ||
if hasAud && !canTstr(aud) { | ||
return claims, errors.New("cwt claim: aud: require tstr") | ||
} | ||
exp, hasExp := claims[4] | ||
if hasExp && !canInt(exp) && !canFloat(exp) { | ||
return claims, errors.New("cwt claim: exp: require int or float") | ||
} | ||
nbf, hasNbf := claims[5] | ||
if hasNbf && !canInt(nbf) && !canFloat(nbf) { | ||
return claims, errors.New("cwt claim: nbf: require int or float") | ||
} | ||
iat, hasIat := claims[6] | ||
if hasIat && !canInt(iat) && !canFloat(iat) { | ||
return claims, errors.New("cwt claim: iat: require int or float") | ||
} | ||
cti, hasCti := claims[7] | ||
if hasCti && !canBstr(cti) { | ||
return claims, errors.New("cwt claim: cti: require tstr") | ||
} | ||
cnf, hasCnf := claims[8] | ||
if hasCnf && !canMap(cnf) { | ||
return claims, errors.New("cwt claim: cnf: require map") | ||
} | ||
scope, hasScope := claims[9] | ||
if hasScope && !canBstr(scope) && !canTstr(scope) { | ||
return claims, errors.New("cwt claim: scope: require bstr or tstr") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a long list of if
statements, can we do something like
for name, value := range claims {
switch name {
case 1: // validate iss
case 2: // validate sub
case 3: // validate aud
// ...
}
}
We could also refactor this to a
validateCWTClaims
function incwt.go