Visitar URL original
Fix GPG key retrieval through HTTPS proxies by Torbjorn-Svensson · Pull Request #265 · SonarSource/sonarqube-scan-action · GitHub
Skip to content

Fix GPG key retrieval through HTTPS proxies - #265

Merged
Seppli11 merged 1 commit into
SonarSource:masterfrom
Torbjorn-Svensson:pr/fix-workaround-gpg-keyserver-bug
Sep 28, 2026
Merged

Seppli11 merged 1 commit into
SonarSource:masterfrom
Torbjorn-Svensson:pr/fix-workaround-gpg-keyserver-bug

Conversation

@Torbjorn-Svensson

@Torbjorn-Svensson Torbjorn-Svensson commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

@Torbjorn-Svensson
Torbjorn-Svensson requested a review from a team as a code owner September 14, 2026 10:07
Comment thread src/main/gpg-verification.js Resolved
Comment thread src/main/gpg-verification.js Resolved
Comment thread src/main/gpg-verification.js Resolved
@Torbjorn-Svensson
Torbjorn-Svensson force-pushed the pr/fix-workaround-gpg-keyserver-bug branch from 4240d4c to 544a06a Compare September 15, 2026 08:04
Comment thread src/main/gpg-verification.js Resolved
@Torbjorn-Svensson
Torbjorn-Svensson force-pushed the pr/fix-workaround-gpg-keyserver-bug branch from 544a06a to da73945 Compare September 15, 2026 08:11
When HTTPS_PROXY or https_proxy is set, download the public key over HTTPS,
validate that exactly one primary key matches the requested fingerprint, and
import it from memory. Retry retrieval using the fallback keyserver when the
primary attempt fails.

Keep native GPG key retrieval when no HTTPS proxy is configured and update
the tests and generated distribution files.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
@Torbjorn-Svensson
Torbjorn-Svensson force-pushed the pr/fix-workaround-gpg-keyserver-bug branch from da73945 to cbaaa06 Compare September 15, 2026 08:34
@sonarqubecloud

Copy link
Copy Markdown

@gitar-bot

gitar-bot Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 5 closed / 5 findings

Fixes GPG key retrieval through HTTPS proxies by working around a keyserver bug. The proxy path imports, fallback keyserver, dist/ regeneration, proxy test assertions, and subkey-skipping parser branch issues have all been resolved.

✅ 5 closed
✅ Security: Proxy path imports any key, dropping fingerprint binding

📄 src/main/gpg-verification.js:176-185 📄 src/main/gpg-verification.js:249-263
On the non-proxy path gpg --recv-keys <fingerprint> is fingerprint-bound: gpg's keyserver retrieval screener rejects any received key whose fingerprint does not match the one requested. The new proxy path instead does a plain gpg --import public-key.asc on whatever the HTTP response contained, and runGpgVerify only runs --verify against the keyring without checking which key produced the signature — so any key present in the response becomes trusted for verification. Concrete trigger: a TLS-terminating corporate proxy (the exact environment this PR targets, where a custom CA is installed on the runner) or a compromised/spoofed keyserver returns an attacker key; a tampered scanner ZIP signed with that key then passes verification. Validate the downloaded file before trusting it, e.g. list it with --import-options show-only --with-colons and abort unless it contains exactly one primary key whose fingerprint equals keyFingerprint.

✅ Bug: Fallback keyserver breaks: download destination already exists

📄 src/main/gpg-verification.js:178-185 📄 src/main/gpg-verification.js:213-227
tc.downloadTool throws Destination file path <dest> already exists when the destination file is present (see the bundled implementation at dist/index.js:3499-3502). Both tryImportKey calls in importSonarSourceKey use the same fixed destination <gpgHome>/public-key.asc, so whenever the primary attempt downloads successfully but fails afterwards (proxy/captive-portal returns HTTP 200 with a non-key body, or gpg --import exits non-zero), the fallback to keys.openpgp.org never runs its download and dies with that misleading message — turning a recoverable failure into a hard failure. Use a per-attempt destination (or remove an existing file first).

