Skip to content

headers: validate CWT claims #210

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

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

@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 3.63636% with 53 lines in your changes missing coverage. Please review.

Project coverage is 89.18%. Comparing base (eb9cdec) to head (c88a9da).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
headers.go 3.63% 53 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
- Coverage   91.12%   89.18%   -1.95%     
==========================================
  Files          12       12              
  Lines        2006     2053      +47     
==========================================
+ Hits         1828     1831       +3     
- Misses        122      168      +46     
+ Partials       56       54       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

@shizhMSFT, @qmuntal, @thomas-fossati can you PTAL?

Comment on lines +118 to +129
for name, _ := range claims {
switch name {
case 1:
iss, hasIss := claims[name]
if hasIss && !canTstr(iss) {
return claims, errors.New("cwt claim: iss: require tstr")
}
case 2:
sub, hasSub := claims[name]
if hasSub && !canTstr(sub) {
return claims, errors.New("cwt claim: sub: require tstr")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are using a for loop against claims CWTClaims where type CWTClaims map[any]any, you don't need to do something like iss, hasIss := claims[name] as hasIss is always true.

You may consider a simpler and better code style. Also, you should use constants instead of 1, 2, ..., for readability and maintainability.

Suggested change
for name, _ := range claims {
switch name {
case 1:
iss, hasIss := claims[name]
if hasIss && !canTstr(iss) {
return claims, errors.New("cwt claim: iss: require tstr")
}
case 2:
sub, hasSub := claims[name]
if hasSub && !canTstr(sub) {
return claims, errors.New("cwt claim: sub: require tstr")
}
for name, value := range claims {
switch name {
case CWTClaimIssuer:
if !canTstr(value) {
return claims, errors.New("cwt claim: iss: require tstr")
}
case CWTClaimSubject:
if !canTstr(value) {
return claims, errors.New("cwt claim: sub: require tstr")
}

So as for the rest of the code.

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.

4 participants