Skip to content
Open
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
^\.jules(/.*)?$
^\.trivyignore\.yaml$
^trivy\.yaml$
^.semgrepignore$
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
**Vulnerability:** Unvalidated inputs passed to `if()` statements can cause process crashes (`condition has length > 1`) or unexpected coercion vulnerabilities.
**Learning:** In R, optional boolean parameters that default to `NULL` should be validated using explicit runtime type validation (e.g., `if (!is.null(flag) && (!is.logical(flag) || length(flag) != 1 || is.na(flag)))`).
**Prevention:** Always implement explicit runtime type validation for optional boolean parameters.

## 2025-02-12 - Fix missing value where TRUE/FALSE needed vulnerability
**Vulnerability:** Weak regex `^[0-9]+$` allowing extremely large strings to be interpreted as numbers in `readline()` inputs, causing `NA` coercion by `as.integer()` and crashing `if()` blocks (`missing value where TRUE/FALSE needed`).
**Learning:** When reading integer inputs via `readline()` in R, avoid weak regex validation like `^[0-9]+$` as large numbers coerce to `NA` via `as.integer()`, breaking `if` conditions and causing unhandled exceptions. Use strictly bounded exact-match regex like `^[12]$` to prevent coercion crashes and DoS vulnerabilities.
**Prevention:** Always bound expected integer inputs and use strict validation like `^[12]$` when expecting a finite set of answers.
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ Applies to every agent (Claude, Codex, Cursor, opencode, ...) working in this re
psychometrics literature. Commit paper PDFs only when redistribution is
permitted; otherwise cite, link, and summarize.
<!-- END cwl-agent-guidance -->

Strix uses the zero-cost `orchestrator/free` route.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Description: Automates fixed item parameter linking for test linking under
the item response theory paradigm using mirt package estimates.
License: GPL-3 | file LICENSE
Imports: mirt, methods
Suggests: testthat (>= 3.0.0)
Suggests: testthat (>= 3.0.0), mockery
Encoding: UTF-8
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
6 changes: 3 additions & 3 deletions R/aFIPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ autoFIPC <-
}
for (attempt in seq_len(3)) {
n <- readline(prompt = "Is it correct? (1: Yes 2: No) : ")
if (grepl("^[0-9]+$", n)) {
if (grepl("^[12]$", n)) {
return(as.integer(n))
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ autoFIPC <-
readline(
prompt = "Do you want to use default BILOG-MG priors for oldform Data? (1: Yes 2: No) : "
)
if (grepl("^[0-9]+$", n)) {
if (grepl("^[12]$", n)) {
return(as.integer(n))
}
}
Expand Down Expand Up @@ -390,7 +390,7 @@ autoFIPC <-
readline(
prompt = "Do you want to use default BILOG-MG priors for newform Data? (1: Yes 2: No) : "
)
if (grepl("^[0-9]+$", n)) {
if (grepl("^[12]$", n)) {
return(as.integer(n))
}
}
Expand Down
2 changes: 0 additions & 2 deletions test_dummy.R

This file was deleted.

3 changes: 0 additions & 3 deletions test_validation.R

This file was deleted.

18 changes: 18 additions & 0 deletions tests/testthat/test-sentinel-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ test_that("autoFIPC validates boolean flags for newformBILOGprior, oldformBILOGp
"Security Error: confirmCommonItems must be a single non-NA logical value or NULL"
)
})

test_that("autoFIPC handles large invalid inputs correctly in interactive sessions without crashing", {
# Using mockery to stub base functions properly in the context of autoFIPC
mockery::stub(aFIPC::autoFIPC, 'interactive', function() TRUE)
mockery::stub(aFIPC::autoFIPC, 'readline', mockery::mock("99999999999999999999", "99999999999999999999", "99999999999999999999"))

# Should stop after 3 attempts due to the new regex validation correctly ignoring large numbers
expect_error(
aFIPC::autoFIPC(
newformXData = data.frame(A=1),
oldformYData = data.frame(A=2),
newformCommonItemNames = c('A'),
oldformCommonItemNames = c('A'),
confirmCommonItems = NULL
),
"Too many invalid common item confirmation attempts"
)
})
Loading