Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions hub/scripts/compile-manifests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,44 @@ export const VALID_HTML_MODES = new Set([
'medicaid_nadac_html',
'usps_docs_html',
'sba_dsbs_loans_html',
// Wave 3 B4 Category L (Research & Scholarly #301-#314)
'semantic_scholar_html',
'unpaywall_html',
'core_ac_html',
'orcid_html',
'ror_html',
'dblp_html',
'biorxiv_medrxiv_html',
'nasa_ads_html',
'nih_reporter_html',
'nsf_awards_html',
'doe_osti_html',
'research_repo_pack_html',
'datacite_html',
'ssrn_nber_html',
// Wave 3 B4 Category M (Security & Vulnerability Intelligence #315-#326)
'cisa_kev_html',
'mitre_attack_html',
'mitre_cwe_capec_html',
'cve_org_html',
'cisa_advisories_html',
'exploit_db_html',
'cert_transparency_html',
'bgp_he_html',
// Wave 3 B4 Category N (Developer Infrastructure #327-#340)
'bitbucket_html',
'sourceforge_launchpad_html',
'bugzilla_html',
'jira_public_html',
'wordpress_plugin_html',
'vscode_marketplace_html',
'chrome_web_store_html',
'artifact_hub_html',
'puppet_forge_html',
'apis_guru_html',
'endoflife_html',
'caniuse_html',
'bundle_packagephobia_html',
]);

