From de02dc304fbb46c0ca46e4bcc18de129f817a6f8 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 19:02:07 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITIC?= =?UTF-8?q?AL]=20Fix=20integer=20overflow=20coercion=20vulnerability=20in?= =?UTF-8?q?=20readline=20input=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/sentinel.md | 4 ++++ R/aFIPC.R | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a4..67f49b8 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -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-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. diff --git a/R/aFIPC.R b/R/aFIPC.R index 6254651..918e19b 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -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)) } } @@ -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)) } } @@ -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)) } } From 307fc62ddd36a0bd4a79a12d8299c2b24f3f30e3 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 19:08:56 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITIC?= =?UTF-8?q?AL]=20Fix=20integer=20overflow=20coercion=20vulnerability=20in?= =?UTF-8?q?=20readline=20input=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/sentinel.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 67f49b8..1108d62 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -1,8 +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. + +**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. From 79b2ec7127180f107c0d0762263ff44894486cf4 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 19:19:45 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITIC?= =?UTF-8?q?AL]=20Fix=20integer=20overflow=20coercion=20vulnerability=20in?= =?UTF-8?q?=20readline=20input=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..28b2d85 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^\.semgrepignore$ +^test_dummy\.R$ +^test_validation\.R$ From 05c072163e25c5c870034c08ff937fb6d0c2a120 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 19:24:50 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITIC?= =?UTF-8?q?AL]=20Fix=20integer=20overflow=20coercion=20vulnerability=20in?= =?UTF-8?q?=20readline=20input=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 146c9a601a8f0bfadc8cbc00dc87d3ac894f73d9 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Sun, 9 Aug 2026 11:27:04 +0900 Subject: [PATCH 5/5] test(security): cover bounded binary prompt parsing --- tests/testthat/test-autoFIPC.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testthat/test-autoFIPC.R b/tests/testthat/test-autoFIPC.R index 13cecd9..c1be0b3 100644 --- a/tests/testthat/test-autoFIPC.R +++ b/tests/testthat/test-autoFIPC.R @@ -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_) + } +})