Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.
Python agent-evaluationagent-pluginsagent-securityagent-skillsagentic-aibenchmarkci-templatesclaude-codecodexevaluateevaluationharnesspluginplugin-evaluationsecurity-scannerskill-evalskill-evaluationskill-evaluatorskill-gap-analysisskills
fix(tier3): make log JWT redaction linear-time (#176)
Narendran Raghavane639eceb6f59
diff --git a/.gitleaks.toml b/.gitleaks.tomlindex 41ff4d10..df15291c 100644--- a/.gitleaks.toml+++ b/.gitleaks.toml@@ -9,9 +9,3 @@ condition = "AND"targetRules = ["generic-api-key"]regexes = ['''^sk-AbCdEf1234567890$''']paths = ['''^tests/test_tier3_(progress|result_display)\.py$''']--[[allowlists]]-description = "Synthetic JWT and private-key fixtures in the first revision of the redaction tests (PR #172); the file now assembles them from split literals"-condition = "AND"-commits = ["97a0616f7786fc5b10c49aa24b0a55f8d446bcab"]-paths = ['''^tests/test_redaction_assignments\.py$''']diff --git a/src/skillevaluator/tier3/eval_core/secret_redaction.py b/src/skillevaluator/tier3/eval_core/secret_redaction.pyindex 15743cbe..53b7a9a4 100644--- a/src/skillevaluator/tier3/eval_core/secret_redaction.py+++ b/src/skillevaluator/tier3/eval_core/secret_redaction.py@@ -21,7 +21,20 @@ LOG_SK_RE = re.compile(r"(?<![A-Za-z0-9_-])sk-[a-zA-Z0-9_-]{8,}|sk-" + _GLUED_KELOG_NVAPI_RE = re.compile(r"(?<![A-Za-z0-9_-])nvapi-[a-zA-Z0-9_-]{8,}|nvapi-" + _GLUED_KEY_BODY)LOG_CRSR_RE = re.compile(r"(?<![A-Za-z0-9_-])crsr_[a-f0-9]{16,}")OPENSHIFT_TOKEN_RE = re.compile(r"(?<![A-Za-z0-9_-])sha256~[A-Za-z0-9._~-]+")-LOG_JWT_RE = re.compile(r"\beyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\b")+# A JWT used to start at any ``\beyJ``, so in a run of JWT characters such as+# "eyJ-" * n every "-eyJ" was a start, and each start scanned to the end of the+# run looking for ".". Now a match starts only at the beginning of a run. The part+# of the run before its first ``\beyJ`` is captured as ``lead`` and written back+# unchanged, which keeps JWTs glued to a "-" (x-eyJ...) redacted. Later starts in+# the same run are never tried: their first segment reaches the same "." with+# fewer characters, so they could only fail where the first start failed. ``lead``+# stops at the first ``\beyJ`` and every earlier offset fails ``\beyJ``, so+# backtracking into it is cheap. No atomic groups or possessive quantifiers: the+# Harbor verifier copy runs on the task image's python3, which may predate 3.11.+LOG_JWT_RE = re.compile(+ r"(?<![A-Za-z0-9_-])(?P<lead>(?:(?!\beyJ)[A-Za-z0-9_-])*)"+ r"\beyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\b"+)# GitHub classic (ghp_/gho_/ghu_/ghs_/ghr_) and fine-grained (github_pat_) tokens.# Single bounded character classes keep both patterns linear.LOG_GITHUB_TOKEN_RE = re.compile(r"\bgh[pousr]_[A-Za-z0-9]{36,255}\b")@@ -43,4 +56,6 @@ def redact_secrets_in_log_line(line = LOG_GITHUB_TOKEN_RE.sub(lambda match: match.group()[:4] + "<redacted>", line)line = LOG_GITHUB_PAT_RE.sub("github_pat_<redacted>", line)line = OPENSHIFT_TOKEN_RE.sub("sha256~<redacted>", line)- return LOG_JWT_RE.sub("jwt-<redacted>", line)+ if "eyJ" not in line: # every JWT match contains "eyJ"; skip the scan on ordinary lines+ return line+ return LOG_JWT_RE.sub(r"\g<lead>jwt-<redacted>", line)diff --git a/src/skillevaluator/tier3/harbor/templates/eval.py b/src/skillevaluator/tier3/harbor/templates/eval.pyindex e466ad66..af47181a 100644--- a/src/skillevaluator/tier3/harbor/templates/eval.py+++ b/src/skillevaluator/tier3/harbor/templates/eval.py@@ -190,7 +190,20 @@ LOG_SK_RE = re.compile(r"(?<![A-Za-z0-9_-])sk-[a-zA-Z0-9_-]{8,}|sk-" + _GLUED_KELOG_NVAPI_RE = re.compile(r"(?<![A-Za-z0-9_-])nvapi-[a-zA-Z0-9_-]{8,}|nvapi-" + _GLUED_KEY_BODY)LOG_CRSR_RE = re.compile(r"(?<![A-Za-z0-9_-])crsr_[a-f0-9]{16,}")OPENSHIFT_TOKEN_RE = re.compile(r"(?<![A-Za-z0-9_-])sha256~[A-Za-z0-9._~-]+")-LOG_JWT_RE = re.compile(r"\beyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\b")+# A JWT used to start at any ``\beyJ``, so in a run of JWT characters such as+# "eyJ-" * n every "-eyJ" was a start, and each start scanned to the end of the+# run looking for ".". Now a match starts only at the beginning of a run. The part+# of the run before its first ``\beyJ`` is captured as ``lead`` and written back+# unchanged, which keeps JWTs glued to a "-" (x-eyJ...) redacted. Later starts in+# the same run are never tried: their first segment reaches the same "." with+# fewer characters, so they could only fail where the first start failed. ``lead``+# stops at the first ``\beyJ`` and every earlier offset fails ``\beyJ``, so+# backtracking into it is cheap. No atomic groups or possessive quantifiers: the+# Harbor verifier copy runs on the task image's python3, which may predate 3.11.+LOG_JWT_RE = re.compile(+ r"(?<![A-Za-z0-9_-])(?P<lead>(?:(?!\beyJ)[A-Za-z0-9_-])*)"+ r"\beyJ[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\b"+)# GitHub classic (ghp_/gho_/ghu_/ghs_/ghr_) and fine-grained (github_pat_) tokens.# Single bounded character classes keep both patterns linear.LOG_GITHUB_TOKEN_RE = re.compile(r"\bgh[pousr]_[A-Za-z0-9]{36,255}\b")@@ -208,7 +221,9 @@ def redact_secrets_in_log_line(line, *, extra_secret_values=None):line = LOG_GITHUB_TOKEN_RE.sub(lambda match: match.group()[:4] + "<redacted>", line)line = LOG_GITHUB_PAT_RE.sub("github_pat_<redacted>", line)line = OPENSHIFT_TOKEN_RE.sub("sha256~<redacted>", line)- return LOG_JWT_RE.sub("jwt-<redacted>", line)+ if "eyJ" not in line: # every JWT match contains "eyJ"; skip the scan on ordinary lines+ return line+ return LOG_JWT_RE.sub(r"\g<lead>jwt-<redacted>", line)_DESTRUCTIVE_PATTERNS = [diff --git a/tests/tier3/test_log_jwt_redaction.py b/tests/tier3/test_log_jwt_redaction.pynew file mode 100644index 00000000..b1b105c7--- /dev/null+++ b/tests/tier3/test_log_jwt_redaction.py@@ -0,0 +1,96 @@+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.+# SPDX-License-Identifier: Apache-2.0++"""JWTs are masked in Tier 3 log lines on the host and in the Harbor verifier, in linear time."""++from __future__ import annotations++import importlib.util+import time+from pathlib import Path++import pytest++from skillevaluator.tier3.eval_core.secret_redaction import redact_secrets_in_log_line++_TEMPLATE = (+ Path(__file__).resolve().parents[2] / "src" / "skillevaluator" / "tier3" / "harbor" / "templates" / "eval.py"+)+++def _load_template_module():+ spec = importlib.util.spec_from_file_location("harbor_template_eval_log_jwt", _TEMPLATE)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++eval_template = _load_template_module()++REDACTORS = pytest.mark.parametrize(+ "redact",+ [redact_secrets_in_log_line, eval_template.redact_secrets_in_log_line],+ ids=["host", "template"],+)+++def _fixture_secret(*parts: str) -> str:+ """Build committed fake secrets from pieces so static scanners do not flag them."""+ return "".join(parts)+++# Synthetic JWT: the {"alg":"HS256","typ":"JWT"} header, a sample payload and a fake signature.+_HEADER = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"+_PAYLOAD = "eyJzdWIiOiIxMjM0NTY3ODkwIn0"+_JWT = _fixture_secret(_HEADER, ".", _PAYLOAD, ".", "c3ludGhldGljLXNpZ25hdHVyZS1ub3QtcmVhbA")+_SHORT_SIGNATURE_JWT = _fixture_secret(_HEADER, ".", _PAYLOAD, ".", "c" * 19)+++@REDACTORS+ ("line", "expected"),+ [+ pytest.param(_JWT, "jwt-<redacted>", id="whole-line"),+ pytest.param(f"token {_JWT} ok", "token jwt-<redacted> ok", id="after-space"),+ pytest.param(f'"{_JWT}"', '"jwt-<redacted>"', id="quoted"),+ pytest.param(f"id_token={_JWT}", "id_token=jwt-<redacted>", id="after-equals"),+ pytest.param(f"Authorization: Bearer {_JWT}", "Authorization: Bearer jwt-<redacted>", id="after-bearer"),+ pytest.param(f"x-{_JWT}", "x-jwt-<redacted>", id="glued-to-dash"),+ pytest.param(f"abc-def-{_JWT}", "abc-def-jwt-<redacted>", id="glued-to-dashed-run"),+ pytest.param(f"é-{_JWT}", "é-jwt-<redacted>", id="dash-after-non-ascii-letter"),+ pytest.param(f"eyJ-eyJ-{_JWT}", "jwt-<redacted>", id="run-starts-with-eyJ"),+ pytest.param(f"x-eyJshort.{_JWT}", "x-eyJshort.jwt-<redacted>", id="after-short-run"),+ pytest.param(f"{_JWT}.{_JWT}", "jwt-<redacted>.jwt-<redacted>", id="two-dotted"),+ pytest.param(f"{_JWT} {_JWT}", "jwt-<redacted> jwt-<redacted>", id="two-spaced"),+ pytest.param(f"{_JWT}-", "jwt-<redacted>-", id="trailing-dash-kept"),+ pytest.param(f"a_{_JWT}", f"a_{_JWT}", id="glued-to-underscore-kept"),+ pytest.param(f"x{_JWT}", f"x{_JWT}", id="glued-to-letter-kept"),+ pytest.param(f"é{_JWT}", f"é{_JWT}", id="glued-to-non-ascii-letter-kept"),+ pytest.param(_SHORT_SIGNATURE_JWT, _SHORT_SIGNATURE_JWT, id="short-signature-kept"),+ ],+)+def test_log_jwt_is_redacted_by_position(redact, line, expected):+ assert redact(line) == expected+++# Near misses for the former ``\beyJ[A-Za-z0-9_-]{20,}\.…`` pattern. It could start+# after every "-" of one long run of JWT characters, and each start rescanned the+# rest of the run, then the following segments. Each 256 KB line took 11 s to 52 s+# with that pattern and takes about 25 ms now. None of them contains a JWT.+_ADVERSARIAL_LINES = {+ "eyJ-after-every-dash": "eyJ-" * 65_536,+ "dash-before-every-eyJ": "-eyJ" * 65_536,+ "long-second-segment": "eyJ-" * 32_768 + "." + "a" * 131_072,+ "third-segment-without-boundary": "eyJ-" * 32_768 + "." + "a" * 20 + "." + "-" * 131_072,+}+++@REDACTORS[email protected]("line", list(_ADVERSARIAL_LINES.values()), ids=list(_ADVERSARIAL_LINES))+def test_log_jwt_redaction_is_fast_on_adversarial_lines(redact, line):+ started = time.perf_counter()+ redacted = redact(line)+ elapsed = time.perf_counter() - started++ assert elapsed < 1.0, f"redaction took {elapsed:.2f}s on a {len(line)}-character line"+ assert redacted == line