Spaces:
Running
Running
deploy(hf): sync szl-holdings/a11oy@648cf7c672d1b1e31260f3fe4b359dc9b364c54f derived COPY set
Browse filesReusable Dockerfile-COPY-derived deploy from szl-holdings/a11oy 648cf7c672d1b1e31260f3fe4b359dc9b364c54f.
Files: 1174 Pruned: 0
Derived from Dockerfile COPY sources (NO hand-maintained allowlist).
Signed-off-by: SZL Holdings <noreply@szlholdings.ai>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
packages/receipt-substrate/src/index.ts
CHANGED
|
@@ -499,7 +499,9 @@ const SENSITIVE_SOURCE_QUERY_KEYS = new Set([
|
|
| 499 |
"sig",
|
| 500 |
"token",
|
| 501 |
]);
|
| 502 |
-
const DIGESTED_SOURCE_QUERY_KEYS = new Set(["code"]);
|
|
|
|
|
|
|
| 503 |
const SENSITIVE_SOURCE_QUERY_PREFIXES = ["x-amz-", "x-goog-", "x-oss-"];
|
| 504 |
const TRACKING_SOURCE_QUERY_PREFIXES = ["utm_"];
|
| 505 |
const TRACKING_SOURCE_QUERY_KEYS = new Set(["fbclid", "gclid", "mc_cid", "mc_eid"]);
|
|
@@ -569,8 +571,39 @@ function cleanHttpStatus(value: unknown): number | undefined {
|
|
| 569 |
}
|
| 570 |
|
| 571 |
function cleanDate(value: unknown): string | undefined {
|
| 572 |
-
if (typeof value !== "string"
|
| 573 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
| 575 |
}
|
| 576 |
|
|
|
|
| 499 |
"sig",
|
| 500 |
"token",
|
| 501 |
]);
|
| 502 |
+
const DIGESTED_SOURCE_QUERY_KEYS = new Set(["code", "q", "snippet"]);
|
| 503 |
+
const ZONED_RFC3339_PATTERN =
|
| 504 |
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})$/;
|
| 505 |
const SENSITIVE_SOURCE_QUERY_PREFIXES = ["x-amz-", "x-goog-", "x-oss-"];
|
| 506 |
const TRACKING_SOURCE_QUERY_PREFIXES = ["utm_"];
|
| 507 |
const TRACKING_SOURCE_QUERY_KEYS = new Set(["fbclid", "gclid", "mc_cid", "mc_eid"]);
|
|
|
|
| 571 |
}
|
| 572 |
|
| 573 |
function cleanDate(value: unknown): string | undefined {
|
| 574 |
+
if (typeof value !== "string") return undefined;
|
| 575 |
+
const cleaned = value.trim();
|
| 576 |
+
const match = ZONED_RFC3339_PATTERN.exec(cleaned);
|
| 577 |
+
if (!match) return undefined;
|
| 578 |
+
const [, yearText, monthText, dayText, hourText, minuteText, secondText, fraction = "", zone] =
|
| 579 |
+
match;
|
| 580 |
+
const year = Number(yearText);
|
| 581 |
+
const month = Number(monthText);
|
| 582 |
+
const day = Number(dayText);
|
| 583 |
+
const hour = Number(hourText);
|
| 584 |
+
const minute = Number(minuteText);
|
| 585 |
+
const second = Number(secondText);
|
| 586 |
+
const millisecond = Number((fraction + "000").slice(0, 3));
|
| 587 |
+
if (zone === "-00:00") return undefined;
|
| 588 |
+
if (zone !== "Z") {
|
| 589 |
+
const offsetHour = Number(zone.slice(1, 3));
|
| 590 |
+
const offsetMinute = Number(zone.slice(4, 6));
|
| 591 |
+
if (offsetHour > 23 || offsetMinute > 59) return undefined;
|
| 592 |
+
}
|
| 593 |
+
const calendar = new Date(0);
|
| 594 |
+
calendar.setUTCFullYear(year, month - 1, day);
|
| 595 |
+
calendar.setUTCHours(hour, minute, second, millisecond);
|
| 596 |
+
if (
|
| 597 |
+
calendar.getUTCFullYear() !== year ||
|
| 598 |
+
calendar.getUTCMonth() !== month - 1 ||
|
| 599 |
+
calendar.getUTCDate() !== day ||
|
| 600 |
+
calendar.getUTCHours() !== hour ||
|
| 601 |
+
calendar.getUTCMinutes() !== minute ||
|
| 602 |
+
calendar.getUTCSeconds() !== second
|
| 603 |
+
) {
|
| 604 |
+
return undefined;
|
| 605 |
+
}
|
| 606 |
+
const date = new Date(cleaned);
|
| 607 |
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
| 608 |
}
|
| 609 |
|
packages/receipt-substrate/src/research_evidence.test.ts
CHANGED
|
@@ -117,6 +117,113 @@ test("content-selecting code parameters retain distinct redacted identities", ()
|
|
| 117 |
assert.match(new URL(openai.sources[0]?.url ?? "").searchParams.get("code") ?? "", /^sha256:/);
|
| 118 |
});
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
test("vendor-prefixed presigned credentials never enter normalized evidence", () => {
|
| 121 |
const base = fixtures.cases.find((candidate) => candidate.name === "matching");
|
| 122 |
assert.ok(base);
|
|
|
|
| 117 |
assert.match(new URL(openai.sources[0]?.url ?? "").searchParams.get("code") ?? "", /^sha256:/);
|
| 118 |
});
|
| 119 |
|
| 120 |
+
test("query and snippet selectors retain distinct digested identities without leaking content", () => {
|
| 121 |
+
const base = fixtures.cases.find((candidate) => candidate.name === "matching");
|
| 122 |
+
assert.ok(base);
|
| 123 |
+
const openai = normalizeOpenAIWebSearchResult({
|
| 124 |
+
...base.openai,
|
| 125 |
+
sources: [{
|
| 126 |
+
url: "https://research.example/paper?q=private-query-alpha&snippet=private-snippet-alpha",
|
| 127 |
+
}],
|
| 128 |
+
});
|
| 129 |
+
const perplexity = normalizePerplexitySearchResult({
|
| 130 |
+
...base.perplexity,
|
| 131 |
+
results: [{
|
| 132 |
+
url: "https://research.example/paper?q=private-query-beta&snippet=private-snippet-beta",
|
| 133 |
+
}],
|
| 134 |
+
});
|
| 135 |
+
const comparison = compareResearchEvidence({
|
| 136 |
+
query_sha256: fixtures.query_sha256,
|
| 137 |
+
policy_sha256: fixtures.policy_sha256,
|
| 138 |
+
providers: [openai, perplexity],
|
| 139 |
+
});
|
| 140 |
+
const receipt = emitTwoWitnessResearchReceipt(comparison, {
|
| 141 |
+
actor_id: "did:example:selector-redaction",
|
| 142 |
+
timestamp: new Date("2026-07-28T12:00:00.000Z"),
|
| 143 |
+
});
|
| 144 |
+
const serialized = JSON.stringify(receipt.envelope);
|
| 145 |
+
const openaiUrl = new URL(openai.sources[0]?.url ?? "");
|
| 146 |
+
const perplexityUrl = new URL(perplexity.sources[0]?.url ?? "");
|
| 147 |
+
|
| 148 |
+
for (const forbidden of [
|
| 149 |
+
"private-query-alpha",
|
| 150 |
+
"private-query-beta",
|
| 151 |
+
"private-snippet-alpha",
|
| 152 |
+
"private-snippet-beta",
|
| 153 |
+
]) {
|
| 154 |
+
assert.equal(serialized.includes(forbidden), false);
|
| 155 |
+
}
|
| 156 |
+
for (const key of ["q", "snippet"]) {
|
| 157 |
+
assert.match(openaiUrl.searchParams.get(key) ?? "", /^sha256:[a-f0-9]{64}$/);
|
| 158 |
+
assert.match(perplexityUrl.searchParams.get(key) ?? "", /^sha256:[a-f0-9]{64}$/);
|
| 159 |
+
assert.notEqual(openaiUrl.searchParams.get(key), perplexityUrl.searchParams.get(key));
|
| 160 |
+
}
|
| 161 |
+
assert.equal(comparison.source_url_overlap_count, 0);
|
| 162 |
+
assert.equal(comparison.label, "DIVERGENT");
|
| 163 |
+
});
|
| 164 |
+
|
| 165 |
+
test("source dates require an explicit timezone and normalize deterministically", () => {
|
| 166 |
+
const base = fixtures.cases.find((candidate) => candidate.name === "matching");
|
| 167 |
+
assert.ok(base);
|
| 168 |
+
const zoned = normalizeOpenAIWebSearchResult({
|
| 169 |
+
...base.openai,
|
| 170 |
+
sources: [{
|
| 171 |
+
url: "https://research.example/zoned",
|
| 172 |
+
published_at: "2026-07-28T08:00:00-04:00",
|
| 173 |
+
last_updated_at: "2026-07-28T12:00:00Z",
|
| 174 |
+
}],
|
| 175 |
+
});
|
| 176 |
+
const zoneLess = normalizeOpenAIWebSearchResult({
|
| 177 |
+
...base.openai,
|
| 178 |
+
sources: [{
|
| 179 |
+
url: "https://research.example/zone-less",
|
| 180 |
+
published_at: "2026-07-28T12:00:00",
|
| 181 |
+
last_updated_at: "2026-07-28",
|
| 182 |
+
}],
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
assert.equal(zoned.sources[0]?.published_at, "2026-07-28T12:00:00.000Z");
|
| 186 |
+
assert.equal(zoned.sources[0]?.last_updated_at, "2026-07-28T12:00:00.000Z");
|
| 187 |
+
assert.equal(zoneLess.sources[0]?.published_at, undefined);
|
| 188 |
+
assert.equal(zoneLess.sources[0]?.last_updated_at, undefined);
|
| 189 |
+
|
| 190 |
+
const leapDay = normalizeOpenAIWebSearchResult({
|
| 191 |
+
...base.openai,
|
| 192 |
+
sources: [{
|
| 193 |
+
url: "https://research.example/leap-day",
|
| 194 |
+
published_at: "2024-02-29T23:59:59+00:00",
|
| 195 |
+
}],
|
| 196 |
+
});
|
| 197 |
+
assert.equal(leapDay.sources[0]?.published_at, "2024-02-29T23:59:59.000Z");
|
| 198 |
+
});
|
| 199 |
+
|
| 200 |
+
test("source dates reject impossible calendar values and offsets", () => {
|
| 201 |
+
const base = fixtures.cases.find((candidate) => candidate.name === "matching");
|
| 202 |
+
assert.ok(base);
|
| 203 |
+
const invalidValues = [
|
| 204 |
+
"2026-02-29T12:00:00Z",
|
| 205 |
+
"2026-02-30T00:00:00Z",
|
| 206 |
+
"2026-04-31T12:00:00Z",
|
| 207 |
+
"2026-13-01T00:00:00Z",
|
| 208 |
+
"2026-07-28T24:00:00Z",
|
| 209 |
+
"2026-07-28T24:01:00Z",
|
| 210 |
+
"2026-07-28T12:00:00-00:00",
|
| 211 |
+
"2026-07-28T12:00:00+24:00",
|
| 212 |
+
"2026-07-28T12:00:00+04:60",
|
| 213 |
+
];
|
| 214 |
+
|
| 215 |
+
for (const published_at of invalidValues) {
|
| 216 |
+
const normalized = normalizeOpenAIWebSearchResult({
|
| 217 |
+
...base.openai,
|
| 218 |
+
sources: [{
|
| 219 |
+
url: "https://research.example/invalid-time",
|
| 220 |
+
published_at,
|
| 221 |
+
}],
|
| 222 |
+
});
|
| 223 |
+
assert.equal(normalized.sources[0]?.published_at, undefined, published_at);
|
| 224 |
+
}
|
| 225 |
+
});
|
| 226 |
+
|
| 227 |
test("vendor-prefixed presigned credentials never enter normalized evidence", () => {
|
| 228 |
const base = fixtures.cases.find((candidate) => candidate.name === "matching");
|
| 229 |
assert.ok(base);
|