Skip to content

fix: sanitize untrusted attributes and preserve fingerprints - #423

Open
stroland02 wants to merge 1 commit into
superloglabs:mainfrom
stroland02:fix-issue-285
Open

fix: sanitize untrusted attributes and preserve fingerprints#423
stroland02 wants to merge 1 commit into
superloglabs:mainfrom
stroland02:fix-issue-285

Conversation

@stroland02

@stroland02 stroland02 commented Jul 27, 2026

Copy link
Copy Markdown

Resolves #285.

What was causing the issue?

  1. The proxy enriches incoming traces and logs with superlog.issue_fingerprint by evaluating exception attributes.
  2. The proxy then routes the payload either to the collector or maps it directly to ClickHouse.
  3. However, the direct ClickHouse mapper (otlp-clickhouse.ts) stripped every superlog.* attribute, including the proxy's newly minted fingerprint.
  4. Similarly, the collector (infra/collector/config.yaml) stripped all superlog.* attributes from logs, thus scrubbing the log fingerprint before it ever reached the database.

The Solution

  1. Pre-Enrichment Sanitization (apps/proxy/src/ingest-fingerprints.ts): Added a highly optimized zero-allocation fast-path scanner to sanitize untrusted superlog.* attributes from the payload prior to trusted enrichment.
  2. Direct Mapper Preservation (apps/proxy/src/otlp-clickhouse.ts): Updated stripSuperlog to preserve the superlog.issue_fingerprint key.
  3. Collector Preservation (infra/collector/config.yaml): Updated the OTTL transformations to cache and restore the fingerprint before/after stripping other keys.

Summary by cubic

Sanitizes untrusted superlog.* attributes before enrichment and preserves superlog.issue_fingerprint through both the direct ClickHouse path and the collector. Fixes #285 so fingerprints persist while other superlog.* keys are stripped.

  • Bug Fixes
    • Proxy: Added sanitizeSuperlog in ingest-fingerprints.ts to drop untrusted superlog.* attrs on traces and logs before stamping fingerprints.
    • Direct mapper: Updated stripSuperlog in otlp-clickhouse.ts to keep superlog.issue_fingerprint; tests adjusted to reflect preservation.
    • Collector: Added OTTL steps to stash and restore superlog.issue_fingerprint around key stripping and remove the temp key.

Written for commit aab9e20. Summary will update on new commits.

Review in cubic

@superlog-app superlog-app Bot 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.

Observability review

  • 2 warnings

}

if (stampedCount === 0) return { body, stampedCount };
if (stampedCount === 0 && sanitizedCount === 0) return { body, stampedCount };

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.

logs · warning — Log when untrusted superlog. attributes are sanitized*

Emit an info log (with sanitizedCount and the request's resource service.name) whenever sanitizedCount > 0 so operators can detect abusive or misconfigured clients attempting to inject fingerprints. Without it, attribute stripping is completely silent and impossible to alert on or audit.

Suggested change
if (stampedCount === 0 && sanitizedCount === 0) return { body, stampedCount };
if (stampedCount === 0 && sanitizedCount === 0) return { body, stampedCount };
if (sanitizedCount > 0) {
logger.info({ sanitizedCount, signal: "traces" }, "sanitized untrusted superlog.* attributes from inbound payload");
}
return { body: Buffer.from(JSON.stringify(payload)), stampedCount };

Useful? React with 👍 / 👎.

}
}
if (!hasSuperlog) return attrs;
return attrs.filter((attr) => !(attr.key || "").startsWith("superlog."));

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.

metrics · warning — Add a counter for sanitized untrusted attribute removals

Increment a module-scope counter (e.g. superlog.proxy.sanitized_attributes_total with dimension signal: traces|logs) each time sanitizeSuperlog removes at least one key, so operators can chart injection attempt rates and alert on spikes without parsing logs.

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot 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.

2 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/proxy/src/ingest-fingerprints.ts">

<violation number="1" location="apps/proxy/src/ingest-fingerprints.ts:287">
P1: Compressed or oversized payloads bypass this sanitizer and can retain a sender-forged `superlog.issue_fingerprint` on the direct ClickHouse path. Apply sanitization after bounded decompression, or keep this key stripped when a payload was not sanitized.</violation>

<violation number="2" location="apps/proxy/src/ingest-fingerprints.ts:287">
P1: Protobuf OTLP log requests still bypass sanitization, so a sender can supply `superlog.issue_fingerprint` and have it retained by the direct ClickHouse mapper. Sanitize protobuf `/v1/logs` records before decode/mapping or add a protobuf log stamping/sanitizing path.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

return next;
}

function sanitizeSuperlog(attrs: OtlpKeyValue[]): OtlpKeyValue[] {

@cubic-dev-ai cubic-dev-ai Bot Jul 27, 2026

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.

P1: Compressed or oversized payloads bypass this sanitizer and can retain a sender-forged superlog.issue_fingerprint on the direct ClickHouse path. Apply sanitization after bounded decompression, or keep this key stripped when a payload was not sanitized.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/proxy/src/ingest-fingerprints.ts, line 287:

<comment>Compressed or oversized payloads bypass this sanitizer and can retain a sender-forged `superlog.issue_fingerprint` on the direct ClickHouse path. Apply sanitization after bounded decompression, or keep this key stripped when a payload was not sanitized.</comment>

<file context>
@@ -237,6 +284,18 @@ function setStringAttribute(attrs: OtlpKeyValue[], key: string, value: string):
   return next;
 }
 
+function sanitizeSuperlog(attrs: OtlpKeyValue[]): OtlpKeyValue[] {
+  let hasSuperlog = false;
+  for (let i = 0; i < attrs.length; i++) {
</file context>
Fix with cubic

return next;
}

function sanitizeSuperlog(attrs: OtlpKeyValue[]): OtlpKeyValue[] {

@cubic-dev-ai cubic-dev-ai Bot Jul 27, 2026

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.

P1: Protobuf OTLP log requests still bypass sanitization, so a sender can supply superlog.issue_fingerprint and have it retained by the direct ClickHouse mapper. Sanitize protobuf /v1/logs records before decode/mapping or add a protobuf log stamping/sanitizing path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/proxy/src/ingest-fingerprints.ts, line 287:

<comment>Protobuf OTLP log requests still bypass sanitization, so a sender can supply `superlog.issue_fingerprint` and have it retained by the direct ClickHouse mapper. Sanitize protobuf `/v1/logs` records before decode/mapping or add a protobuf log stamping/sanitizing path.</comment>

<file context>
@@ -237,6 +284,18 @@ function setStringAttribute(attrs: OtlpKeyValue[], key: string, value: string):
   return next;
 }
 
+function sanitizeSuperlog(attrs: OtlpKeyValue[]): OtlpKeyValue[] {
+  let hasSuperlog = false;
+  for (let i = 0; i < attrs.length; i++) {
</file context>
Fix with cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fingerprint sanitization removes the key required by issue-activity rollups

1 participant