✅ Quality: dist/ not regenerated, so the fix does not take effect

📄 src/main/gpg-verification.js:23 📄 src/main/gpg-verification.js:176-185
The action runs the bundled dist/ output, not src/, and .github/workflows/unit-tests.yml verifies dist/ is in sync with src/. As submitted this PR changes only src/main/gpg-verification.js, so the proxy workaround has no runtime effect and the dist freshness check will fail. Run the bundling step and commit the regenerated dist/ before merge.

✅ Quality: Proxy tests now assert on a flag the code never emits

📄 src/main/tests/gpg-verification-mocked.test.js:718-732 📄 src/main/gpg-verification.js:152-154
The retained HTTP_PROXY tests still assert !args.includes("--keyserver-options"), but this PR removes the only site that ever passed --keyserver-options, so those assertions now pass vacuously and no longer prove the proxy is unused. At the same time the deleted "prefer HTTPS_PROXY over https_proxy" test leaves getProxyFromEnv's still-live precedence logic uncovered. Assert the observable behaviour instead: --recv-keys present and downloadTool not called for the HTTP-only cases, and re-add a precedence test asserting the HTTPS_PROXY value wins (e.g. via the downloaded-key path).

✅ Quality: Subkey-skipping branch of fingerprint parser is untested

📄 src/main/gpg-verification.js:206-220 📄 src/main/tests/gpg-verification-mocked.test.js:664 📄 src/main/tests/gpg-verification-mocked.test.js:716 📄 src/main/tests/gpg-verification-mocked.test.js:759 📄 src/main/tests/gpg-verification-mocked.test.js:795-798 📄 src/main/tests/gpg-verification-mocked.test.js:837
Every mocked --with-colons fixture in the new tests emits only pub/fpr pairs, so the case "sub" branch and the readingPrimaryKey guard — the only reason the parser is more than "take the last fpr" — are never executed. Real gpg --import-options show-only --with-colons output for the SonarSource key is pub / fpr / uid / sub / fpr, so a regression that let a subkey fingerprint overwrite the primary one (or that counted subkey fprs) would pass the whole suite while rejecting or mis-accepting every proxied run in production. Add a fixture that includes uid and sub records after the primary fpr, plus a negative case where only a subkey fingerprint matches keyFingerprint.

Review coverage

🧪 Functional validation No results

📋 Rules No rules evaluated

🤖 Auto-approval Not enabled · Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@Seppli11 Seppli11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for your contribution @Torbjorn-Svensson

The code itself looks good. However, the new code does worry me a bit. To me, it looks a bit brittle given that the new code calls gpg and then parses the output.
Would you be able to add two IT cases to the qa-main.yml file that test both the happy path and the case where the key is rejected?

About the GPG bug report, given that there hasn't really been an official respond yet, I'm assuming an upstream fix might take a while.

@Torbjorn-Svensson

Copy link
Copy Markdown
Contributor Author

Thanks a lot for your contribution @Torbjorn-Svensson

The code itself looks good. However, the new code does worry me a bit. To me, it looks a bit brittle given that the new code calls gpg and then parses the output. Would you be able to add two IT cases to the qa-main.yml file that test both the happy path and the case where the key is rejected?

I'm not exactly sure I understand what you want.
Do you want me to "wrap" gpg command to output a certain response or do you want to run the real gpg binary?

  • If you want it to fake the data, then I think it's the same as the tests that I've already included in the PR.
  • If you want to run the real binary, then I would need to be able to control the server side, meaning that I would have to be able to configure that localhost should be used for the key server and have a webserver serving a known key on the URL. Doing so would be possible, but it would mean that the feature to allow external configuration of the keyserver would need to be implemented first. Is this what you want?

Today, there is also no test in the qa-main.yml for validating the signature of the binaries.

About the GPG bug report, given that there hasn't really been an official respond yet, I'm assuming an upstream fix might take a while.

