Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(scripts): read a key inside a string literal as data in the public boundary

Alfredo Lopeza31b9bbdce62
diff --git a/scripts/tests/test-minikube-t2-contract.sh b/scripts/tests/test-minikube-t2-contract.sh
index 332d09747..c5bd2d179 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -745,6 +745,39 @@ for leaked in \
exit 1
fi
done
+# A key that is the content of a string literal ending in `=` or `:` is test
+# data, not an assignment: the quote after it closes that literal, so the text
+# up to the next quote is code. A real assignment later on the line, or a key
+# inside a literal of the other quote type, is still a credential.
+string_key="password="
+printf "const shape = { label: '%s', value: '%s' }\n" "$string_key" "$marker_value" >"$marker_repo/client.ts"
+if ! T2_PUBLIC_ROOT="$marker_repo" T2_PUBLIC_BASE_REF="$marker_base" \
+ bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh" >"$tmp/marker-boundary.out" 2>"$tmp/marker-boundary.err"; then
+ echo 'FAIL: public boundary read a key inside a string literal as a credential assignment' >&2
+ cat "$tmp/marker-boundary.err" >&2
+ exit 1
+fi
+if ! grep -Fxq 'PUBLIC_BOUNDARY_PASS' "$tmp/marker-boundary.out"; then
+ echo 'FAIL: public boundary accepted the string-literal key without reporting PUBLIC_BOUNDARY_PASS' >&2
+ exit 1
+fi
+for leaked in \
+ "const shape = { label: '$string_key', password: '$marker_value' }" \
+ "const line = \"$string_key'$marker_value'\"" \
+ "// it's $string_key'$marker_value'"; do
+ printf '%s\n' "$leaked" >"$marker_repo/client.ts"
+ if T2_PUBLIC_ROOT="$marker_repo" T2_PUBLIC_BASE_REF="$marker_base" \
+ bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh" 2>"$tmp/marker-boundary.err"; then
+ echo "FAIL: public boundary accepted a credential assignment ($leaked)" >&2
+ exit 1
+ fi
+ if ! grep -Fq -- '- client.ts: credential assignment' "$tmp/marker-boundary.err"; then
+ echo "FAIL: public boundary rejected ($leaked) for another reason" >&2
+ cat "$tmp/marker-boundary.err" >&2
+ exit 1
+ fi
+done
+echo 'PASS: public boundary reads a string-literal key as data and still rejects real assignments'
bash "$ROOT/scripts/tests/test-minikube-t2-scenarios.sh"
bash "$ROOT/scripts/tests/test-minikube-t2-proxy-runtime.sh"
bash "$ROOT/scripts/tests/test-minikube-t2-control-api-runtime.sh"
diff --git a/scripts/tests/test-minikube-t2-public-boundary.sh b/scripts/tests/test-minikube-t2-public-boundary.sh
index 771ac142f..0d1d41434 100755
--- a/scripts/tests/test-minikube-t2-public-boundary.sh
+++ b/scripts/tests/test-minikube-t2-public-boundary.sh
@@ -109,13 +109,50 @@ for line in diff.splitlines():
# under secret-named keys. The exemption applies in any file, and only when
# the whole value is the marker; a value that merely contains it is flagged.
redaction_marker = re.compile(r"(?i)\[redacted\]")
+ code_after_literal = re.compile(r"\s*[,)\]};+]")
+
+ def open_quote_before(text, end):
+ """The quote of the string literal still open at `end`, or None."""
+ open_quote = None
+ escaped = False
+ for char in text[:end]:
+ if escaped:
+ escaped = False
+ elif char == "\\":
+ escaped = True
+ elif open_quote is None and char in "\"'":
+ open_quote = char
+ elif char == open_quote:
+ open_quote = None
+ return open_quote
+
# Every match on the line is checked: an exempt first match must not hide a
# real value later on the same line.
for expression, reason in patterns:
flagged = False
- for match in re.finditer(expression, value):
+ compiled = re.compile(expression)
+ position = 0
+ while True:
+ match = compiled.search(value, position)
+ if match is None:
+ break
+ position = match.end()
if reason == "private key" and "evidence-scanner" in current:
continue
+ # A key inside a string literal ending in `=` or `:` (for example
+ # `label: 'password='`) is data: the quote after it closes that
+ # literal, and the captured text is code up to the next literal.
+ # Resume just after the closing quote, so a real assignment later
+ # on the line is still read.
+ if (
+ reason == "credential assignment"
+ and match.group(1)
+ and value[match.start(1) - 1] in "\"'"
+ and open_quote_before(value, match.start()) == value[match.start(1) - 1]
+ and code_after_literal.match(match.group(1))
+ ):
+ position = match.start(1)
+ continue
if (
reason == "credential assignment"
and match.group(1)