T09 · Insecure Skill Coding Practices
- Location
index.js:495- Finding
Prometheus Exposition Format Injection Through Unvalidated Metric Metadata
- Content
View full analysis
`${k}="${v}"`) .join(','); const labelStr = labels ? `{${labels}}` : ''; lines.push(`# TYPE ${this.prefix}_${counter.name} counter`); lines.push(`${this.prefix}_${counter.name}${labelStr} ${counter.get()}`); } // Export gauges for (const [key, gauge] of this.gauges) { const labels = Object.entries(gauge.labels) .map(([k, v]) => `${k}="${v}"`) .join(','); const labelStr = labels ? `{${labels}}` : ''; lines.push(`# TYPE ${this.prefix}_${gauge.name} gauge`); lines.push(`${this.prefix}_${gauge.name}${labelStr} ${gauge.get()}`); } ``` ### Technical Analysis The Prometheus exporter directly interpolates metric prefixes, metric names, label names, and label values into the text exposition format. It neither validates identifiers against Prometheus naming rules nor escapes special characters in label values. Prometheus label values require escaping of backslashes, double quotes, and newline characters. Metric and label names must also conform to the appropriate identifier syntax. Because the public collector APIs accept caller-provided names and labels, a value containing a quote and newline can terminate the current label value and introduce additional exposition lines. The same underlying issue affects histogram serialization at `index.js:521-528`, where names derived from caller-controlled keys and prefixes are directly inserted into output. ### Attack Path 1. An attacker gains influence over an operation name, metric name, label name, label value, or collector prefix passed to the library. 2. The attacker supplies crafted metadata containing exposition syntax, such as an embedded quote and newline. 3. The application records the ...[truncated 1091 chars]- Remediation
View remediation
