twsrt 3.3.2__tar.gz → 3.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {twsrt-3.3.2 → twsrt-3.3.3}/PKG-INFO +3 -3
  2. {twsrt-3.3.2 → twsrt-3.3.3}/README.md +2 -2
  3. {twsrt-3.3.2 → twsrt-3.3.3}/pyproject.toml +2 -2
  4. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/bin/cli.py +1 -1
  5. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/doctor.py +30 -8
  6. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/probe.py +50 -4
  7. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/PKG-INFO +3 -3
  8. {twsrt-3.3.2 → twsrt-3.3.3}/setup.cfg +0 -0
  9. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/__init__.py +0 -0
  10. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/bin/__init__.py +0 -0
  11. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/__init__.py +0 -0
  12. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/agent.py +0 -0
  13. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/claude.py +0 -0
  14. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/codex.py +0 -0
  15. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/composition.py +0 -0
  16. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/config.py +0 -0
  17. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/copilot.py +0 -0
  18. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/jsonc.py +0 -0
  19. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/models.py +0 -0
  20. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/profiles.py +0 -0
  21. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/sources.py +0 -0
  22. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt/lib/symlink.py +0 -0
  23. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/SOURCES.txt +0 -0
  24. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/dependency_links.txt +0 -0
  25. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/entry_points.txt +0 -0
  26. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/requires.txt +0 -0
  27. {twsrt-3.3.2 → twsrt-3.3.3}/src/twsrt.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twsrt
3
- Version: 3.3.2
3
+ Version: 3.3.3
4
4
  Summary: Agent security configuration generator — translates canonical security rules into agent-specific configs
5
5
  Author-email: sysid <sysid@gmx.de>
6
6
  License-Expression: BSD-3-Clause
@@ -503,8 +503,8 @@ otherwise `default_profile` is compared and reports drift.
503
503
 
504
504
  **How `test` works.** Each effective SRT rule becomes a probe command
505
505
  (`head -c 1` on a denied file, an append-open that writes nothing on a
506
- write rule, `curl -I` per domain, plus a canary host outside the
507
- allowlist). Each probe runs twice: plainly as a control, then under
506
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
507
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
508
508
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
509
509
  sandboxed run fails, so a missing file can never count as protected. The
510
510
  probe set is derived from the compiled file, never authored: change the
@@ -489,8 +489,8 @@ otherwise `default_profile` is compared and reports drift.
489
489
 
490
490
  **How `test` works.** Each effective SRT rule becomes a probe command
491
491
  (`head -c 1` on a denied file, an append-open that writes nothing on a
492
- write rule, `curl -I` per domain, plus a canary host outside the
493
- allowlist). Each probe runs twice: plainly as a control, then under
492
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
493
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
494
494
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
495
495
  sandboxed run fails, so a missing file can never count as protected. The
496
496
  probe set is derived from the compiled file, never authored: change the
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twsrt"
3
- version = "3.3.2"
3
+ version = "3.3.3"
4
4
  description = "Agent security configuration generator — translates canonical security rules into agent-specific configs"
5
5
  readme = "README.md"
6
6
  license = "BSD-3-Clause"
@@ -45,7 +45,7 @@ dev = [
45
45
  ]
46
46
 
47
47
  [tool.bumpversion]
48
- current_version = "3.3.2"
48
+ current_version = "3.3.3"
49
49
  commit = true
50
50
  tag = false
51
51
  tag_name = "v{new_version}"
@@ -21,7 +21,7 @@ from twsrt.lib.models import (
21
21
  yolo_path,
22
22
  )
23
23
 
24
- __version__ = "3.3.2"
24
+ __version__ = "3.3.3"
25
25
 
26
26
  app = typer.Typer(
27
27
  name="twsrt",
@@ -353,8 +353,10 @@ def _check_profile_lists(
353
353
  tuple(items),
354
354
  )
355
355
  )
356
- if key == "allowedDomains":
357
- _check_wildcard_apex(list_name, values, ignores, base_dir, findings)
356
+ if key in _DOMAIN_LISTS:
357
+ _check_wildcard_apex(
358
+ key, list_name, values, ignores, base_dir, findings
359
+ )
358
360
 
359
361
 
