Skip to content
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
7 changes: 5 additions & 2 deletions src/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { runLicenseCheck } from "./license/index.js";
import { generateImageSBOM, parseImageRef } from "./oci_image/utils.js";
import { addProxyAgent, getCustom, getTokenHeaders , TRUSTIFY_DA_OPERATION_TYPE_HEADER, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER } from "./tools.js";

/** Media type for CycloneDX JSON batch payloads (batch-analysis API). */
export const CYCLONEDX_JSON_MEDIA_TYPE = 'application/vnd.cyclonedx+json'

export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken }

/**
Expand Down Expand Up @@ -155,7 +158,7 @@ async function requestStackBatch(sbomByPurl, url, html = false, opts = {}) {
method: 'POST',
headers: {
'Accept': html ? 'text/html' : 'application/json',
'Content-Type': 'application/json',
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
...getTokenHeaders(opts)
},
body: JSON.stringify(sbomByPurl)
Expand Down Expand Up @@ -208,7 +211,7 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
method: 'POST',
headers: {
'Accept': html ? 'text/html' : 'application/json',
'Content-Type': 'application/vnd.cyclonedx+json',
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
...getTokenHeaders(opts)
},
body: JSON.stringify(imageSboms),
Comment on lines 211 to 217
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Proxy config ignored 🐞 Bug ⛯ Reliability

requestImages() sends the batch-analysis request via fetch() without addProxyAgent(...), so
TRUSTIFY_DA_PROXY_URL is ignored for image analysis requests and can fail in proxied environments.
Agent Prompt
## Issue description
`requestImages()` bypasses proxy configuration because it calls `fetch()` directly instead of wrapping request init with `addProxyAgent(...)`. This causes image analysis requests to ignore `TRUSTIFY_DA_PROXY_URL`.

## Issue Context
Other outbound requests in `src/analysis.js` (e.g., `requestStackBatch`) consistently wrap options via `addProxyAgent(options, opts)` so proxy settings apply.

## Fix Focus Areas
- src/analysis.js[198-218]
- src/tools.js[182-194]

## Suggested change
In `requestImages()`, build a `fetchOptions` object identical to the current inline object, wrap it with `addProxyAgent(fetchOptions, opts)`, and pass the wrapped options to `fetch(finalUrl, wrappedOptions)` (mirroring `requestStackBatch`). Ensure headers/body stay the same.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Expand Down
16 changes: 16 additions & 0 deletions test/stack_analysis_batch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import esmock from 'esmock'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

import { CYCLONEDX_JSON_MEDIA_TYPE } from '../src/analysis.js'

const BACKEND_URL = 'http://localhost:9999'
const BACKEND_OPTS = { TRUSTIFY_DA_BACKEND_URL: BACKEND_URL }

Expand Down Expand Up @@ -73,13 +75,22 @@ function makeSbom(name, version) {
}
}

function mediaTypeWithoutParameters(contentType) {
if (!contentType) {
return ''
}
return contentType.split(';')[0].trim()
}

suite('stackAnalysisBatch', () => {
let server
let capturedBody
let capturedContentType

suiteSetup(() => {
server = setupServer(
http.post(`${BACKEND_URL}/api/v5/batch-analysis`, async ({ request }) => {
capturedContentType = request.headers.get('content-type')
capturedBody = await request.json()
const report = {}
for (const purl of Object.keys(capturedBody)) {
Expand All @@ -97,6 +108,7 @@ suite('stackAnalysisBatch', () => {

setup(() => {
capturedBody = null
capturedContentType = null
})

test('discovers JS workspace packages, generates SBOMs, and sends batch request', async () => {
Expand Down Expand Up @@ -127,6 +139,7 @@ suite('stackAnalysisBatch', () => {

expect(result).to.be.an('object')
expect(capturedBody).to.be.an('object')
expect(mediaTypeWithoutParameters(capturedContentType)).to.equal(CYCLONEDX_JSON_MEDIA_TYPE)
const purls = Object.keys(capturedBody)
expect(purls).to.include('pkg:npm/app-a@1.0.0')
expect(purls).to.include('pkg:npm/app-b@2.0.0')
Expand Down Expand Up @@ -164,6 +177,7 @@ suite('stackAnalysisBatch', () => {
expect(result.metadata.ecosystem).to.equal('javascript')
expect(result.metadata.successful).to.equal(2)
expect(result.metadata.failed).to.equal(0)
expect(mediaTypeWithoutParameters(capturedContentType)).to.equal(CYCLONEDX_JSON_MEDIA_TYPE)
} finally {
cleanup()
}
Expand Down Expand Up @@ -196,6 +210,7 @@ suite('stackAnalysisBatch', () => {
expect(result.metadata.failed).to.be.at.least(1)
expect(result.metadata.errors.some(e => e.phase === 'validation')).to.be.true
expect(capturedBody).to.be.an('object')
expect(mediaTypeWithoutParameters(capturedContentType)).to.equal(CYCLONEDX_JSON_MEDIA_TYPE)
expect(Object.keys(capturedBody)).to.include('pkg:npm/good@1.0.0')
} finally {
cleanup()
Expand Down Expand Up @@ -281,6 +296,7 @@ suite('stackAnalysisBatch', () => {

expect(result).to.be.an('object')
expect(capturedBody).to.be.an('object')
expect(mediaTypeWithoutParameters(capturedContentType)).to.equal(CYCLONEDX_JSON_MEDIA_TYPE)
expect(Object.keys(capturedBody)).to.include('pkg:npm/web@1.0.0')
} finally {
cleanup()
Expand Down
Loading