Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

fix: GNAP header inspection bug #321

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

DRK3
Copy link
Collaborator

@DRK3 DRK3 commented Jul 18, 2022

The GNAP middleware's Accept method checks each value in the Authorization header slice and if any of them contain a GNAP token, then the middleware handles it. However, the middleware Handle method then uses the Header.Get method, which always gets the first value from the Header slice. Thus, if a request comes in with a GNAP token in the Authorization header but in any value but the first, the handler will accept it but then fail to handle it since it will miss the token.

Also updated code that access headers to use the built-in Header methods to retrieve the values (instead of directly accessing the map) since they ensure that values are canonicalized.

Signed-off-by: Derek Trider [email protected]

@cla-bot cla-bot bot added the cla-signed label Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #321 (471fd63) into main (740622e) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   86.26%   86.30%   +0.03%     
==========================================
  Files          26       26              
  Lines        2133     2139       +6     
==========================================
+ Hits         1840     1846       +6     
  Misses        182      182              
  Partials      111      111              
Impacted Files Coverage Δ
pkg/controller/mw/authmw/gnapmw/gnap_middleware.go 100.00% <100.00%> (ø)
pkg/controller/mw/authmw/zcapmw/zcap_middleware.go 91.42% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 740622e...471fd63. Read the comment docs.

@DRK3 DRK3 force-pushed the FixGNAPMiddlewareHeaderLogic branch from ee77113 to fa0ee57 Compare July 18, 2022 17:45
@DRK3 DRK3 requested a review from aholovko July 18, 2022 17:48
The GNAP middleware's Accept method checks each value in the Authorization header slice and if any of them contain a GNAP token, then the middleware handles it. However, the middleware Handle method then uses the Header.Get method, which always gets the first value from the Header slice. Thus, if a request comes in with a GNAP token in the Authorization header but in any value but the first, the handler will accept it but then fail to handle it since it will miss the token.

Also updated code that access headers to use the built-in Header methods to retrieve the values (instead of directly accessing the map) since they ensure that values are canonicalized.

Signed-off-by: Derek Trider <[email protected]>
@DRK3 DRK3 force-pushed the FixGNAPMiddlewareHeaderLogic branch from fa0ee57 to 471fd63 Compare July 18, 2022 20:53
@DRK3 DRK3 merged commit 671f38b into trustbloc:main Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants