Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

pranjalkole
Copy link

We could also refactor this to a validateCWTClaims function in cwt.go

Signed-off-by: Pranjal Kole <pranjal.kole7@gmail.com>
@SteveLasker
Copy link
Contributor

@veraison/go-cose-maintainers, can we get some 👀's on this?

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 19.44444% with 29 lines in your changes missing coverage. Please review.

Project coverage is 90.00%. Comparing base (92fbe95) to head (8e222cd).

Files with missing lines Patch % Lines
headers.go 19.44% 22 Missing and 7 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

Comment on lines +126 to +153
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")
}
Copy link
Contributor

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

		// ...
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants