From a8ce34600dccaf0642ccdfbb862ef76700bb5e69 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 14:36:18 +0000 Subject: [PATCH 1/3] fix: clear code-scanning findings without changing behavior Pin the unscoped dependency ranges the npm rule flags, pin the Alpine envsubst package, and stop upgrading packages inside the image. Give the publish and EBRAINS workflows contents: read. Build chart and terms HTML outside template literals, compare transformation steps without using a stringified value as a key, and scan snake_case labels in linear time. --- .github/workflows/ebrains.yml | 3 +++ .github/workflows/publish_images.yml | 3 +++ Dockerfile | 6 ++--- package-lock.json | 16 ++++++------- package.json | 16 ++++++------- src/app/core/html.utils.spec.ts | 7 ++++++ .../charts/renderers/box-plot-chart.ts | 14 +++++------ .../charts/renderers/grouped-bar-chart.ts | 4 ++-- .../charts/renderers/k-means-chart.ts | 5 ++-- .../charts/renderers/matrix-chart.ts | 2 +- .../charts/renderers/mean-plot-chart.ts | 5 ++-- .../charts/renderers/pca-heatmap-chart.ts | 2 +- .../regression/regression-view.spec.ts | 20 +++++++++++++++- .../visualisations/result-format.ts | 23 ++++++++++++++++++- .../summary/key-figures.component.html | 11 +++++++++ .../summary/key-figures.component.ts | 14 +---------- .../pages/terms-page/terms-page.component.ts | 10 ++++---- src/app/services/experiment-studio.service.ts | 5 ++-- 18 files changed, 110 insertions(+), 56 deletions(-) create mode 100644 src/app/pages/experiment-studio/visualisations/summary/key-figures.component.html diff --git a/.github/workflows/ebrains.yml b/.github/workflows/ebrains.yml index 33da9030b..72f887632 100644 --- a/.github/workflows/ebrains.yml +++ b/.github/workflows/ebrains.yml @@ -6,6 +6,9 @@ on: tags: - "*" +permissions: + contents: read + jobs: to_ebrains: runs-on: ubuntu-latest diff --git a/.github/workflows/publish_images.yml b/.github/workflows/publish_images.yml index 458a6bbf5..5ae18b6f0 100644 --- a/.github/workflows/publish_images.yml +++ b/.github/workflows/publish_images.yml @@ -4,6 +4,9 @@ on: release: types: [published] +permissions: + contents: read + env: HARBOR_REGISTRY: docker-registry.ebrains.eu DOCKER_BUILDKIT: 1 diff --git a/Dockerfile b/Dockerfile index 761a86a09..c62b8343a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,8 +29,7 @@ RUN --mount=type=cache,target=/app/.angular/cache \ # Step 2: Use Nginx to serve the Angular app FROM nginx:alpine-slim@sha256:858c48843bd53b3f72487a2156071c63954b8e3de4882aeb11efcd92717dd261 -RUN apk upgrade --no-cache \ - && apk add --no-cache gettext-envsubst +RUN apk add --no-cache gettext-envsubst=1.0-r0 ENV PLATFORM_BACKEND_SERVER=platform-backend-service:8080 \ PLATFORM_BACKEND_CONTEXT=services \ NOTEBOOK_ENABLED=0 \ @@ -50,6 +49,7 @@ COPY --from=build /app/dist/fl-platform/browser /usr/share/nginx/html RUN chown -R nginx:nginx /usr/share/nginx/html /etc/nginx/conf.d /var/cache/nginx \ && install -o nginx -g nginx -m 0644 /dev/null /var/run/nginx.pid -USER nginx +# 101 is the nginx user created by the official alpine image. +USER 101 EXPOSE 80 CMD ["/docker-entrypoint.sh"] diff --git a/package-lock.json b/package-lock.json index cc93f2eec..2a284c96e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,15 +17,15 @@ "@angular/platform-browser": "^22.2.3", "@angular/router": "^22.2.3", "@fortawesome/fontawesome-free": "^7.3.1", - "d3": "^7.9.0", + "d3": "7.9.0", "echarts": "6.1.0", - "html2canvas": "^1.4.1", - "jspdf": "^4.2.1", - "jspdf-autotable": "^5.0.9", - "jszip": "^3.10.2", - "ngx-echarts": "^22.0.0", - "rxjs": "~7.8.2", - "tslib": "^2.8.1" + "html2canvas": "1.4.1", + "jspdf": "4.2.1", + "jspdf-autotable": "5.0.9", + "jszip": "3.10.2", + "ngx-echarts": "22.0.0", + "rxjs": "7.8.2", + "tslib": "2.8.1" }, "devDependencies": { "@angular/build": "22.2.4", diff --git a/package.json b/package.json index e76fa06da..be21e2430 100644 --- a/package.json +++ b/package.json @@ -32,15 +32,15 @@ "@angular/platform-browser": "^22.2.3", "@angular/router": "^22.2.3", "@fortawesome/fontawesome-free": "^7.3.1", - "d3": "^7.9.0", + "d3": "7.9.0", "echarts": "6.1.0", - "html2canvas": "^1.4.1", - "jspdf": "^4.2.1", - "jspdf-autotable": "^5.0.9", - "jszip": "^3.10.2", - "ngx-echarts": "^22.0.0", - "rxjs": "~7.8.2", - "tslib": "^2.8.1" + "html2canvas": "1.4.1", + "jspdf": "4.2.1", + "jspdf-autotable": "5.0.9", + "jszip": "3.10.2", + "ngx-echarts": "22.0.0", + "rxjs": "7.8.2", + "tslib": "2.8.1" }, "devDependencies": { "@angular/build": "22.2.4", diff --git a/src/app/core/html.utils.spec.ts b/src/app/core/html.utils.spec.ts index 2308e5d6b..24cb0336f 100644 --- a/src/app/core/html.utils.spec.ts +++ b/src/app/core/html.utils.spec.ts @@ -4,4 +4,11 @@ describe('escapeHtml', () => { it('escapes every HTML-significant character', () => { expect(escapeHtml(`Sex &"'x`)).toBe('Sex <b>&"'x</b>'); }); + + it('leaves ordinary chart labels and numbers unchanged', () => { + expect(escapeHtml('PC1 · 12.3%')).toBe('PC1 · 12.3%'); + expect(escapeHtml('Mean')).toBe('Mean'); + expect(escapeHtml('1.50')).toBe('1.50'); + expect(escapeHtml(null)).toBe(''); + }); }); diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/box-plot-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/box-plot-chart.ts index 5a592e79f..2f9043a43 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/box-plot-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/box-plot-chart.ts @@ -169,16 +169,16 @@ export function buildBoxPlotChart(result: any): EChartsOption[] { const showPooled = !!pooled && hasBox(pooled); const tooltipRow = (name: string, value: number | null) => - `
` + - `${name}${fmt(value)}
`; + '
' + + '' + escapeHtml(name) + '' + escapeHtml(fmt(value)) + '
'; const tooltipFor = (s: BoxStats, title: string, quartileNote = '') => - `
${escapeHtml(title)}
` + + '
' + escapeHtml(title) + '
' + tooltipRow('Max', s.max) + - tooltipRow(`Q3${quartileNote}`, s.q3) + - tooltipRow(`Median${quartileNote}`, s.median) + - tooltipRow(`Q1${quartileNote}`, s.q1) + + tooltipRow('Q3' + quartileNote, s.q3) + + tooltipRow('Median' + quartileNote, s.median) + + tooltipRow('Q1' + quartileNote, s.q1) + tooltipRow('Min', s.min) + - `
` + + '
' + tooltipRow('Mean', s.mean) + tooltipRow('Std. deviation', s.std); diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/grouped-bar-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/grouped-bar-chart.ts index 8800540a8..368f45a64 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/grouped-bar-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/grouped-bar-chart.ts @@ -107,11 +107,11 @@ export function buildGroupedBarChart( }, formatter: (params: any) => { const dataset = params[0]?.axisValue ?? ''; - let html = `${escapeHtml(dataset)}
`; + let html = '' + escapeHtml(dataset) + '
'; for (const p of params) { const pct = p.data?.value ?? p.value; const cnt = p.data?.count ?? 0; - html += `${p.marker} ${escapeHtml(p.seriesName)}: ${pct}% (n=${cnt})
`; + html += p.marker + ' ' + escapeHtml(p.seriesName) + ': ' + pct + '% (n=' + cnt + ')
'; } return html; }, diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/k-means-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/k-means-chart.ts index e9258ff89..252cf0b42 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/k-means-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/k-means-chart.ts @@ -79,8 +79,9 @@ function buildKMeans2DChart( trigger: 'item', formatter: (p: any) => { const size = sizeTexts[p.seriesIndex]; - return `${escapeHtml(names[p.seriesIndex])}
${escapeHtml(variables[0])}: ${p.value[0].toFixed(2)}
${escapeHtml(variables[1])}: ${p.value[1].toFixed(2)}` + - (size === null ? '' : `
${escapeHtml(size)} rows`); + return escapeHtml(names[p.seriesIndex]) + '
' + escapeHtml(variables[0]) + ': ' + p.value[0].toFixed(2) + '
' + + escapeHtml(variables[1]) + ': ' + p.value[1].toFixed(2) + '' + + (size === null ? '' : '
' + escapeHtml(size) + ' rows'); }, }, grid: { top: 64, left: 24, right: 32, bottom: 48, containLabel: true }, diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/matrix-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/matrix-chart.ts index 4f7e1b585..9aef02558 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/matrix-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/matrix-chart.ts @@ -84,7 +84,7 @@ export function buildMatrixChart(result: any): EChartsOption[] { const [j, i, r] = params.value; const row = rows[i]; const col = cols[j]; - const lines = [`${escapeHtml(row)} × ${escapeHtml(col)}`, `r = ${r.toFixed(3)}`]; + const lines = [escapeHtml(row) + ' × ' + escapeHtml(col), 'r = ' + r.toFixed(3) + '']; const lower = cell(ciLower, row, col); const upper = cell(ciUpper, row, col); if (lower !== null && upper !== null) lines.push(`95% CI ${lower.toFixed(3)} to ${upper.toFixed(3)}`); diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/mean-plot-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/mean-plot-chart.ts index d51f79bf9..945c477e8 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/mean-plot-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/mean-plot-chart.ts @@ -110,14 +110,15 @@ function intervalPlot(data: IntervalPoint[], labels: IntervalLabels, height = 38 if (p.seriesType === 'scatter') { const group = p.name ?? (Array.isArray(p.value) ? p.value[0] : ''); const mean = Array.isArray(p.value) ? p.value[1] : meanMap[group]; - return `${escapeHtml(group)}
${labels.value}: ${fmt(mean)}`; + return escapeHtml(group) + '
' + escapeHtml(labels.value) + ': ' + escapeHtml(fmt(mean)) + ''; } if (p.seriesType === 'custom' && Array.isArray(p.value)) { const group = p.value[4]; const low = p.value[1]; const high = p.value[2]; const mean = meanMap[group]; - return `${escapeHtml(group)}
${labels.value}: ${fmt(mean)}
${labels.intervalShort}: ${fmt(low)} – ${fmt(high)}`; + return escapeHtml(group) + '
' + escapeHtml(labels.value) + ': ' + escapeHtml(fmt(mean)) + '
' + + escapeHtml(labels.intervalShort) + ': ' + escapeHtml(fmt(low)) + ' – ' + escapeHtml(fmt(high)) + ''; } return ''; } diff --git a/src/app/pages/experiment-studio/visualisations/charts/renderers/pca-heatmap-chart.ts b/src/app/pages/experiment-studio/visualisations/charts/renderers/pca-heatmap-chart.ts index 2d8957787..38b846f8e 100644 --- a/src/app/pages/experiment-studio/visualisations/charts/renderers/pca-heatmap-chart.ts +++ b/src/app/pages/experiment-studio/visualisations/charts/renderers/pca-heatmap-chart.ts @@ -75,7 +75,7 @@ export function buildPCAHeatmapChart(result: any): EChartsOption[] { position: 'top', formatter: (params: any) => { const [component, variable, val] = params.value; - return `${componentLabels[component]}
${escapeHtml(variableNames[variable])}: ${val.toFixed(3)}`; + return escapeHtml(componentLabels[component]) + '
' + escapeHtml(variableNames[variable]) + ': ' + val.toFixed(3) + ''; }, }, grid: { diff --git a/src/app/pages/experiment-studio/visualisations/regression/regression-view.spec.ts b/src/app/pages/experiment-studio/visualisations/regression/regression-view.spec.ts index 279bb6cf3..cbeb5d005 100644 --- a/src/app/pages/experiment-studio/visualisations/regression/regression-view.spec.ts +++ b/src/app/pages/experiment-studio/visualisations/regression/regression-view.spec.ts @@ -1,4 +1,4 @@ -import { chiSquarePValue, formatPValue, formatRatio, ratioDigits } from '../result-format'; +import { chiSquarePValue, formatPValue, formatRatio, ratioDigits, readable } from '../result-format'; import { buildRegressionView } from './regression-view'; describe('result-format', () => { @@ -12,6 +12,24 @@ describe('result-format', () => { expect(chiSquarePValue(0, 3)).toBe(1); }); + it('turns raw snake_case codes into words and leaves other labels unchanged', () => { + expect(readable('stroke_territory_cohort')).toBe('Stroke territory cohort'); + expect(readable('cluster_2')).toBe('Cluster 2'); + expect(readable('kmeans_labels')).toBe('K-means labels'); + expect(readable('a_b_c')).toBe('A b c'); + expect(readable('Age')).toBe('Age'); + expect(readable('a')).toBe('a'); + expect(readable('')).toBe(''); + expect(readable('a_')).toBe('a_'); + expect(readable('_ab')).toBe('_ab'); + expect(readable('a__b')).toBe('a__b'); + expect(readable('A_b')).toBe('A_b'); + expect(readable('already labelled')).toBe('already labelled'); + const long = 'a'.repeat(20000); + expect(readable(long)).toBe(long); + expect(readable('a_' + 'b'.repeat(100) + '_c9')).toBe('A ' + 'b'.repeat(100) + ' c9'); + }); + it('formats p-values APA style and ratios at 3 significant digits', () => { expect(formatPValue(1.1102230246251565e-16)).toBe('< 0.001'); expect(formatPValue(0.8119)).toBe('0.812'); diff --git a/src/app/pages/experiment-studio/visualisations/result-format.ts b/src/app/pages/experiment-studio/visualisations/result-format.ts index a7fdd824e..a3b3ecbb4 100644 --- a/src/app/pages/experiment-studio/visualisations/result-format.ts +++ b/src/app/pages/experiment-studio/visualisations/result-format.ts @@ -115,7 +115,28 @@ export function chiSquarePValue(x: number, df: number): number { /** A raw snake_case code (a created column such as stroke_territory_cohort, or a level such as * cluster_2) reads as words; labelled names pass through unchanged. */ export function readable(code: string): string { - if (!/^[a-z0-9]+(_[a-z0-9]+)+$/.test(code)) return code; + if (!isRawSnakeCode(code)) return code; const words = code.replace(/_/g, ' ').replace(/^kmeans\b/, 'K-means'); return words.charAt(0).toUpperCase() + words.slice(1); } + +/** Same strings as `^[a-z0-9]+(_[a-z0-9]+)+$`, scanned once so a long label cannot backtrack. */ +function isRawSnakeCode(code: string): boolean { + let i = 0; + if (!isSnakeWordChar(code, i)) return false; + while (isSnakeWordChar(code, i)) i += 1; + if (i >= code.length) return false; + while (i < code.length) { + if (code.charCodeAt(i) !== 95) return false; + i += 1; + if (!isSnakeWordChar(code, i)) return false; + while (isSnakeWordChar(code, i)) i += 1; + } + return true; +} + +function isSnakeWordChar(code: string, index: number): boolean { + if (index >= code.length) return false; + const char = code.charCodeAt(index); + return (char >= 48 && char <= 57) || (char >= 97 && char <= 122); +} diff --git a/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.html b/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.html new file mode 100644 index 000000000..af003f8fa --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.html @@ -0,0 +1,11 @@ +
+ @for (figure of figures(); track figure.label) { +
+ {{ figure.label }} + {{ figure.value }} + @if (figure.note) { + {{ figure.note }} + } +
+ } +
diff --git a/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.ts b/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.ts index 652665250..d5970bc90 100644 --- a/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.ts +++ b/src/app/pages/experiment-studio/visualisations/summary/key-figures.component.ts @@ -9,19 +9,7 @@ export interface KeyFigure { /** The headline numbers of a result: one strip of label / value / note cells. */ @Component({ selector: 'app-key-figures', - template: ` -
- @for (figure of figures(); track figure.label) { -
- {{ figure.label }} - {{ figure.value }} - @if (figure.note) { - {{ figure.note }} - } -
- } -
- `, + templateUrl: './key-figures.component.html', styleUrl: './key-figures.component.css', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/src/app/pages/terms-page/terms-page.component.ts b/src/app/pages/terms-page/terms-page.component.ts index a8a3a25a2..d941b27a5 100644 --- a/src/app/pages/terms-page/terms-page.component.ts +++ b/src/app/pages/terms-page/terms-page.component.ts @@ -96,7 +96,7 @@ export class TermsPageComponent implements OnInit { return; } const text = this.formatInline(paragraph.join(' ')); - html.push(`

