-
Notifications
You must be signed in to change notification settings - Fork 0
fix(webhook): enforce URL admission at storage boundary #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
3
commits into
develop
Choose a base branch
from
sentinel/ssrf-webhook-validation-1491454139714134853
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
|
|
||
| from appguardrail_core.controlplane import connect, create_org, set_webhook | ||
|
|
||
|
|
||
| def test_set_webhook_rejects_loopback_before_persistence() -> None: | ||
| conn = connect(":memory:") | ||
| org_id, _ = create_org(conn, "ssrf-contract") | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid webhook URL"): | ||
| set_webhook(conn, org_id, "http://127.0.0.1:8080/internal") | ||
|
|
||
| row = conn.execute( | ||
| "SELECT webhook_url FROM orgs WHERE id = ?", (org_id,) | ||
| ).fetchone() | ||
| assert row["webhook_url"] is None | ||
|
|
||
|
|
||
| def test_set_webhook_allows_explicit_clear_without_url_validation() -> None: | ||
| conn = connect(":memory:") | ||
| org_id, _ = create_org(conn, "clear-contract") | ||
|
|
||
| set_webhook(conn, org_id, None) | ||
|
|
||
| row = conn.execute( | ||
| "SELECT webhook_url FROM orgs WHERE id = ?", (org_id,) | ||
| ).fetchone() | ||
| assert row["webhook_url"] is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
빈 문자열을 해제 값으로 처리해야 합니다.
기존
url or None정규화와Set (or clear)계약에 따르면""은 웹훅 해제 값으로 사용할 수 있습니다. 현재 코드는_is_safe_url("")가False를 반환하므로 데이터베이스 갱신 전에ValueError를 발생시킵니다. 빈 문자열만None으로 정규화한 뒤 검증하고, 다른 비문자열 값은 계속 거부하십시오.수정 예시
def set_webhook(conn: sqlite3.Connection, org_id: int, url: "str | None") -> None: """Set (or clear) the org's drift-alert webhook URL.""" - if url is not None and not _is_safe_url(url): + normalized_url = None if isinstance(url, str) and url == "" else url + if normalized_url is not None and not _is_safe_url(normalized_url): raise ValueError("Invalid webhook URL") - conn.execute("UPDATE orgs SET webhook_url = ? WHERE id = ?", (url or None, org_id)) + conn.execute("UPDATE orgs SET webhook_url = ? WHERE id = ?", (normalized_url, org_id))🤖 Prompt for AI Agents
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: ContextualWisdomLab/appguardrail
Length of output: 21321
SSRF (CWE-918): Server-Side Request Forgery (SSRF)
Reachability: External · Exploitability: Moderate
DNS 재바인딩 방어를 구현하십시오.
_is_safe_url은 검증 시점의 주소만 확인합니다.opener.open은 연결 시 DNS를 다시 해석하므로, 검증된 공인 주소가 사설 주소로 변경될 수 있습니다. DNS 결과에 연결을 고정하거나 egress 정책으로 사설망 목적지를 차단하고 회귀 테스트를 추가하십시오.🤖 Prompt for AI Agents