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
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
**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-28 - Fix integer coercion DoS vulnerability via interactive readline
**Vulnerability:** Interactive `readline()` prompts parsing integers via `as.integer()` were loosely validated with `^[0-9]+$`. Large inputs coerced to `NA`, breaking `if` conditionals and causing crashes (Denial of Service).
**Learning:** Weak regex for integers is dangerous since R's 32-bit limits can easily cause silent `NA` generation upon coercion.
**Prevention:** Strictly bound validations for menu prompts (e.g., `^[12]$` instead of `^[0-9]+$`).
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
10 changes: 10 additions & 0 deletions tests/testthat/test-autoFIPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ test_that("autoFIPC validates input types securely", {
"Security Error: tryEM must be a single non-NA logical value"
)
})

test_that("autoFIPC securely restricts input via regex for prompts", {
expect_true(grepl("^[12]$", "1"))
expect_true(grepl("^[12]$", "2"))
expect_false(grepl("^[12]$", "3"))
expect_false(grepl("^[12]$", "12"))
expect_false(grepl("^[12]$", "0"))
expect_false(grepl("^[12]$", "abc"))
expect_false(grepl("^[12]$", ""))
Comment on lines +93 to +100

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ” Prompt tests bypass production code

These assertions duplicate the regex instead of invoking autoFIPC(). They can pass after a prompt diverges and reintroduces the coercion failure.

Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

})
Loading