From 2ead3e646c582be0dcd2ba9154dffdab7df35ccb Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 4 Jul 2026 21:16:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[security?= =?UTF-8?q?=20improvement]=20=EC=99=B8=EB=B6=80=20API=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=20URL=20=EC=8A=A4=ED=82=B4=20=EA=B2=80=EC=A6=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `scripts/ci/noema_review_gate.py`의 `urllib.request.urlopen`을 사용하여 `NOEMA_LLM_API_URL`을 호출할 때 `http://` 또는 `https://` 스킴을 명시적으로 검증하도록 수정했습니다. 이를 통해 `file://` 스킴 등을 통한 SSRF 및 로컬 파일 포함 취약점을 방지합니다. 또한 `.jules/sentinel.md`에 관련된 학습 내용을 추가했습니다. --- .jules/sentinel.md | 4 ++++ scripts/ci/noema_review_gate.py | 4 +++- tests/test_noema_review_gate.py | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 9133bba1..a945caee 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -22,3 +22,7 @@ **Vulnerability:** Server-Side Request Forgery (SSRF) / Local File Inclusion **Learning:** Functions that fetch URLs provided via user inputs (e.g., `wait_for_url` fetching `--backend-ready-url` in CI scripts) can inadvertently read local files if they do not validate the scheme. Python's `urllib.request.urlopen` supports `file://` schemes, allowing attackers to access arbitrary file contents from the host machine or sandbox if they can control the URL parameter. **Prevention:** Always validate URL inputs to restrict allowed schemes. Check that URLs explicitly start with `http://` or `https://` before fetching them with standard libraries like `urllib`. +## 2026-07-04 - Fix unvalidated URL scheme in NOEMA_LLM_API_URL +**Vulnerability:** urllib.request.urlopen in scripts/ci/noema_review_gate.py was calling the URL provided by NOEMA_LLM_API_URL environment variable without validating that it uses http:// or https:// scheme, potentially allowing file:// or other unexpected schemes to be used. +**Learning:** In Python, urllib.request.urlopen will happily read local files if provided with a file:// scheme. This could lead to a Server-Side Request Forgery (SSRF) or local file read vulnerability if the environment variable is attacker-controlled or misconfigured. This expands our previous understanding of URL scheme validation to environment variables. +**Prevention:** Always validate that URLs to be requested by urllib or other HTTP clients strictly start with http:// or https://, especially when the URL originates from environment variables or external configuration. diff --git a/scripts/ci/noema_review_gate.py b/scripts/ci/noema_review_gate.py index 1e4661b7..d57f6561 100644 --- a/scripts/ci/noema_review_gate.py +++ b/scripts/ci/noema_review_gate.py @@ -267,6 +267,8 @@ def call_llm(repo: str, number: int, pr: dict[str, Any], diff: str, truncated: b if not api_url or not api_key: print("Noema LLM review unavailable: NOEMA_LLM_API_URL or NOEMA_LLM_API_KEY is not configured.") return None + if not (api_url.startswith("http://") or api_url.startswith("https://")): + raise ValueError(f"Invalid NOEMA_LLM_API_URL scheme: {api_url}") prompt = { "role": "user", @@ -304,7 +306,7 @@ def call_llm(repo: str, number: int, pr: dict[str, Any], diff: str, truncated: b }, method="POST", ) - with urllib.request.urlopen(request, timeout=120) as response: + with urllib.request.urlopen(request, timeout=120) as response: # nosec B310 - scheme validated above raw = response.read().decode("utf-8") data = json.loads(raw) content = (((data.get("choices") or [{}])[0].get("message") or {}).get("content") or "").strip() diff --git a/tests/test_noema_review_gate.py b/tests/test_noema_review_gate.py index 0b333ab3..aa9c5c04 100644 --- a/tests/test_noema_review_gate.py +++ b/tests/test_noema_review_gate.py @@ -214,6 +214,11 @@ def fake_urlopen(request, timeout): assert seen["url"] == "https://llm.example.test/chat" assert seen["body"]["model"] == "review-model" + monkeypatch.setenv("NOEMA_LLM_API_URL", "file:///etc/passwd") + with pytest.raises(ValueError, match="Invalid NOEMA_LLM_API_URL scheme: file:///etc/passwd"): + noema.call_llm("owner/repo", 1, pr, "diff", True) + + monkeypatch.setenv("NOEMA_LLM_API_URL", "https://llm.example.test/chat") monkeypatch.setattr( noema.urllib.request, "urlopen",