const pslDatPath = join(manifestsDir, 'public_suffix_list.dat');
Expand Down
1 change: 1 addition & 0 deletions hub/scripts/run-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const suiteSpecs = [
['test/wave3-b1-gov-edu-jobs.test.ts', 'wave3-b1-gov-edu-jobs.test.mjs'],
['test/wave3-b2-schema-community-store.test.ts', 'wave3-b2-schema-community-store.test.mjs'],
['test/wave3-b3-trade-regulators.test.ts', 'wave3-b3-trade-regulators.test.mjs'],
['test/wave3-b4-research-security-dev.test.ts', 'wave3-b4-research-security-dev.test.mjs'],
['test/mcp-part2-wave2e.test.ts', 'mcp-part2-wave2e.test.mjs'],
['test/wave2-security-fixes.test.ts', 'wave2-security-fixes.test.mjs'],
['test/hub-secrets-policy.test.ts', 'hub-secrets-policy.test.mjs'],
Expand Down
2 changes: 2 additions & 0 deletions hub/src/adapter-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface AdapterPolicy {
maxCacheTtlMs?: number;
maxConcurrent?: number;
strictRobots?: boolean;
maxFetchBytes?: number;
allowTruncatedStream?: boolean;
}

export function isValidUserAgentHeaderValue(ua: string): boolean {
Expand Down
89 changes: 86 additions & 3 deletions hub/src/extractors/declarative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,46 @@ export type DeclarativeJsonMode =
| 'medicaid_nadac_json'
| 'usps_addresses_json'
| 'carrier_tracking_json'
| 'sba_dkan_json';
| 'sba_dkan_json'
| 'semantic_scholar_json'
| 'unpaywall_json'
| 'core_ac_json'
| 'orcid_json'
| 'ror_json'
| 'dblp_json'
| 'biorxiv_medrxiv_json'
| 'nasa_ads_json'
| 'nih_reporter_json'
| 'nsf_awards_json'
| 'doe_osti_json'
| 'research_repo_pack_json'
| 'datacite_json'
| 'cisa_kev_json'
| 'first_epss_json'
| 'mitre_attack_index_json'
| 'mitre_cwe_json'
| 'cve_org_json'
| 'vendor_csaf_json'
| 'cert_transparency_json'
| 'rdap_bootstrap_json'
| 'rdap_json'
| 'bgp_asn_ripe_json'
| 'bitbucket_json'
| 'sourceforge_json'
| 'launchpad_json'
| 'bugzilla_json'
| 'jira_public_json'
| 'wordpress_plugin_json'
| 'open_vsx_json'
| 'amo_addon_json'
| 'artifact_hub_json'
| 'ansible_galaxy_json'
| 'puppet_forge_json'
| 'apis_guru_json'
| 'endoflife_json'
| 'web_compat_json'
| 'bundlephobia_json'
| 'packagephobia_json';

export interface DeclarativeExtractSpec {
commerceMode?: DeclarativeCommerceMode;
Expand Down Expand Up @@ -655,7 +694,16 @@ export interface DeclarativeExtractSpec {
| 'cbo_rss_xml'
| 'everycrs_csv'
| 'cms_hpt_txt'
| 'cms_mrf_csv';
| 'cms_mrf_csv'
| 'dblp_xml'
| 'cisa_kev_csv'
| 'mitre_attack_stix_bundle'
| 'cisa_advisories_rss'
| 'security_txt_text'
| 'exploit_db_csv'
| 'exploit_db_rss'
| 'gerrit_json'
| 'apis_guru_list_bounded';
pathParam?: string;
codeByPath?: DeclarativeCodeByPathSpec;
xml?: DeclarativeXmlSpec;
Expand Down Expand Up @@ -1020,7 +1068,42 @@ export type DeclarativeHtmlMode =
| 'cms_price_transparency_html'
| 'medicaid_nadac_html'
| 'usps_docs_html'
| 'sba_dsbs_loans_html';
| 'sba_dsbs_loans_html'
| 'semantic_scholar_html'
| 'unpaywall_html'
| 'core_ac_html'
| 'orcid_html'
| 'ror_html'
| 'dblp_html'
| 'biorxiv_medrxiv_html'
| 'nasa_ads_html'
| 'nih_reporter_html'
| 'nsf_awards_html'
| 'doe_osti_html'
| 'research_repo_pack_html'
| 'datacite_html'
| 'ssrn_nber_html'
| 'cisa_kev_html'
| 'mitre_attack_html'
| 'mitre_cwe_capec_html'
| 'cve_org_html'
| 'cisa_advisories_html'
| 'exploit_db_html'
| 'cert_transparency_html'
| 'bgp_he_html'
| 'bitbucket_html'
| 'sourceforge_launchpad_html'
| 'bugzilla_html'
| 'jira_public_html'
| 'wordpress_plugin_html'
| 'vscode_marketplace_html'
| 'chrome_web_store_html'
| 'artifact_hub_html'
| 'puppet_forge_html'
| 'apis_guru_html'
| 'endoflife_html'
| 'caniuse_html'
| 'bundle_packagephobia_html';

export interface DeclarativeHtmlRouteSpec {
id?: string;
Expand Down
37 changes: 33 additions & 4 deletions hub/src/overflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,25 @@ export function decodeBase64TextWireBody(base64Body: unknown, contentType?: unkn
}
}

function trimTrailingIncompleteUtf8(bytes: Uint8Array): Uint8Array {
const n = bytes.byteLength;
if (n === 0) return bytes;
let i = n - 1;
while (i >= 0 && n - i <= 3 && (bytes[i]! & 0xc0) === 0x80) {
i--;
}
if (i < 0) return bytes;
const b = bytes[i]!;
let expectedLen = 1;
if ((b & 0xe0) === 0xc0) expectedLen = 2;
else if ((b & 0xf0) === 0xe0) expectedLen = 3;
else if ((b & 0xf8) === 0xf0) expectedLen = 4;
if (expectedLen > 1 && n - i < expectedLen) {
return bytes.subarray(0, i);
}
return bytes;
}

export function encodeBodyForWire(
bytes: Uint8Array,
contentType?: string,
Expand Down Expand Up @@ -1446,6 +1465,7 @@ export async function cloudflareOverflowFetch(
ifNoneMatch?: string;
ifModifiedSince?: string;
maxBytes?: number;
allowTruncatedStream?: boolean;
userAgentProfile?: string;
minIntervalMs?: number;
blockCrossOriginRedirects?: boolean;
Expand Down Expand Up @@ -1877,8 +1897,15 @@ export async function cloudflareOverflowFetch(
aggregateBatchBytes += bytes.byteLength;

const isPaymentRequired = resp.status === 402;
const allowTruncated =
Boolean(r.allowTruncatedStream) &&
truncated &&
resp.status >= 200 &&
resp.status < 300;
const decodedPreview =
!truncated && bytes.byteLength <= 98_304 ? new TextDecoder('utf-8', { fatal: false }).decode(bytes) : '';
(!truncated || allowTruncated) && bytes.byteLength <= 98_304
? new TextDecoder('utf-8', { fatal: false }).decode(bytes)
: '';
if (resp.status === 403 && bytes.byteLength <= 512 && /^\s*forbidden redirect target:/i.test(decodedPreview)) {
results.push({
id: r.id,
Expand All @@ -1899,13 +1926,15 @@ export async function cloudflareOverflowFetch(
!truncated && !isPaymentRequired
? classifyWafAndChallenge({ status: resp.status, headers: resp.headers, rawBody: decodedPreview })
: null;
const bodyBytesForWire =
allowTruncated && !hasBinaryControlBytes(bytes) ? trimTrailingIncompleteUtf8(bytes) : bytes;
const encodedBody =
isPaymentRequired
? !truncated && bytes.byteLength <= 65_536
? encodeBodyForWire(bytes, respCt)
: undefined
: includeBody && !truncated
? encodeBodyForWire(bytes, respCt)
: includeBody && (!truncated || allowTruncated)
? encodeBodyForWire(bodyBytesForWire, respCt)
: undefined;
const isNotModified = resp.status === 304 && Boolean(callerIfNoneMatch || callerIfModifiedSince);
const isAutoKindSkip =
Expand All @@ -1917,7 +1946,7 @@ export async function cloudflareOverflowFetch(
// HTTP 402 MUST ALWAYS surface as `payment_required` (status 402) even if an untrusted origin sent an oversized `> maxBytes` body (`x402_7.mjs`)!
const outcome = isPaymentRequired
? 'payment_required'
: truncated
: truncated && !allowTruncated
? 'error'
: wafMatch || cfMitigated
? 'challenge'
Expand Down
Loading
Loading