360
362
  def _profile_lists(
@@ -418,8 +420,10 @@ def _domain_covers(parent: str, child: str) -> bool:
418
420
  if ":" in parent or ":" in child:
419
421
  return False # ponytail: port-qualified entries are not compared
420
422
  if not child.startswith("*"):
421
- # `twsrt test` cannot dial a wildcard: a concrete host below one is
422
- # that rule's only live probe, so it is never dead weight.
423
+ # A concrete host below a wildcard is never dead weight: `twsrt test`
424
+ # probes the wildcard only via srt's filter decision for a made-up
425
+ # subdomain; the concrete host is its only end-to-end probe (a real
426
+ # connection, judged against a control run).
423
427
  return False
424
428
  if parent == "*":
425
429
  return True
@@ -427,7 +431,25 @@ def _domain_covers(parent: str, child: str) -> bool:
427
431
  return parent.startswith("*.") and child.endswith(parent[1:])
428
432
 
429
433
 
434
+ # list key -> (severity, code, description after "<n> wildcards ").
435
+ _WILDCARD_APEX = {
436
+ "allowedDomains": (
437
+ "info",
438
+ "wildcard-apex",
439
+ "not matching the bare apex domain (add it where needed)",
440
+ ),
441
+ # A deny leaves the apex open: Claude's WebFetch deny skips it, and srt
442
+ # blocks it only while no allowedDomains entry (e.g. "*") admits it.
443
+ "deniedDomains": (
444
+ "warning",
445
+ "wildcard-deny-apex",
446
+ "leaving the bare apex domain not denied; list it too",
447
+ ),
448
+ }
449
+
450
+
430
451
  def _check_wildcard_apex(
452
+ key: str,
431
453
  list_name: str,
432
454
  values: dict[str, list[Path]],
433
455
  ignores: Ignores,
@@ -435,6 +457,7 @@ def _check_wildcard_apex(
435
457
  findings: list[Finding],
436
458
  ) -> None:
437
459
  """Grouped by the wildcard's fragment, so profiles sharing it dedup."""
460
+ severity, code, description = _WILDCARD_APEX[key]
438
461
  missing: dict[Path, list[str]] = {}
439
462
  for value, origins in values.items():
440
463
  if _ignored(ignores, origins, value):
@@ -444,11 +467,10 @@ def _check_wildcard_apex(
444
467
  for origin, items in missing.items():
445
468
  findings.append(
446
469
  Finding(
447
- "info",
448
- "wildcard-apex",
470
+ severity,
471
+ code,
449
472
  _show(origin, base_dir),
450
- f"{list_name}: {_count(items, 'wildcard', 'wildcards')} not "
451
- "matching the bare apex domain (add it where needed)",
473
+ f"{list_name}: {_count(items, 'wildcard', 'wildcards')} {description}",
452
474
  tuple(items),
453
475
  )
454
476
  )
@@ -30,6 +30,10 @@ Runner = Callable[..., subprocess.CompletedProcess]
30
30
  ScratchFactory = Callable[[Path], Path]
31
31
 
32
32
  _CURL = "curl -sS -m 10 -o /dev/null -I https://{host}/"
33
+ # Prints srt's answer to the CONNECT: the filter decides on the hostname before
34
+ # any DNS lookup, so the answer is a verdict even for a host that does not exist.
35
+ _CONNECT = "curl -sS -m 10 -o /dev/null -w '%{{http_connect}}' https://{host}/"
36
+ _WILDCARD_LABEL = "twsrt-probe"
33
37
  _CANARY_DOMAINS = ("example.com", "example.org", "example.net")
34
38
  _WALK_DEPTH = 4
35
39
  _STDERR_LIMIT = 400
@@ -72,6 +76,8 @@ class Probe:
72
76
  # The .srt-settings.json key this probe verifies; derived from kind unless
73
77
  # given (the allowlist canary is a net-deny probe of allowedDomains).
74
78
  section: str = ""
79
+ # Judged by the srt proxy's CONNECT status on stdout, not by exit codes.
80
+ proxy_verdict: bool = False
75
81
 
76
82
  def __post_init__(self) -> None:
77
83
  if not self.section:
@@ -94,7 +100,8 @@ class ProbeResult:
94
100
  status: Status
95
101
  control_exit: int | None = None
96
102
  sandbox_exit: int | None = None
97
- # stderr only, last 400 chars; stdout of either run is never captured.
103
+ # stderr only, last 400 chars; stdout is never kept (a proxy-verdict probe
104
+ # reads its CONNECT status from stdout, which ends up in reason).
98
105
  control_stderr: str = ""
99
106
  sandbox_stderr: str = ""
100
107
  duration_ms: int = 0
@@ -394,6 +401,20 @@ def _concrete_write_probe(
394
401
 
395
402
 
396
403
  def _network(host: str, kind: str, expect: Expect) -> Probe:
404
+ if host.startswith("*.") and not _is_glob(host[2:]):
405
+ # *.x matches any subdomain of x (never x itself); a made-up label
406
+ # stands in for all of them. No control run: outside the sandbox the
407
+ # host does not resolve, and the proxy's answer is the witness.
408
+ concrete = f"{_WILDCARD_LABEL}.{host[2:]}"
409
+ log.debug("%s %s: probing synthetic subdomain %s", kind, host, concrete)
410
+ return Probe(
411
+ kind,
412
+ host,
413
+ _CONNECT.format(host=concrete),
414
+ expect,
415
+ control=False,
416
+ proxy_verdict=True,
417
+ )
397
418
  if _is_glob(host):
398
419
  return _skip(kind, host, expect, "wildcard domain: no concrete host")
399
420
  return Probe(kind, host, _CURL.format(host=host), expect)
@@ -473,10 +494,32 @@ def judge(
473
494
  return Status.PASS, ""
474
495
 
475
496
 
497
+ def judge_proxy(expect: Expect, code: str) -> tuple[Status, str]:
498
+ """Verdict from srt's answer to the CONNECT, as printed by curl.
499
+
500
+ 403 is srt's policy denial; any other answer means the filter let the
501
+ request through (502: the upstream did not resolve). Without an answer
502
+ (000, empty) curl never reached the proxy and nothing was judged.
503
+ """
504
+ code = code.strip()
505
+ if code in ("", "000"):
506
+ return Status.ERROR, "no proxy answer: curl did not reach the srt proxy"
507
+ blocked = code == "403"
508
+ if expect is Expect.DENY and not blocked:
509
+ return Status.FAIL, f"not blocked: proxy answered {code}"
510
+ if expect is Expect.ALLOW and blocked:
511
+ return Status.FAIL, "blocked but should be allowed: proxy answered 403"
512
+ return Status.PASS, f"proxy answered {code}"
513
+
514
+
476
515
  def run_probe(
477
516
  probe: Probe, settings: Path, timeout: float, run: Runner | None = None
478
517
  ) -> ProbeResult:
479
- """Execute control and sandboxed run; stdout is discarded, never captured."""
518
+ """Execute control and sandboxed run.
519
+
520
+ stdout is discarded, except the sandboxed run of a proxy-verdict probe:
521
+ there it carries only curl's three-digit CONNECT status.
522
+ """
480
523
  run = run or subprocess.run
481
524
  if probe.skip_reason is not None:
482
525
  return ProbeResult(probe, Status.SKIP, reason=probe.skip_reason)
@@ -502,6 +545,7 @@ def run_probe(
502
545
  ["srt", "-s", str(settings), "-c", probe.command],
503
546
  timeout,
504
547
  capture=True,
548
+ stdout=probe.proxy_verdict,
505
549
  )
506
550
  _remove(artifact)
507
551
  except subprocess.TimeoutExpired:
@@ -518,6 +562,8 @@ def run_probe(
518
562
  stderr = (completed.stderr or "")[-_STDERR_LIMIT:]
519
563
  if "sandbox_apply" in stderr:
520
564
  status, reason = Status.ERROR, "srt could not apply the sandbox"
565
+ elif probe.proxy_verdict:
566
+ status, reason = judge_proxy(probe.expect, completed.stdout or "")
521
567
  else:
522
568
  status, reason = judge(
523
569
  probe.expect,
@@ -597,7 +643,7 @@ def _srt_version(run: Runner, which: Callable[[str], str | None]) -> str:
597
643
 
598
644
 
599
645
  def _execute(
600
- run: Runner, argv: list[str], timeout: float, capture: bool
646
+ run: Runner, argv: list[str], timeout: float, capture: bool, stdout: bool = False
601
647
  ) -> subprocess.CompletedProcess:
602
648
  log.debug("exec: %s", shlex.join(argv))
603
649
  started = time.monotonic()
@@ -605,7 +651,7 @@ def _execute(
605
651
  completed = run(
606
652
  argv,
607
653
  stdin=subprocess.DEVNULL,
608
- stdout=subprocess.DEVNULL,
654
+ stdout=subprocess.PIPE if stdout else subprocess.DEVNULL,
609
655
  stderr=subprocess.PIPE if capture else subprocess.DEVNULL,
610
656
  text=True,
611
657
  timeout=timeout,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twsrt
3
- Version: 3.3.2
3
+ Version: 3.3.3
4
4
  Summary: Agent security configuration generator — translates canonical security rules into agent-specific configs
5
5
  Author-email: sysid <sysid@gmx.de>
6
6
  License-Expression: BSD-3-Clause
@@ -503,8 +503,8 @@ otherwise `default_profile` is compared and reports drift.
503
503
 
504
504
  **How `test` works.** Each effective SRT rule becomes a probe command
505
505
  (`head -c 1` on a denied file, an append-open that writes nothing on a
506
- write rule, `curl -I` per domain, plus a canary host outside the
507
- allowlist). Each probe runs twice: plainly as a control, then under
506
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
507
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
508
508
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
509
509
  sandboxed run fails, so a missing file can never count as protected. The
510
510
  probe set is derived from the compiled file, never authored: change the
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes