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

Fix header check in secret scanning #17275

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/unit/integration/secrets/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import pretend
import pytest

from webob.headers import EnvironHeaders

from warehouse.integrations.secrets import config, utils, views


Expand All @@ -34,6 +36,18 @@ class TestDiscloseToken:
"https://api.github.com/meta/public_keys/token_scanning",
"token",
),
(
config._github_origin,
{ # Test for case-insensitivity on header names
"GitHub-Public-Key-Identifier": "foo",
"GitHub-Public-Key-Signature": "bar",
},
{
"github.token": "token",
},
"https://api.github.com/meta/public_keys/token_scanning",
"token",
),
(
config._depsdev_origin,
{
Expand All @@ -57,7 +71,9 @@ def test_disclose_token(
api_url,
api_token,
):
pyramid_request.headers = headers
pyramid_request.headers = EnvironHeaders({})
for k, v in headers.items():
pyramid_request.headers[k] = v
pyramid_request.body = "[1, 2, 3]"
pyramid_request.json_body = [1, 2, 3]
pyramid_request.registry.settings = settings
Expand Down
2 changes: 1 addition & 1 deletion warehouse/integrations/secrets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def _detect_origin(request):
for origin in config.origins:
if origin.headers.issubset(request.headers.keys()):
if all([k in request.headers for k in origin.headers]):
return origin


Expand Down