Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ jobs:
node --check frontend/release.js
node --check frontend/gateway-session.js
node tests/gateway_session_test.mjs
- name: Initialize ephemeral CI container identity
run: |
python3 - <<'PY'
from pathlib import Path
import re, uuid
path = Path("/etc/machine-id")
value = path.read_text().strip() if path.exists() else ""
if not value:
path.write_text(uuid.uuid4().hex + "\n")
elif not re.fullmatch(r"[0-9a-fA-F]{32}", value):
raise SystemExit("Invalid CI container machine identity")
PY
- name: Private database and synthetic Gateway integration
run: |
useradd -m reachtest
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/security-runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Gateway runtime security guard
on: [push, pull_request]
permissions:
contents: read
jobs:
runtime-guard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check security boundary and launcher syntax
run: |
PYTHONDONTWRITEBYTECODE=1 python3 tests/runtime_guard_test.py
bash -n scripts/gateway.sh
28 changes: 28 additions & 0 deletions docs/security-runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Gateway runtime security baseline (2026-10-21)

The account Gateway now requires Java 21.0.13 or a newer 21.x security update.
The launcher no longer silently selects `.local/java-runtime-21`. Select a separately
installed, vendor-verified runtime with `REACH_JAVA_HOME=/absolute/java/home`.
`JAVA_HOME` and PATH are then pinned to the executable actually inspected.
The check also rejects the compromised emSign ECC Root CA - G3 in the effective
default trust store (including `jssecacerts`) and refuses ambient Java option
variables. Do not disable certificate verification to restore connectivity.

Run `python3 scripts/runtime_guard.py --java /absolute/java/home/bin/java` before
launching. The output records version, executable, trust-store path and hash.
Run `python3 tests/runtime_guard_test.py` for the version-gate regressions.
A denied runtime cannot start a new Gateway session. Existing processes are not
stopped or silently upgraded. No account databases, credentials or login sessions
are copied or changed by this check.

The previously selected Ubuntu runtime is 21.0.12.1. At review time the local APT
metadata and Temurin/Azul latest-21 metadata still offered that older release.
Do not label it patched. Install a vendor build carrying the October security
updates when available, then run the guard and validate local HTTPS login plus
account/market-data sessions. A successful runtime check is a baseline check,
not proof that the Gateway's own JAR dependencies are vulnerability-free.

