diff --git a/.Rbuildignore b/.Rbuildignore index 8989c62f..11922399 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -24,3 +24,15 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^mockery$ +^\.semgrepignore$ +^\.gitleaks\.toml$ +^\.yamllint\.yml$ +^trivy\.yaml$ +^\.Jules$ +^AGENTS\.md$ +^ARCHITECTURE\.md$ +^CLAUDE\.md$ +^CONTRIBUTING\.md$ +^\.jules$ +^\.markdownlint\.json$ diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6f24d72a..50423455 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,3 +11,5 @@ updates: commit-message: prefix: "chore" include: "scope" + cooldown: + default-days: 7 diff --git a/.jules/sentinel.md b/.jules/sentinel.md index a8207a48..354e2639 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-25 - 대화형 입력값 검증 강화 +**Vulnerability:** `readline()`으로 받은 입력을 `grepl("^[0-9]+$", n)`과 같은 정규식으로만 검증할 경우, 매우 긴 숫자 문자열 입력 시 `as.integer()`에서 정수 오버플로가 발생하여 `NA`가 반환되고 이는 프로세스 크래시(DoS)로 이어질 수 있음. +**Learning:** 제한된 옵션을 갖는 대화형 숫자를 검증할 때는 오버플로우 우회 공격 및 의도치 않은 캐스팅 오류를 방지하기 위해 반드시 완전 일치 검사(예: `n %in% c("1", "2")`)를 사용해야 함. +**Prevention:** 대화형 입력값에 대해 항상 허용된 값들의 집합과 완전 일치하는지 엄격히 검증하도록 함. diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..2a8f612b --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,5 @@ +{ + "MD013": false, + "MD041": false, + "MD022": false +} diff --git a/.yamllint.yml b/.yamllint.yml index 7c7978a4..15351959 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -6,3 +6,6 @@ rules: max: 140 truthy: allowed-values: ["true", "false", "on", "off"] + +ignore: | + packrat/ diff --git a/DESCRIPTION b/DESCRIPTION index f31d3e1a..c90753c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/R/aFIPC.R b/R/aFIPC.R index 62546519..118aca09 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 (n %in% c("1", "2")) { 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 (n %in% c("1", "2")) { 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 (n %in% c("1", "2")) { return(as.integer(n)) } } diff --git a/tests/testthat/test-sentinel-validation.R b/tests/testthat/test-sentinel-validation.R index 900f0ee3..79a55b95 100644 --- a/tests/testthat/test-sentinel-validation.R +++ b/tests/testthat/test-sentinel-validation.R @@ -35,3 +35,24 @@ test_that("autoFIPC validates boolean flags for newformBILOGprior, oldformBILOGp "Security Error: confirmCommonItems must be a single non-NA logical value or NULL" ) }) + +test_that("interactive readline validation prevents integer overflow coercion DOS", { + # We test this behavior by verifying that the function checkCorrect requires exact match, + # but since readline is mocked/not available here, we will test the exact match logic indirectly. + # If we replace readline with a mock that returns an invalid string, it should exhaust attempts + # and stop with an error, not crash with a condition > 1 error. + + mockery::stub(aFIPC::autoFIPC, "interactive", TRUE) + mockery::stub(aFIPC::autoFIPC, "readline", "1000000000000000000000000000000000") + + 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" + ) +})