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
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
^\.jules(/.*)?$
^\.trivyignore\.yaml$
^trivy\.yaml$
^\.semgrepignore$
^test_dummy\.R$
^test_validation\.R$
23 changes: 20 additions & 3 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Sentinel Journal

## 2024-07-12 - Fix missing parameter validations
**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.

**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.

## 2024-07-13 - Fix integer overflow coercion vulnerability in readline input validation

**Vulnerability:** Weak regex `^[0-9]+$` allows excessive numeric strings that
coerce to `NA` inside `as.integer()`, which can lead to unhandled process crashes.
**Learning:** `readline()` validation should strictly match exact expected bounds
for interactive prompts instead of open-ended digit validation to prevent
integer overflow coercion.
**Prevention:** Strictly match against exact expected values (e.g., `^[12]$`)
instead of unbounded digit classes when validating user inputs mapped to integers.
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
21 changes: 21 additions & 0 deletions tests/testthat/test-autoFIPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,24 @@ test_that("autoFIPC validates input types securely", {
"Security Error: tryEM must be a single non-NA logical value"
)
})

test_that("binary prompt choices reject overflow and malformed values", {
expect_identical(aFIPC:::parseBinaryChoice("1"), 1L)
expect_identical(aFIPC:::parseBinaryChoice("2"), 2L)

invalid_values <- list(
"0",
"3",
"01",
"2147483648",
paste0(strrep("9", 10000L)),
"1\n2",
"",
NA_character_,
c("1", "2"),
1
)
for (value in invalid_values) {
expect_identical(aFIPC:::parseBinaryChoice(value), NA_integer_)
}
})
Loading