References:
- https://www.oracle.com/java/technologies/javase/21-0-13-relnotes.html
- https://www.oracle.com/security-alerts/cpuoct2026.html
- https://ubuntu.com/security/notices/USN-8944-1
11 changes: 8 additions & 3 deletions scripts/gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
[[ "${REACH_ENV:-user}" == "user" ]] || { echo "Real Gateway cannot start from a test/demo runtime." >&2; exit 1; }
gateway_dir="${REACH_GATEWAY_DIR:-$repo_dir/.local/clientportal}"
if [[ -x "$repo_dir/.local/java-runtime-21/usr/lib/jvm/java-21-openjdk-amd64/bin/java" ]]; then
export PATH="$repo_dir/.local/java-runtime-21/usr/lib/jvm/java-21-openjdk-amd64/bin:$PATH"
# Explicit runtime selection; never silently prefer a stale private JRE.
if [[ -n "${REACH_JAVA_HOME:-}" ]]; then
java_executable="$REACH_JAVA_HOME/bin/java"
else
java_executable="$(command -v java || true)"
fi
command -v java >/dev/null || { echo 'Install Java (JRE 11 or newer) first.' >&2; exit 1; }
JAVA_HOME="$(python3 "$repo_dir/scripts/runtime_guard.py" --java "$java_executable" --java-home)"
export JAVA_HOME
export PATH="$JAVA_HOME/bin:$PATH"
[[ -f "$gateway_dir/root/conf.yaml" ]] || { echo 'Download and extract the official Client Portal Gateway; see docs/ibkr.md.' >&2; exit 1; }
python3 "$repo_dir/scripts/device_guard.py" "$gateway_dir"
cd "$gateway_dir"
Expand Down
76 changes: 76 additions & 0 deletions scripts/runtime_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
"""Validate the actual Gateway Java executable before starting an account session."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys

MINIMUM = (21, 0, 13)
DENIED = {'86a1ecba089c4a8d3bbe2734c612ba341d813e043cf9e8a862cd5c57a36bbe6b'}


def validate_version(text):
match = re.search(r'^\s*java\.version\s*=\s*(\S+)', text, re.M)
if not match:
raise ValueError('Cannot identify actual Java version')
version = match[1]
if re.search(r'(?:-ea|-internal)', version):
raise ValueError('Preview/internal Java is not approved for the Gateway')
parts = re.match(r'^(\d+)\.(\d+)\.(\d+)(?:[.+-]|$)', version)
if not parts or tuple(map(int, parts.groups())) < MINIMUM or int(parts[1]) != 21:
raise ValueError('Gateway requires security-updated Java 21.0.13 or newer in the 21.x line; update the actual selected runtime')
return version


def inspect(java):
java = Path(java).resolve(strict=True)
env = dict(os.environ, LC_ALL='C')
# Ambient options can change the effective trust store or executable startup.
for key in ('JAVA_TOOL_OPTIONS', 'JDK_JAVA_OPTIONS', '_JAVA_OPTIONS'):
if env.get(key):
raise ValueError('Unset '+key+' before starting the Gateway; review runtime settings explicitly')
result = subprocess.run([str(java), '-XshowSettings:properties', '-version'],
capture_output=True, text=True, timeout=15, env=env, check=True)
text = result.stdout+'\n'+result.stderr
version = validate_version(text)
home = re.search(r'^\s*java\.home\s*=\s*(.+)$', text, re.M)
if not home:
raise ValueError('Cannot identify actual java.home')
home = Path(home[1].strip()).resolve(strict=True)
if java != (home/'bin/java').resolve(strict=True):
raise ValueError('Java executable and java.home differ')
store = home/'lib/security/cacerts'
# JSSE selects jssecacerts before cacerts when it exists.
if (home/'lib/security/jssecacerts').exists():
store = home/'lib/security/jssecacerts'
if not store.is_file():
raise ValueError('Java trust store is unavailable')
certs = subprocess.run([str(home/'bin/keytool'), '-J-Duser.language=en', '-list', '-v',
'-keystore', str(store), '-storepass', 'changeit'],
capture_output=True, text=True, timeout=20, env=env, check=True)
fingerprints = {x.replace(':', '').lower() for x in re.findall(r'SHA256:\s*([0-9A-Fa-f:]{95})', certs.stdout)}
if not fingerprints:
raise ValueError('Cannot verify Java trust-store fingerprints')
if fingerprints & DENIED:
raise ValueError('Java trust store still trusts the compromised emSign root; install an updated vendor runtime/trust store')
return dict(java=str(java), java_home=str(home), version=version,
trust_store=str(store), trust_store_sha256=hashlib.sha256(store.read_bytes()).hexdigest())


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--java', default=shutil.which('java'))
parser.add_argument('--java-home', action='store_true')
args = parser.parse_args()
try:
if not args.java:
raise ValueError('Select an updated runtime with REACH_JAVA_HOME')
info = inspect(args.java)
print(info['java_home'] if args.java_home else json.dumps(info, indent=2))
except (OSError, ValueError, subprocess.SubprocessError) as exc:
raise SystemExit('Gateway runtime denied: '+str(exc))
10 changes: 10 additions & 0 deletions scripts/test-isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def free_port():
command([sys.executable,root/'tests/integration.py','--url',url,'--root',root,'--report',run/'integration-report.json'])
command([sys.executable,root/'tests/release_integration.py','--url',url])
print('ISOLATED_TEST_REPORTS='+str(run))
except BaseException:
print('ISOLATED_TEST_LOGS='+str(run),file=sys.stderr,flush=True)
for name in ('app.log','mock.log','postgres.log'):
path=run/name
if path.is_file():
print('--- '+name+' (last 16384 bytes) ---',file=sys.stderr)
with path.open('rb') as log:
log.seek(max(0,path.stat().st_size-16384))
print(log.read().decode('utf-8','replace'),file=sys.stderr,flush=True)
raise
finally:
for p in reversed(processes):
p.terminate()
Expand Down
41 changes: 41 additions & 0 deletions tests/runtime_guard_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import importlib.util
from pathlib import Path
import unittest
from unittest.mock import patch
ROOT=Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('runtime_guard',ROOT/'scripts/runtime_guard.py')
guard=importlib.util.module_from_spec(spec);spec.loader.exec_module(guard)
class RuntimeGuardTests(unittest.TestCase):
def test_stale_private_runtime_rejected(self):
with self.assertRaisesRegex(ValueError,'21.0.13'):guard.validate_version(' java.version = 21.0.12.1')
def test_fixed_21_accepted(self):
self.assertEqual(guard.validate_version(' java.version = 21.0.13'),'21.0.13')
self.assertEqual(guard.validate_version(' java.version = 21.0.14'),'21.0.14')
def test_other_major_or_preview_not_silently_accepted(self):
for version in ['17.0.21','25.0.5','21.0.13-ea','garbage']:
with self.subTest(version=version),self.assertRaises(ValueError):guard.validate_version(' java.version = '+version)
def test_missing_version_rejected(self):
with self.assertRaises(ValueError):guard.validate_version('java is fine')
def test_compromised_trust_store_rejected_and_jssecacerts_precedence(self):
import tempfile,subprocess
with tempfile.TemporaryDirectory() as tmp:
home=Path(tmp);(home/'bin').mkdir();(home/'lib/security').mkdir(parents=True)
java=home/'bin/java';java.touch()
(home/'lib/security/cacerts').write_bytes(b'fixture')
effective=home/'lib/security/jssecacerts';effective.write_bytes(b'override')
props=subprocess.CompletedProcess([],0,'',f' java.version = 21.0.13\n java.home = {home}\n')
denied=':'.join(next(iter(guard.DENIED))[i:i+2] for i in range(0,64,2))
listing=subprocess.CompletedProcess([],0,'SHA256: '+denied,'')
with patch.dict(guard.os.environ,{},clear=True),patch.object(guard.subprocess,'run',side_effect=[props,listing]) as run:
with self.assertRaisesRegex(ValueError,'compromised'):guard.inspect(java)
self.assertIn(str(effective),run.call_args.args[0])
def test_clean_trust_store_returns_evidence(self):
import tempfile,subprocess
with tempfile.TemporaryDirectory() as tmp:
home=Path(tmp);(home/'bin').mkdir();(home/'lib/security').mkdir(parents=True)
java=home/'bin/java';java.touch();(home/'lib/security/cacerts').write_bytes(b'fixture')
props=subprocess.CompletedProcess([],0,'',f' java.version = 21.0.13\n java.home = {home}\n')
listing=subprocess.CompletedProcess([],0,'SHA256: '+':'.join(['ab']*32),'')
with patch.dict(guard.os.environ,{},clear=True),patch.object(guard.subprocess,'run',side_effect=[props,listing]):
self.assertEqual(guard.inspect(java)['version'],'21.0.13')
if __name__=='__main__':unittest.main()
Loading