Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b4254a9
fix(fuzz): surface Atheris crash reproducers in the run log
claude Jul 30, 2026
25fe95c
fix(fuzz): bound in-memory evidence growth to stop execute_query OOM
claude Jul 30, 2026
82911bd
fix(security): remediate base-branch Semgrep SAST findings blocking PRs
claude Jul 30, 2026
cc6dbeb
test(authz): cover JWKS URL scheme guard (unblock coverage-evidence)
claude Jul 30, 2026
47386e7
test(authz): reach 100% coverage of the OIDC/JWKS module
claude Jul 30, 2026
38ab65f
test(authz): drop constant-condition ternary flagged by code-quality
claude Jul 30, 2026
54f6035
fix(orchestrator): close SQL source-table allowlist bypass via comma …
claude Jul 30, 2026
d1691c1
test(policy): pin governance deny-paths (policy.py 88% -> 98%)
claude Jul 30, 2026
23909c7
test(browse): cover PII-masking + policy-deny/validation paths (brows…
claude Jul 30, 2026
aec9570
test(observability): cover log-sink export + header extraction (80% -…
claude Jul 30, 2026
cbaf7c8
test(config): cover the DB-backed KV config loader (config.py 77% -> …
claude Jul 30, 2026
a504523
test(orchestrator): pin SQL-safety guards + query-draft branches (89%…
claude Jul 30, 2026
529aa03
test(connectors): pin source-connector contract guards (84% -> 100%)
claude Jul 30, 2026
a72033a
test(sdp): cover embeddings, connector-secret status, semantic valida…
claude Jul 30, 2026
6263c0c
test(sdp): bring catalog + demo_smoke to 100% line coverage
claude Jul 30, 2026
03f0225
chore: refresh head for last-push approval
opencode-agent[bot] Aug 2, 2026
02a63c6
docs(fuzz): document all reproducer artifact types
seonghobae Aug 3, 2026
a71f4b4
fix(fuzz): emit shell-safe absolute replay command
seonghobae Aug 3, 2026
492ea6e
test(authz): prove rejected JWKS schemes never fetch
seonghobae Aug 3, 2026
c73b872
test(credentials): remove vacuous secret exposure assertion
seonghobae Aug 3, 2026
88e4f39
fix(catalog): preserve schema fields in patch requests
seonghobae Aug 3, 2026
c257ae4
test(catalog): exercise schema patch through public contract
seonghobae Aug 3, 2026
03fe04c
test(browse): require masking integration fixture
seonghobae Aug 3, 2026
c496915
fix(security): suppress three verified false-positive Semgrep findings
claude Aug 3, 2026
bd8b307
chore(ci): retrigger required review pipeline at same tree
claude Aug 3, 2026
2ba30b9
chore(ci): re-fire synchronize after Actions event-processing outage
claude Aug 3, 2026
8130be1
chore: refresh head for last-push approval
opencode-agent[bot] Aug 3, 2026
1ced73d
Merge PR #34 base remediation into comma-join fix branch
Aug 4, 2026
0d8b3ad
test(sql): preserve derived-table projection commas
seonghobae Aug 5, 2026
7fb0077
fix(sql): ignore nested projection commas in relation scan
seonghobae Aug 5, 2026
93cafb3
refactor(sql): keep parser fix narrowly scoped
seonghobae Aug 5, 2026
a8d6967
test(security): require patched cryptography locks
seonghobae Aug 5, 2026
00fb51b
fix(security): pin patched cryptography runtime
seonghobae Aug 5, 2026
061af7a
fix(security): constrain test resolver to patched cryptography
seonghobae Aug 5, 2026
f0bb292
ci: materialize patched dependency locks once
seonghobae Aug 5, 2026
86ebe03
docs(security): record cryptography advisory decision
seonghobae Aug 5, 2026
a1d90ec
ci: run one-shot lock materializer on exact PR head
seonghobae Aug 5, 2026
4c12f25
fix(ci): remove unsafe temporary lock materializer
seonghobae Aug 9, 2026
c384254
Merge remote-tracking branch 'origin/main' into local/pr35
claude Aug 13, 2026
fcc5faa
fix(security): bump cryptography 49.0.0 -> 50.0.0 (CVE-2026-69247)
claude Aug 14, 2026
5e40a9a
fix(security): make FROM-clause boundary/JOIN scanning paren-depth-aware
claude Aug 14, 2026
b9a5b08
fix(security): collect parenthesized-join relations in SQL allowlist
cursoragent Aug 17, 2026
9c12f5d
fix(review): address remaining CodeRabbit comments on existing #35 files
cursoragent Aug 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/sdp/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,44 @@

_FORBIDDEN_KEYWORDS = {"drop", "delete", "truncate", "alter", "insert", "update", "merge", "exec", "union"}

# Keywords that terminate a FROM clause's relation list. Everything between a
# ``FROM`` and the first of these is the (possibly comma-separated) table list.
_CLAUSE_BOUNDARY = re.compile(
r"\b(where|group\s+by|order\s+by|having|limit|offset|window|"
r"union|intersect|except|fetch)\b",
re.IGNORECASE,
)


def _from_clause_tables(sql: str) -> list[str]:
"""Return every relation named in each FROM clause of ``sql``.

Unlike a bare ``FROM <table>`` / ``JOIN <table>`` match, this also captures
comma-separated (implicit-join) relations such as the ``customer`` in
``FROM crm, customer``, which would otherwise slip past the source-table
allowlist. Iterating over every ``FROM`` occurrence also covers subquery
FROM clauses, matching the previous scan's coverage.
"""

tables: list[str] = []
for from_match in re.finditer(r"\bfrom\b", sql, re.IGNORECASE):
region = sql[from_match.end():]
boundary = _CLAUSE_BOUNDARY.search(region)
if boundary:
region = region[: boundary.start()]
# Split on JOIN so an ON-condition never swallows the next relation, then
# split each segment on commas to expose implicit-join relations.
for join_segment in re.split(r"\bjoin\b", region, flags=re.IGNORECASE):
relation_part = re.split(r"\bon\b", join_segment, maxsplit=1, flags=re.IGNORECASE)[0]
for candidate in relation_part.split(","):
stripped_candidate = candidate.strip()
if not stripped_candidate:
continue
identifier = re.match(r"[A-Za-z_][\w.]*", stripped_candidate.split()[0])
if identifier:
tables.append(identifier.group(0))
return tables


def _safe_identifier(value: str) -> str:
return "".join(ch if ch.isalnum() or ch == "_" else "_" for ch in value)
Expand Down Expand Up @@ -45,10 +83,7 @@ def validate_sql_query(sql: str, *, source_system: str) -> list[str]:
warnings.append("forbidden_keyword_detected")
break

referenced = [
next(value for value in match if value)
for match in re.findall(r"\bfrom\s+([A-Za-z_][\w.]*)|\bjoin\s+([A-Za-z_][\w.]*)", stripped, re.IGNORECASE)
]
referenced = _from_clause_tables(stripped)
Comment thread
seonghobae marked this conversation as resolved.
Resolved
if not referenced:
warnings.append("missing_source_table")
return warnings
Expand Down
32 changes: 32 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,38 @@ def test_browse_query_rejects_table_outside_dataset_binding():
)


def test_browse_query_rejects_comma_joined_unauthorized_table():
"""A comma-separated (implicit-join) table outside the dataset binding must
be rejected by the source-table allowlist, exactly like an explicit
unauthorized FROM/JOIN target. The allowlisted table for crm-event is
``crm`` (source_system s3://analytics/events/crm); smuggling a second table
via ``FROM crm, customer`` must not pass validation."""
response = client.post(
"/browse/query",
json={
"user": "analyst",
"purpose": "analysis",
"dataset_ids": ["crm-event"],
"language": "SQL",
"query": "SELECT count(*) AS active_count FROM crm, customer",
},
)
assert response.status_code == 400
assert "unauthorized_table_reference" in response.json()["detail"]["warnings"]


def test_validate_sql_query_flags_comma_joined_table_outside_allowlist():
"""Unit-level guard: validate_sql_query must flag a comma-joined relation
that is not the allowlisted source table."""
from sdp.orchestrator import validate_sql_query

warnings = validate_sql_query(
"SELECT count(*) FROM crm, customer",
source_system="s3://analytics/events/crm",
)
assert "unauthorized_table_reference" in warnings


def test_browse_query_rejects_literal_tautology_injection():
response = client.post(
"/browse/query",
Expand Down
Loading