From ff2d5ec49fcae5f5fc4c133e1dae713cdfd9d493 Mon Sep 17 00:00:00 2001 From: Tarzelf Date: Sun, 18 Oct 2026 12:10:09 -0400 Subject: [PATCH] Fix native audit downloader client identification --- .../download-audit.py | 9 +++- .../provenance.json | 4 +- .../native-contact-audit-publication.test.mjs | 45 +++++++++++++++++++ .../download-audit.py | 9 +++- .../provenance.json | 4 +- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py b/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py index 56ed63a..cc5f8cd 100644 --- a/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py +++ b/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py @@ -10,16 +10,21 @@ from hashlib import sha256 import json from pathlib import Path, PurePosixPath -from urllib.request import urlopen +from urllib.request import Request, urlopen BASE_URL = 'https://research.dvidia.org/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/audit/' INTEGRITY_SHA256 = 'dc7b6091b1c680b9479ea65157c7d553043af688e159463db6174696ad5949fa' MAX_FILE_BYTES = 25 * 1024 * 1024 MAX_TOTAL_BYTES = 512 * 1024 * 1024 +USER_AGENT = 'DVIDIA-Native-Contact-Audit-Downloader/1.0' def read_url(url, maximum): - with urlopen(url, timeout=60) as response: + request = Request(url, headers={ + 'User-Agent': USER_AGENT, + 'Accept-Encoding': 'identity', + }) + with urlopen(request, timeout=60) as response: payload = response.read(maximum + 1) if len(payload) > maximum: raise ValueError('Download exceeded its byte bound.') diff --git a/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json b/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json index e0ceacb..2c32b80 100644 --- a/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json +++ b/docs/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json @@ -254,8 +254,8 @@ "bytes": 749465 }, "download-audit.py": { - "sha256": "790e826065c91dd3a461f32290aeedd55d9a5efcd4cbde5025378242857a14e5", - "bytes": 3402 + "sha256": "fac88c925d06f480de8448149e43d210ce8a96438ca57784f2ba8ec7876ccaf2", + "bytes": 3590 }, "qa.json": { "sha256": "c9a6120e03d1aea102b4d5aa90bdfb16e0148267672a5650caca9932cef7df3e", diff --git a/scripts/native-contact-audit-publication.test.mjs b/scripts/native-contact-audit-publication.test.mjs index 825507a..bf64687 100644 --- a/scripts/native-contact-audit-publication.test.mjs +++ b/scripts/native-contact-audit-publication.test.mjs @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; +import { spawnSync } from 'node:child_process'; import { createReadStream } from 'node:fs'; import { readFile, readdir } from 'node:fs/promises'; import { resolve } from 'node:path'; @@ -16,6 +17,50 @@ const PROTOCOL = 'f5ded43bc66dd512e223ffea76ad51897ffea15bb016fa2c29dcd1b4fb6601 const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const json = async path => JSON.parse(await readFile(path)); const close = (a, b, tolerance = 1e-8) => assert.ok(Math.abs(a - b) < tolerance, `${a} != ${b}`); + +test('public downloader identifies its client and still enforces byte bounds', () => { + const result = spawnSync('python3', ['-c', String.raw` +from http.server import BaseHTTPRequestHandler, HTTPServer +import runpy +import sys +from threading import Thread + +downloader = runpy.run_path(sys.argv[1]) +requests = [] +class Handler(BaseHTTPRequestHandler): + def do_GET(self): + requests.append((self.path, self.headers.get('User-Agent'), self.headers.get('Accept-Encoding'))) + if self.headers.get('User-Agent') != 'DVIDIA-Native-Contact-Audit-Downloader/1.0': + self.send_response(403) + self.end_headers() + return + self.send_response(200) + self.end_headers() + self.wfile.write(b'audit') + def log_message(self, *args): + pass + +server = HTTPServer(('127.0.0.1', 0), Handler) +thread = Thread(target=server.serve_forever, daemon=True) +thread.start() +url = f'http://127.0.0.1:{server.server_port}/integrity.json' +try: + assert downloader['read_url'](url, 5) == b'audit' + try: + downloader['read_url'](url, 4) + except ValueError as error: + assert str(error) == 'Download exceeded its byte bound.' + else: + raise AssertionError('Oversized responses must fail.') + assert requests == [('/integrity.json', downloader['USER_AGENT'], 'identity')] * 2 +finally: + server.shutdown() + server.server_close() + thread.join() +`, resolve(RUN, 'download-audit.py')], { encoding: 'utf8', timeout: 10_000 }); + assert.equal(result.status, 0, result.stderr || result.error?.message); +}); + async function files(directory) { const result = []; for (const entry of await readdir(directory, { withFileTypes: true })) { diff --git a/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py b/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py index 56ed63a..cc5f8cd 100644 --- a/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py +++ b/topics/physical-grounding/runs/2026-10-18-native-contact-audit/download-audit.py @@ -10,16 +10,21 @@ from hashlib import sha256 import json from pathlib import Path, PurePosixPath -from urllib.request import urlopen +from urllib.request import Request, urlopen BASE_URL = 'https://research.dvidia.org/downloads/topics/physical-grounding/runs/2026-10-18-native-contact-audit/audit/' INTEGRITY_SHA256 = 'dc7b6091b1c680b9479ea65157c7d553043af688e159463db6174696ad5949fa' MAX_FILE_BYTES = 25 * 1024 * 1024 MAX_TOTAL_BYTES = 512 * 1024 * 1024 +USER_AGENT = 'DVIDIA-Native-Contact-Audit-Downloader/1.0' def read_url(url, maximum): - with urlopen(url, timeout=60) as response: + request = Request(url, headers={ + 'User-Agent': USER_AGENT, + 'Accept-Encoding': 'identity', + }) + with urlopen(request, timeout=60) as response: payload = response.read(maximum + 1) if len(payload) > maximum: raise ValueError('Download exceeded its byte bound.') diff --git a/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json b/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json index e0ceacb..2c32b80 100644 --- a/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json +++ b/topics/physical-grounding/runs/2026-10-18-native-contact-audit/provenance.json @@ -254,8 +254,8 @@ "bytes": 749465 }, "download-audit.py": { - "sha256": "790e826065c91dd3a461f32290aeedd55d9a5efcd4cbde5025378242857a14e5", - "bytes": 3402 + "sha256": "fac88c925d06f480de8448149e43d210ce8a96438ca57784f2ba8ec7876ccaf2", + "bytes": 3590 }, "qa.json": { "sha256": "c9a6120e03d1aea102b4d5aa90bdfb16e0148267672a5650caca9932cef7df3e",