Yes, it's likely going to take years before this is available to your users.

@Seppli11

Copy link
Copy Markdown
Contributor

Hey @Torbjorn-Svensson,
Sorry for the late response.

I was thinking of a full end-to-end test. While it is not the prettiest solution, using keyserver.ubuntu.com seems okey. But on second thought, it will be very hard for you to implement this since you won't be able to run GitHub actions on this repository.

I did a test of this change and it worked. So I'm fine with merging it

@Seppli11
Seppli11 merged commit 6abe0a7 into SonarSource:master Sep 28, 2026
144 of 193 checks passed
luketainton pushed a commit to luketainton/actions_gha-workflows that referenced this pull request Sep 30, 2026
…0 (#125)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [SonarSource/sonarqube-scan-action](https://github.com/SonarSource/sonarqube-scan-action) | action | minor | `v8.2.2` → `v8.3.0` |

---

### Release Notes

<details>
<summary>SonarSource/sonarqube-scan-action (SonarSource/sonarqube-scan-action)</summary>

### [`v8.3.0`](https://github.com/SonarSource/sonarqube-scan-action/releases/tag/v8.3.0)

[Compare Source](SonarSource/sonarqube-scan-action@v8.2.2...v8.3.0)

#### What's Changed

- Fix GPG key retrieval through HTTPS proxies by [@&#8203;Torbjorn-Svensson](https://github.com/Torbjorn-Svensson) in [#&#8203;265](SonarSource/sonarqube-scan-action#265)
- Configure Renovate by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;267](SonarSource/sonarqube-scan-action#267)
- SQSCANGHA-168 Update actions/cache action to v5.1.0 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;269](SonarSource/sonarqube-scan-action#269)
- Update npm dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;268](SonarSource/sonarqube-scan-action#268)
- Update dependency [@&#8203;actions/exec](https://github.com/actions/exec) to v3 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;270](SonarSource/sonarqube-scan-action#270)
- Update GitHub Actions dependencies (major) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;271](SonarSource/sonarqube-scan-action#271)

#### New Contributors

- [@&#8203;Torbjorn-Svensson](https://github.com/Torbjorn-Svensson) made their first contribution in [#&#8203;265](SonarSource/sonarqube-scan-action#265)
- [@&#8203;renovate](https://github.com/renovate)\[bot] made their first contribution in [#&#8203;267](SonarSource/sonarqube-scan-action#267)

**Full Changelog**: <SonarSource/sonarqube-scan-action@v8.2.2...v8.3.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMjQuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjEyNC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tainton.uk/actions/gha-workflows/pulls/125
Co-authored-by: renovate[bot] <renovate-bot@git.tainton.uk>
luketainton pushed a commit to luketainton/repos_epage-go that referenced this pull request Sep 30, 2026
…(#19)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [SonarSource/sonarqube-scan-action](https://github.com/SonarSource/sonarqube-scan-action) | action | minor | `v8.2` → `v8.3` |

---

### Release Notes

<details>
<summary>SonarSource/sonarqube-scan-action (SonarSource/sonarqube-scan-action)</summary>

### [`v8.3.0`](https://github.com/SonarSource/sonarqube-scan-action/releases/tag/v8.3.0)

[Compare Source](SonarSource/sonarqube-scan-action@v8.2.2...v8.3.0)

#### What's Changed

- Fix GPG key retrieval through HTTPS proxies by [@&#8203;Torbjorn-Svensson](https://github.com/Torbjorn-Svensson) in [#&#8203;265](SonarSource/sonarqube-scan-action#265)
- Configure Renovate by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;267](SonarSource/sonarqube-scan-action#267)
- SQSCANGHA-168 Update actions/cache action to v5.1.0 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;269](SonarSource/sonarqube-scan-action#269)
- Update npm dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;268](SonarSource/sonarqube-scan-action#268)
- Update dependency [@&#8203;actions/exec](https://github.com/actions/exec) to v3 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;270](SonarSource/sonarqube-scan-action#270)
- Update GitHub Actions dependencies (major) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;271](SonarSource/sonarqube-scan-action#271)

#### New Contributors

- [@&#8203;Torbjorn-Svensson](https://github.com/Torbjorn-Svensson) made their first contribution in [#&#8203;265](SonarSource/sonarqube-scan-action#265)
- [@&#8203;renovate](https://github.com/renovate)\[bot] made their first contribution in [#&#8203;267](SonarSource/sonarqube-scan-action#267)

**Full Changelog**: <SonarSource/sonarqube-scan-action@v8.2.2...v8.3.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMjQuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjEyNC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tainton.uk/repos/epage-go/pulls/19
Co-authored-by: renovate[bot] <renovate-bot@git.tainton.uk>
centosinfra-prod-github-app Bot pushed a commit to ansible-collections/amazon.aws that referenced this pull request Oct 8, 2026
…ates (#3148)

Bumps the github-actions group with 2 updates in the / directory: dawidd6/action-download-artifact and SonarSource/sonarqube-scan-action.
Updates dawidd6/action-download-artifact from 25 to 27

Release notes
Sourced from dawidd6/action-download-artifact's releases.

v27
What's Changed

fix: merge unfiltered runs into filtered run search by @​dawidd6 in dawidd6/action-download-artifact#432

Full Changelog: dawidd6/action-download-artifact@v26...v27
v26
Full Changelog: dawidd6/action-download-artifact@v25...v26



Commits

eab87c9 fix: merge unfiltered runs into filtered run search (#432)
27e4ae6 feat: log skipped workflow runs in debug mode
See full diff in compare view



Updates SonarSource/sonarqube-scan-action from 8.2.2 to 8.3.0

Release notes
Sourced from SonarSource/sonarqube-scan-action's releases.

v8.3.0
What's Changed

Fix GPG key retrieval through HTTPS proxies by @​Torbjorn-Svensson in SonarSource/sonarqube-scan-action#265
Configure Renovate by @​renovate[bot] in SonarSource/sonarqube-scan-action#267
SQSCANGHA-168 Update actions/cache action to v5.1.0 by @​renovate[bot] in SonarSource/sonarqube-scan-action#269
Update npm dependencies by @​renovate[bot] in SonarSource/sonarqube-scan-action#268
Update dependency @​actions/exec to v3 by @​renovate[bot] in SonarSource/sonarqube-scan-action#270
Update GitHub Actions dependencies (major) by @​renovate[bot] in SonarSource/sonarqube-scan-action#271

New Contributors

@​Torbjorn-Svensson made their first contribution in SonarSource/sonarqube-scan-action#265
@​renovate[bot] made their first contribution in SonarSource/sonarqube-scan-action#267

Full Changelog: SonarSource/sonarqube-scan-action@v8.2.2...v8.3.0



Commits

d209202 Update GitHub Actions dependencies (major) (#271)
0333cb3 Update dependency @​actions/exec to v3 (#270)
da4450e Update npm dependencies (#268)
c5094d1 SQSCANGHA-168 Update actions/cache action to v5.1.0 (#269)
001613f SQSCANGHA-162 Configure Renovate (#267)
6abe0a7 SQSCANGHA-165 Fix GPG key retrieval through HTTPS proxies (#265)
See full diff in compare view



Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore <dependency name> major version will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself)
@dependabot ignore <dependency name> minor version will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself)
@dependabot ignore <dependency name> will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself)
@dependabot unignore <dependency name> will remove all of the ignore conditions of the specified dependency
@dependabot unignore <dependency name> <ignore condition> will remove the ignore condition of the specified dependency and ignore conditions

Reviewed-by: Don Naro <dnaro@redhat.com>
Reviewed-by: Bikouo Aubin
@Torbjorn-Svensson
Torbjorn-Svensson deleted the pr/fix-workaround-gpg-keyserver-bug branch October 15, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants