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

Return 401 for GET request to /v2 API for public artifacts. #14768

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

reasonerjt
Copy link
Contributor

This commits make sure when the request does not carry authorization
headers, the HEAD and GET will get the same response code. This change
should be made due to #14711

Signed-off-by: Daniel Jiang jiangd@vmware.com

This commits make sure when the request does not carry authorization
headers, the HEAD and GET will get the same response code.  This change
should be made due to goharbor#14711

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #14768 (6a379d3) into master (0b9cad3) will increase coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14768      +/-   ##
==========================================
+ Coverage   66.22%   66.42%   +0.20%     
==========================================
  Files         940      937       -3     
  Lines       74477    75355     +878     
  Branches     2140     2194      +54     
==========================================
+ Hits        49320    50055     +735     
- Misses      21256    21381     +125     
- Partials     3901     3919      +18     
Flag Coverage Δ
unittests 66.42% <100.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/server/middleware/v2auth/auth.go 84.05% <100.00%> (+0.23%) ⬆️
...rtal/src/app/shared/services/RequestQueryParams.ts 0.00% <0.00%> (-100.00%) ⬇️
src/pkg/project/metadata/manager.go 3.57% <0.00%> (-64.29%) ⬇️
src/server/v2.0/handler/model/scanner.go 83.87% <0.00%> (-16.13%) ⬇️
...rc/portal/src/app/shared/services/label.service.ts 9.37% <0.00%> (-7.82%) ⬇️
src/pkg/project/metadata/dao/dao.go 60.00% <0.00%> (-6.67%) ⬇️
...rt-versions-detail/helm-chart-version.component.ts 28.83% <0.00%> (-6.05%) ⬇️
src/core/api/base.go 31.88% <0.00%> (-5.80%) ⬇️
...ook/add-webhook-form/add-webhook-form.component.ts 41.37% <0.00%> (-5.68%) ⬇️
src/common/utils/passports.go 84.61% <0.00%> (-5.13%) ⬇️
... and 41 more

@reasonerjt reasonerjt merged commit c2ab176 into goharbor:master Apr 29, 2021
@reasonerjt reasonerjt deleted the fix-14711 branch September 21, 2021 11:13
@@ -60,7 +60,8 @@ func (rc *reqChecker) check(req *http.Request) (string, error) {
return getChallenge(req, al), fmt.Errorf("unauthorized to list catalog")
}
}
if a.target == repository && req.Header.Get(authHeader) == "" && req.Method == http.MethodHead { // make sure 401 is returned for CLI HEAD, see #11271
if a.target == repository && req.Header.Get(authHeader) == "" &&
(req.Method == http.MethodHead || req.Method == http.MethodGet) { // make sure 401 is returned for CLI HEAD, see #11271
return getChallenge(req, al), fmt.Errorf("authorize header needed to send HEAD to repository")

Choose a reason for hiding this comment

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

The error message here says authorize header needed to send HEAD to repository but this is true for GET too (with this PR), right? With (req.Method == http.MethodHead || req.Method == http.MethodGet)

cc @reasonerjt

Choose a reason for hiding this comment

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

Should it says HEAD or GET ? Or maybe interpolate the req.Method in the string for accuracy? Something like this maybe? -

fmt.Errorf("authorize header needed to send %s to repository", req.Method)

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