${text}

`); + html.push('

' + text + '

'); paragraph = []; }; @@ -142,14 +142,14 @@ export class TermsPageComponent implements OnInit { if (trimmed && next && /^=+$/.test(next)) { flushParagraph(); closeLists(); - html.push(`

${this.formatInline(trimmed)}

`); + html.push('

' + this.formatInline(trimmed) + '

'); i += 1; continue; } if (trimmed && next && /^-+$/.test(next)) { flushParagraph(); closeLists(); - html.push(`

${this.formatInline(trimmed)}

`); + html.push('

' + this.formatInline(trimmed) + '

'); i += 1; continue; } @@ -177,13 +177,13 @@ export class TermsPageComponent implements OnInit { } } closeOpenItemAtDepth(depth); - html.push(`
  • ${this.formatInline(content)}`); + html.push('
  • ' + this.formatInline(content)); listStack[depth - 1].openItem = true; continue; } if (listStack.length > 0 && /^\s{4,}/.test(line)) { - html.push(`

    ${this.formatInline(trimmed)}

    `); + html.push('

    ' + this.formatInline(trimmed) + '

    '); continue; } diff --git a/src/app/services/experiment-studio.service.ts b/src/app/services/experiment-studio.service.ts index 34705c421..82dded505 100644 --- a/src/app/services/experiment-studio.service.ts +++ b/src/app/services/experiment-studio.service.ts @@ -713,7 +713,8 @@ export class ExperimentStudioService { upsertTransformation(step: TransformationStep): boolean { const current = this.appliedTransformationsSignal(); const index = current.findIndex((existing) => existing.id === step.id); - if (index !== -1 && JSON.stringify(current[index]) === JSON.stringify(step)) return true; + const existing = index === -1 ? undefined : current[index]; + if (existing !== undefined && JSON.stringify(existing) === JSON.stringify(step)) return true; if (index !== -1 && this.outputsInUse(step.id, stepOutputNames(step)).length) return false; // Replace in place to keep request-order/dependency guarantees; append only when new. const next = index === -1 @@ -2037,7 +2038,7 @@ export class ExperimentStudioService { map((resp) => this.normalizeTransientResponse(resp)), ); } catch (error) { - console.error(`${algorithmName} report is not available:`, error); + console.error('%s report is not available:', algorithmName, error); return null; } } From adfa39e0ab369f64401b9e784da4ec99a19b0493 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 14:42:28 +0000 Subject: [PATCH 2/3] fix: base the runtime image on current Alpine 3.24.4 Dropping apk upgrade left the pinned nginx image on Alpine 3.24.3, and OSV then failed the container gate at CVSS 8. The current alpine-slim digest already ships 3.24.4, which is the release that upgrade was applying. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c62b8343a..ea272df84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,7 @@ RUN --mount=type=cache,target=/app/.angular/cache \ npm run build -- --configuration ${BUILD_CONFIGURATION} # Step 2: Use Nginx to serve the Angular app -FROM nginx:alpine-slim@sha256:858c48843bd53b3f72487a2156071c63954b8e3de4882aeb11efcd92717dd261 +FROM nginx:alpine-slim@sha256:ec64c3fd662994360b0b53a934649480a01e313986a1fcb46d4451e50939d228 RUN apk add --no-cache gettext-envsubst=1.0-r0 ENV PLATFORM_BACKEND_SERVER=platform-backend-service:8080 \ PLATFORM_BACKEND_CONTEXT=services \ From ab4a289449faa92dd8fdee971cba9a23fc93088a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 14:47:42 +0000 Subject: [PATCH 3/3] fix: keep apk upgrade so the image stays past the CVE gate The current nginx:alpine-slim digest is Alpine 3.24.4 and still fails OSV at CVSS 8 without apk upgrade. The packages that clear the gate are newer than that image, so the upgrade step has to stay. --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea272df84..52916e3e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,8 +28,9 @@ RUN --mount=type=cache,target=/app/.angular/cache \ npm run build -- --configuration ${BUILD_CONFIGURATION} # Step 2: Use Nginx to serve the Angular app -FROM nginx:alpine-slim@sha256:ec64c3fd662994360b0b53a934649480a01e313986a1fcb46d4451e50939d228 -RUN apk add --no-cache gettext-envsubst=1.0-r0 +FROM nginx:alpine-slim@sha256:858c48843bd53b3f72487a2156071c63954b8e3de4882aeb11efcd92717dd261 +RUN apk upgrade --no-cache \ + && apk add --no-cache gettext-envsubst=1.0-r0 ENV PLATFORM_BACKEND_SERVER=platform-backend-service:8080 \ PLATFORM_BACKEND_CONTEXT=services \ NOTEBOOK_ENABLED=0 \