This document describes the threat model, v0.2.0 and v0.5.0 red-team audit findings, and concrete mitigations implemented in statci (R/security.R and across all verification engines).
Reporting a Vulnerability
Please report security issues privately via the repository issue tracker or email (marcus.harris.uconn@gmail.com).
v0.5.0 Independent Peer Red-Team Audit Findings & Mitigations
Following an independent adversarial red-team review of statci v0.4.0, all 20 findings (6 High, 10 Medium, 4 Low) were remediated and locked down with permanent regression tests in tests/testthat/test-peer-redteam.R:
1. Symlinked Ancestor Write Escape & Dangling Symlink Rejection (validate_contained_dest())
-
Finding: On POSIX platforms,
normalizePath(..., mustWork = FALSE)does not resolve symlinked ancestor directories when a leaf file or nested subdirectory does not yet exist, allowinguse_statci_github_action(file = "link/ci.yaml")andstatci_audit_project()(report.output_dir: link/sub) to write files outside the project root. -
Mitigation (
R/security.R):validate_contained_dest()now walks every path component incrementally from the canonicalizedroot_dir, inspectingSys.readlink()at each segment, rejecting dangling symlinks, and verifying that every existing canonicalized ancestor remains strictly insideroot_dir.
2. External Directory Read & Code-Snippet Leakage via lint.paths (statci_audit_project())
-
Finding:
.statci.ymllint.pathsentries pointing to symlinks targeting directories outside the project root could causestatci_audit_project()to scan external files and embed code snippets in HTML/Markdown/SARIF reports. -
Mitigation (
R/config.R): Everylint.pathsentry is now validated throughvalidate_contained_dest(root_norm, lp, arg = "lint.paths", allow_root = TRUE)before any directory scan executes.
3. Unified Diff Hunk-Termination Bypass & Safe Path Decoding (stat_lint_diff())
-
Finding: Added lines beginning with
++(emitted as+++ ...) or deleted lines beginning with--(emitted as--- ...) inside an active unified diff hunk previously flippedin_hunk <- FALSE, silently dropping all subsequent added lines in the hunk. Additionally, Git octal-quoted UTF-8 paths ("b/caf\303\251.R") and spaces/parentheses in filenames caused skips or aborts. -
Mitigation (
R/lint-diff.R,R/security.R):parse_unified_diff()now tracks exact remaining old/new hunk line counts (rem_old,rem_new) from@@ -a,b +c,d @@headers so active hunk lines never terminate parsing; invokesgit -c core.quotepath=false diff; decodes C-quoted octal escapes for rawdiff_text; stripsb/only on Git/a/diffs; and validates diff paths withvalidate_safe_diff_rel_path()(blocking control bytes,.., absolute/drive/home paths, backslashes, and symlink escapes while permitting spaces, parentheses, and UTF-8).
4. Markdown Multiverse Report HTML/XSS Neutralization (render_statci_report())
-
Finding:
build_markdown_report()interpolated multiversems$parameterdirectly inside backticks, allowing payloads containing backticks and<script>tags to break out and inject raw HTML into Markdown reports and$GITHUB_STEP_SUMMARY. -
Mitigation (
R/report.R):ms$parameteris now passed throughmd_escape_cell()with backticks neutralized before Markdown interpolation.
5. SARIF 2.1.0 Schema Compliance, RFC-3986 URI Encoding & Host Path Stripping (export_statci_sarif())
-
Finding:
NAline/column values serialized as"startLine": "NA";#,?,%, and spaces were unencoded inartifactLocation.uri; and omittingbase_urileaked absolute host filesystem paths intouriandprimaryLocationLineHash. -
Mitigation (
R/sarif.R):startLineandstartColumnare coerced strictly to positive integers (>= 1L); every URI segment is RFC-3986 percent-encoded; and absolute paths without a matchingbase_uriare relativized togetwd()or reduced tobasename()so host directories are never leaked.
6. Strict YAML Config Validation & AST/Auditor Integrity Hardening
-
Config (
R/config.R): Rejects top-level and section YAML sequences (unnamed lists), non-finitemanuscript.tol_extra(.inf/.na), andNAbooleans (warn_rounding: .na,check_internal: .na). -
AST Linter (
R/lint-parser.R,R/lint-rules.R): Closed pipe (|>/%>%) and lexical-scoping evasions across 10 rules, eliminated false positives on positionalpredict(fit, test_df)and scalar matrix lookups (m[i, 1]), and fixed Quarto/Rmd doc-fence nesting,~~~{r}tilde chunks, and blank lines before#| eval: false. -
Auditors (
R/audit-*.R): Enforced reserved/duplicate fork name checks, pre-expand.grid()max_specsguard, andNA-level preservation inaudit_multiverse(); confidence-level-aware CI arithmetic, impossiblep/R^2bounds, GFM outer-pipe-free tables, and regex-safe model matching inaudit_manuscript(); strictNAand out-of-[0,1]p-value handling inaudit_power_curve(); collinear/NA-cluster/numeric-cluster resilience inaudit_sensitivity(); degenerate SE/CI failure checks inaudit_estimator(); and consistent draw-count enforcement inaudit_sbc().
v0.2.0 Red-Team Audit Findings & Mitigations
1. GitHub Actions Workflow, Shell & R Code Injection (use_statci_github_action())
-
Vulnerability found in v0.1.0: Unvalidated user strings (
r_version,lint_paths,manuscript,models_path,audit_script,report_dir,file) were interpolated directly into generated YAML scalars andrun:blocks. Payloads such asr_version = "release\n - run: curl ..."could inject new workflow steps,lint_paths = 'R"); system("id"); c("R'could inject arbitrary R execution, andfile = "../../outside.yaml"permitted path traversal outside the project root. -
Mitigation in v0.2.0 (
R/security.R,R/github-action.R):- Strict allowlist validators (
validate_r_version(),validate_branch_names(),validate_safe_rel_path(),validate_contained_dest(),safe_yaml_scalar()) reject control characters, newlines, quotes, backslashes,..traversal segments, absolute/home paths, and shell/YAML/R metacharacters. -
Zero untrusted string interpolation into
run:blocks: All validated parameters are passed via workflowenv:variables (STATCI_LINT_PATHS,STATCI_MANUSCRIPT,STATCI_MODELS_PATH,STATCI_REPORT_DIR,STATCI_FAIL_ON,STATCI_AUDIT_SCRIPT) and read viaSys.getenv()inside static R code (orRscript --vanilla "$STATCI_AUDIT_SCRIPT"). - Workflow actions use vetted major tags (
actions/checkout@v4withpersist-credentials: false,r-lib/actions/setup-r@v2,r-lib/actions/setup-r-dependencies@v2,actions/upload-artifact@v4) under minimalpermissions: contents: read.
- Strict allowlist validators (
2. HTML Report XSS & Markdown HTML Injection (render_statci_report())
-
Audit scope: Malicious filenames, rule IDs, lint messages, code snippets, model names, term names, sensitivity details, and report titles containing
<script>,<img onerror=...>,<svg onload=...>, or control characters. -
Mitigation in v0.2.0 (
R/security.R,R/report.R):- Centralized
html_escape_strict()strips non-printable ASCII control bytes and escapes&,<,>,", and'viahtmltools::htmlEscape(..., attribute = TRUE)across every rendered field. - Added a strict Content-Security-Policy header (
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline';">) to standalone HTML5 reports as defense-in-depth against script execution. - Centralized
md_escape_cell()escapes<,>,&,|, newlines, and control bytes in Markdown table cells so untrusted inputs cannot inject raw HTML into$GITHUB_STEP_SUMMARYor PR comments.
- Centralized
3. File Path & Symlink Traversal (stat_lint(), stat_lint_dir(), audit_manuscript())
- Audit scope: Control characters, directories passed where files are expected, dangling symlinks, and symlinks inside scanned directories pointing outside the project or model directory.
-
Mitigation in v0.2.0 (
R/security.R,R/lint-engine.R,R/audit-manuscript.R):-
validate_existing_file()andvalidate_existing_dir()reject control bytes, broken symlinks, and mismatched file/directory types. -
is_safe_contained_file()verifies resolved canonical paths stay strictly inside scanned directories (stat_lint_dir()skips symlink escapes;audit_manuscript()aborts if a.rdsdirectory contains a symlink escaping the model directory).
-
4. ReDoS Defense in Manuscript Prose Parser (audit_manuscript())
-
Audit scope: Pathological long prose strings (e.g., 25,000+ repeated digits, spaces,
*,$, or unclosed<!-- statci:/CI [delimiters) causing catastrophic PCRE backtracking. -
Mitigation in v0.2.0 (
R/audit-manuscript.R):- Replaced unbounded nested quantifiers in
parse_tag_attrs(),normalize_prose_line(),span_pat,comment_pat, and all claim patterns (ci_brack_pat,ci_to_pat, etc.) with strictly linear-time bounded-quantifier regexes plus a 20,000-byte per-line scan cap. - Verified sub-50ms execution on adversarial ReDoS inputs in
tests/testthat/test-adversarial-security.R.
- Replaced unbounded nested quantifiers in
5. AST Linter Anti-Evasion Hardening (R/lint-parser.R, R/lint-rules.R)
-
Evasions found & fixed in v0.2.0:
-
Fake
# statci-ignoreinside string literals (x <- rnorm(5); s <- "# statci-ignore") bypassed linting because v0.1.0 scanned raw lines with regex. Nowparse_suppressions_ast()extracts directives strictly from parsed XML<COMMENT>AST tokens. -
R 4.1+ shorthand lambdas
\(x)bypassedglobal_seed_override_in_fnand false-positived inunseeded_randomnessbecausexmlparsedataemits<OP-LAMBDA>rather than<FUNCTION>. All function-scope queries now matchexpr[FUNCTION or OP-LAMBDA]. -
Comments/strings spoofing convergence or seed restoration (
# TODO: check isSingular,# $convergence,x <- ".Random.seed") bypassedmissing_convergence_checkandglobal_seed_override_in_fn. Both rules now inspect AST nodes (SYMBOL_FUNCTION_CALL,SLOT,OP-DOLLAR,LBB, andon.exit()AST symbols) exclusively. -
Non-evaluated Quarto/Rmd pseudocode chunks (
eval: false/eval = FALSE) no longer produce spuriousparse_errorfindings if they contain illustrative non-R syntax. - Added built-in rule #14
duplicate_parallel_seedcatching constantset.seed(42)inside loops and parallel workers.
-
Fake
