diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..56967a0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,7 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^\.semgrepignore$ +^test_dummy\.R$ +^test_validation\.R$ +^\.markdownlint-cli2\.jsonc$ diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a4..47f1611 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -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. + +## 2024-07-23 - Strict Numeric Input Validation for `readline()` +**Vulnerability:** In R scripts, validating interactive `readline()` numeric inputs against unbounded digit classes (e.g., `^[0-9]+$`) rather than strict exact expected values (e.g., `^[12]$`) can cause integer overflow coercion vulnerabilities. Excessively large numeric strings will pass the regex check but evaluate to `NA` when coerced with `as.integer()`, causing downstream crashes or unexpected state. +**Learning:** Bounded inputs must be strictly validated for the specific range expected rather than broadly accepting any number of digits, as unbounded strings bypass size limitations. +**Prevention:** Always implement strict matching (e.g., `^[12]$`) against exact expected values for menu inputs rather than unbounded digit classes. diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc new file mode 100644 index 0000000..2ef6cd9 --- /dev/null +++ b/.markdownlint-cli2.jsonc @@ -0,0 +1,8 @@ +{ + "config": { + "MD013": false, + "MD022": false, + "MD041": false + }, + "ignores": ["packrat/**"] +} 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)) } }