fix: resolve SSRF and tainted format string code scanning alerts#27
Open
fix: resolve SSRF and tainted format string code scanning alerts#27
Conversation
Co-authored-by: rocketstack-matt <66839492+rocketstack-matt@users.noreply.github.com>
Co-authored-by: rocketstack-matt <66839492+rocketstack-matt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix security vulnerabilities in project
fix: resolve SSRF and tainted format string code scanning alerts
Mar 19, 2026
There was a problem hiding this comment.
Pull request overview
Mitigates outstanding CodeQL security alerts by hardening document loading against SSRF/path traversal and removing tainted format-string usage in UI logging.
Changes:
- Add private/internal host blocking and redirect disabling to
DirectUrlDocumentLoader. - Harden
CalmHubDocumentLoaderagainst encoded/double-encoded path traversal via segment-wise decode/validate/re-encode. - Replace
console.error()template-literal first-argument usage with constant strings + separate args; add/extend unit tests.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/src/document-loader/direct-url-document-loader.ts | Adds private-host guard, reconstructs request URL, disables redirects; introduces IPv4/IPv6 private host detection helpers. |
| shared/src/document-loader/direct-url-document-loader.spec.ts | Adds parameterized tests asserting rejection of private/internal targets (IPv4/IPv6 + alternate forms). |
| shared/src/document-loader/calmhub-document-loader.ts | Adds raw-input traversal pre-check and safe path reconstruction to prevent encoded traversal/path injection. |
| shared/src/document-loader/calmhub-document-loader.spec.ts | Adds tests for percent-encoded, double-encoded traversal and malformed percent-encoding. |
| calm-hub-ui/src/service/calm-service.tsx | Moves user-controlled values out of console.error() format-string position. |
| calm-hub-ui/src/service/adr-service/adr-service.tsx | Same format-string hardening; updates rejected Error messages to include contextual values safely. |
| package-lock.json | Updates lockfile metadata for @swc/core-* optional platform packages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| } | ||
| // Reconstruct a safe URL from validated components. Disable redirects to prevent | ||
| // SSRF via 3xx responses that redirect to internal/private addresses. | ||
| const safeUrl = parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname + parsedUrl.search; |
Comment on lines
+86
to
+92
| * Returns true if the given hostname resolves to a private, loopback, link-local, | ||
| * or otherwise non-public network address. | ||
| * | ||
| * NOTE: This is a string-based check on the literal hostname value. It does NOT | ||
| * protect against DNS rebinding attacks, where a public-looking hostname later | ||
| * resolves to a private IP address. For stronger protection, consider resolving | ||
| * the hostname to IP addresses and validating each resolved address. |
Comment on lines
+57
to
+58
| // double-encoded percent signs (%25) that could hide traversal after further decoding. | ||
| if (documentId.includes('/..') || /(%2e(%2e|\.)|\.%2e|%2f|%5c|%25)/i.test(documentId)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the CodeQL alerts left open after PR finos#2239 was closed without merging, incorporating all Copilot review feedback into a clean implementation.
Description
Tainted format string (
js/tainted-format-string)Moves user-controlled values out of the
console.error()format-string position incalm-service.tsx(9 instances) andadr-service.tsx(3 instances):SSRF –
DirectUrlDocumentLoader(js/request-forgery)Adds
isPrivateHost()guard before every outbound HTTP request. Key design points vs. the closed PR:import { isIPv4 } from 'net'moved out of class body::unspecified address blocked; link-local covers the fullfe80::/10range (fe80–febf, not just fe80); ULAfc00::/7; IPv4-mapped/compatible/translated forms (URL constructor normalises dotted-decimal to hex groups before we inspect them)0x7f000001,2130706433,0177.0.0.1) handled automatically — the WHATWGURLconstructor normalises these to standard dotted-decimal beforeisIPv4()is calledmaxRedirects: 0prevents SSRF via 3xx redirect to an internal addressisISATAPrenamedisV4Translated— the condition detects::ffff:0:x/96(IPv4-translated), not ISATAPSSRF / path traversal –
CalmHubDocumentLoader(js/request-forgery)documentIdfor percent-encoded traversal sequences (%2e,%2f,%5c,%25) before the URL constructor resolves them.././embedded separators, then re-encodes — avoids the double-encoding bug present in the closed PRdecodeURIComponentwrapped in try/catch; throws a descriptive error on malformed percent-encodingType of Change
Affected Components
calm-hub-ui/)shared/)Commit Message Format ✅
fix(shared,calm-hub-ui): resolve SSRF and tainted format string code scanning alertsTesting
24 new parameterised tests cover private/internal URL rejection (IPv4 ranges, IPv6 loopback/unspecified/link-local/ULA/embedded, alternate representations,
localhost.). 4 new tests cover percent-encoded and double-encoded path traversal inCalmHubDocumentLoader. CodeQL reports 0 alerts.Checklist
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
calm.finos.org/opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development /home/REDACTED/work/architecture-as-code/architecture-as-code/node_modules/tinypool/dist/entry/process.js(dns block)download.cypress.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node dist/index.js --exec install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Created from VS Code.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.