Repository navigation
Description
tracking https://github.com/project-loupe/audit-sv2-ui/issues/45
Finding
- repo:
stratum-mining/sv2-ui(https://github.com/stratum-mining/sv2-ui.git) - reviewed revision:
b610455ac2d1e017c1df5db8787c0b2e505eabdc - title: Neutralize terminal controls in downloaded container logs
- severity:
low - location:
src/components/data/ContainerLogsPanel.tsx:19 - cwe: CWE-150
- scanner:
llm-code-review - fingerprint:
08b63554988c807fce3bb7ed6bd0cade281c21e01b34acf0fef90daac2196c50
Description
buildDownloadContent copies each container-controlled line.message byte-for-byte into the .txt download. The in-tree Docker collector decodes log buffers as UTF-8 and does not remove C0/C1 controls; JSON transport escapes and then restores those bytes, so ESC/BEL sequences reach this sink. A malicious or compromised mining container can therefore place an OSC-52 clipboard payload, ANSI screen-clearing sequence, or deceptive terminal hyperlink in the exported file. If an operator downloads logs during diagnosis and displays the file with cat or another terminal mode that interprets controls, the terminal can replace clipboard contents or falsify what the operator sees, creating a credible command-pasting or incident-response deception path. React's escaping protects the on-page text but does not sanitize the separately generated file.
Whether an unauthenticated mining peer can make the pinned, out-of-tree Stratum container log arbitrary protocol strings is uncertain because that image's source is outside this worktree; the issue still crosses the container-to-operator boundary if the service is compromised or logs attacker-controlled values. The regression test directly exercises that boundary with OSC-52 and ANSI bytes. Searches for ContainerLogsPanel terminal control escape download, logs terminal escape injection, CWE 150 log download, and container log ANSI control sequence found no match. Finding #8063 was reviewed and is the distinct unbounded-history resource-exhaustion issue.
Proof of Concept
diff --git a/src/components/data/ContainerLogsPanel.tsx b/src/components/data/ContainerLogsPanel.tsx
--- a/src/components/data/ContainerLogsPanel.tsx
+++ b/src/components/data/ContainerLogsPanel.tsx
@@ -9,7 +9,7 @@ interface ContainerLogsPanelProps {
isJdMode: boolean;
}
-function buildDownloadContent(lines: ContainerLogLine[]): string {
+export function buildDownloadContent(lines: ContainerLogLine[]): string {
return lines
.map((line) => {
const parts: string[] = [];
diff --git a/src/components/data/ContainerLogsPanel.test.ts b/src/components/data/ContainerLogsPanel.test.ts
new file mode 100644
--- /dev/null
+++ b/src/components/data/ContainerLogsPanel.test.ts
@@ -0,0 +1,24 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+
+import { buildDownloadContent } from './ContainerLogsPanel';
+import type { ContainerLogLine } from '@/types/log-diagnostics';
+
+test('downloaded logs neutralize terminal control sequences', () => {
+ const line: ContainerLogLine = {
+ container: 'translator',
+ stream: 'stderr',
+ timestamp: null,
+ message: '\u001b]52;c;Y3VybCBodHRwczovL2F0dGFja2VyLmludmFsaWQ=\u0007safe message\u001b[2J',
+ raw: '',
+ };
+
+ const content = buildDownloadContent([line]);
+
+ assert.match(content, /safe message/);
+ assert.doesNotMatch(
+ content,
+ /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/u,
+ 'a downloaded text log must not retain raw terminal control bytes',
+ );
+});
Suggested Fix
diff --git a/src/components/data/ContainerLogsPanel.tsx b/src/components/data/ContainerLogsPanel.tsx
--- a/src/components/data/ContainerLogsPanel.tsx
+++ b/src/components/data/ContainerLogsPanel.tsx
@@ -16,7 +16,8 @@ function buildDownloadContent(lines: ContainerLogLine[]): string {
if (line.timestamp) parts.push(line.timestamp);
parts.push(`[${line.container}]`);
parts.push(`[${line.stream}]`);
- parts.push(line.message);
+ // eslint-disable-next-line no-control-regex
+ parts.push(line.message.replace(/[\u0000-\u001F\u007F-\u009F]/g, ''));
return parts.join(' ');
})
.join('\n');
This finding was discovered by Project Loupe.
Activity