fix(chains): strip every keyed provider URL, and make the gate fail closed

The first pass matched only `infura.io/.../v3/<lowercase hex>`, so it missed
`https://...infura.io/v3/<key>`, upper-case keys and hosts, and Nova's
OnFinality `?apikey=` URLs (Moonriver, and the Hades testnet in v20/v21
preConfigured). preConfigured was copied from Nova without the filter, and the
integrity check passed if grep itself failed.

- one predicate, is_keyed(), in sync_from_nova.py: Infura /v3/ ids and
  apikey/api_key/key/token query values, case-insensitive; {PLACEHOLDER}
  values are allowed
- preConfigured details are filtered after the copy; a chain left with no
  node loses its details file and its index entry (Hades, v20/v21 only)
- rewritten files keep their own indent, so the diff is the data change only
- check 5 imports is_keyed() and checks every string in every JSON file
  under chains/; an unreadable file or an empty tree is an error
- check 3 reports a grep error instead of passing on it
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-10-17 19:58:49 +04:00
1 parent 7f0bb6a3d3
commit b5f5af2cce
20 files changed
+92 -161

No files matched your search

+57 -16
View File
@@ -52,25 +52,65 @@ def load_blacklist() -> set:
return set()
# Nova's configs carry Nova's own Infura project keys written into node URLs.
# They are not ours to use: our builds fill `{INFURA_API_KEY}` from our own
# secret, and a keyed URL breaks for every user the day Nova rotates it.
KEYED_ENDPOINT = re.compile(r"infura\.io/.*/v3/[0-9a-f]{32}")
# Nova's configs carry Nova's own provider keys written into node URLs (Infura
# project ids, OnFinality apikeys). They are not ours to use: our builds fill
# placeholders like `{INFURA_API_KEY}` from our own secrets, and a keyed URL
# breaks for every user the day Nova rotates it. check_pezkuwi_integrity.py
# imports this same predicate, so the filter and the gate cannot disagree.
KEYED_ENDPOINT = re.compile(
r"infura\.io/(?:[^?#\s]*/)?v3/[0-9a-z]{32}"
r"|[?&](?:api[_-]?key|apikey|access[_-]?token|token|key)=(?!\{)[^&#\s]+",
re.IGNORECASE,
)
def is_keyed(url: str) -> bool:
"""True if the URL embeds a literal credential rather than a {PLACEHOLDER}."""
return bool(KEYED_ENDPOINT.search(url))
def strip_chain(chain: dict) -> dict | None:
"""The chain without keyed nodes; None if no node is left."""
nodes = chain.get('nodes')
if not isinstance(nodes, list):
return chain
kept = [n for n in nodes if not (isinstance(n, dict) and is_keyed(str(n.get('url', ''))))]
if not kept:
return None
return chain if len(kept) == len(nodes) else {**chain, 'nodes': kept}
def strip_keyed_endpoints(chains: list) -> list:
"""Drop nodes whose URL embeds a third-party API key, and any chain left with no node."""
out = []
for chain in chains:
nodes = chain.get('nodes')
if nodes is not None:
kept = [n for n in nodes if not KEYED_ENDPOINT.search(n.get('url', ''))]
if not kept:
continue
if len(kept) != len(nodes):
chain = {**chain, 'nodes': kept}
out.append(chain)
return out
"""Drop nodes whose URL embeds a third-party key, and any chain left with no node."""
return [c for c in (strip_chain(c) for c in chains) if c is not None]
def rewrite_in_place(path: Path, data):
"""Rewrite a JSON file keeping its own indent and trailing newline, so a
filtered copy of Nova's file differs from it only where the data does."""
raw = path.read_text(encoding='utf-8')
second = raw.split('\n', 2)[1] if raw.count('\n') >= 1 else ''
indent = (len(second) - len(second.lstrip(' '))) or 2
out = json.dumps(data, indent=indent, ensure_ascii=False)
path.write_text(out + ('\n' if raw.endswith('\n') else ''), encoding='utf-8')
def strip_preconfigured(preconfig: Path):
"""Apply strip_chain to every details file; a chain left with no node is
removed together with its entry in the matching index."""
for details, index in (("details", "chains.json"), ("detailsDev", "chains_dev.json")):
dropped = set()
for f in sorted((preconfig / details).glob("*.json")):
chain = load_json(f)
stripped = strip_chain(chain)
if stripped is None:
dropped.add(chain.get('chainId'))
f.unlink()
elif stripped is not chain:
rewrite_in_place(f, stripped)
index_file = preconfig / index
if dropped and index_file.exists():
rewrite_in_place(index_file, [c for c in load_json(index_file) if c.get('chainId') not in dropped])
def merge_chains(nova_chains: list, pezkuwi_chains: list, blocked_ids: set) -> list:
@@ -165,6 +205,7 @@ def sync_chains():
if output_preconfig.exists():
shutil.rmtree(output_preconfig)
shutil.copytree(nova_preconfig, output_preconfig)
strip_preconfigured(output_preconfig)
def sync_xcm():