Commit 6b9d07cde4

6b9d07cde421b86a14b379f975d84fb0fa705c61

parent: d3d7a60402

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-01 05:44 UTC

Reject non-http(s) TSA URLs in timestamp submit

Ref #1

Layout: unified · split

evidence_seal/timestamp.py +4
@@ -19,6 +19,7 @@ from __future__ import annotations
19 19
20import base64 20import base64
21import secrets 21import secrets
22import urllib.parse
22import urllib.request 23import urllib.request
23from datetime import timezone 24from datetime import timezone
24from pathlib import Path 25from pathlib import Path
@@ -76,6 +77,9 @@ def submit(request_der: bytes, tsa_url: str, timeout: float = 30.0) -> bytes:
76 77
77 Network call — the caller is responsible for choosing a trusted TSA URL. 78 Network call — the caller is responsible for choosing a trusted TSA URL.
78 """ 79 """
80 scheme = urllib.parse.urlsplit(tsa_url).scheme.lower()
81 if scheme not in ("http", "https"):
82 raise ValueError(f"TSA URL must use http or https: {tsa_url}")
79 req = urllib.request.Request( 83 req = urllib.request.Request(
80 tsa_url, 84 tsa_url,
81 data=request_der, 85 data=request_der,
tests/test_timestamp.py +8
@@ -17,6 +17,7 @@ from evidence_seal.timestamp import (
17 apply_timestamp, 17 apply_timestamp,
18 build_request, 18 build_request,
19 parse_token, 19 parse_token,
20 submit,
20 verify_timestamp, 21 verify_timestamp,
21) 22)
22 23
@@ -223,6 +224,13 @@ def test_verify_unstamped_manifest(manifest):
223 assert "not timestamped" in message 224 assert "not timestamped" in message
224 225
225 226
227def test_submit_rejects_non_http_url(manifest, tmp_path):
228 target = tmp_path / "tsa.tsr"
229 target.write_bytes(b"")
230 with pytest.raises(ValueError, match="http or https"):
231 submit(build_request(manifest["id"]), target.as_uri())
232
233
226# --- full CMS signature verification (needs cryptography) --- 234# --- full CMS signature verification (needs cryptography) ---
227 235
228 236