feat: TypeConstrainedAttribute for Statements + DataflowIR.Language - #635
Merged
Merged
Conversation
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #635 +/- ##
==========================================
+ Coverage 84.22% 84.26% +0.03%
==========================================
Files 160 160
Lines 22529 22571 +42
==========================================
+ Hits 18976 19019 +43
Misses 2857 2857
+ Partials 696 695 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3 tasks done
shivasurya
force-pushed
the
shiva/pr-06-type-attr-language
branch
from
April 2, 2026 23:32
7864d50 to
32d425e
Compare
This was referenced Apr 3, 2026
Owner
Author
This was referenced Apr 3, 2026
Owner
Author
Merge activity
|
shivasurya
changed the base branch from
shiva/pr-05-type-enrichment
to
graphite-base/635
April 3, 2026 17:34
Extends TypeConstrainedAttributeExecutor to scan CallGraph.Statements
for enriched AttributeAccess (Go struct field access). After PR-05
type enrichment, "net/http.Request.URL.Path" in Statements is matched
by GoHTTPRequest.attr("URL.Path").
Also adds DataflowIR.Language field and language filter in
findFunctionsWithSourcesAndSinks — Go rules only analyze Go functions.
Changes:
- ir_types.go: DataflowIR.Language, plural ReceiverTypes/AttributeNames
on TypeConstrainedAttributeIR with getReceiverTypes/getAttributeNames
- type_constrained_executor.go: Execute() scans Statements + CallSites,
matchesAttributeAccess uses plural helpers
- dataflow_executor.go: language filter in findFunctionsWithSourcesAndSinks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
shivasurya
force-pushed
the
shiva/pr-06-type-attr-language
branch
from
April 3, 2026 17:36
32d425e to
479192f
Compare
shivasurya
added a commit
that referenced
this pull request
Apr 3, 2026
## Summary Enables Go security rule authoring via the Python SDK. Rule authors write type-first rules with no variable names — pure type contracts. **Stacked on:** #635 (PR-06: TypeConstrainedAttribute + Language filter) ### New files - **`codepathfinder/go_rule.py`** — 14 Go QueryType classes: GoHTTPRequest, GoHTTPClient, GoHTTPResponseWriter, GoSQLDB, GoOS, GoOSExec, GoFmt, GoIO, GoFilepath, GoStrconv, GoJSON, GoTemplate, GoContext, GoCrypto - **`rules/go_decorators.py`** — `@go_rule` decorator mirroring `@python_rule`. Injects `language="go"` into DataflowIR matcher dict for language scoping. - **`rules/go_ir.py`** — `compile_go_rules()` JSON IR compiler mirroring `python_ir.py` ### Design for multi-language scalability Each language follows the same pattern: `{lang}_decorators.py` + `{lang}_ir.py` + `codepathfinder/{lang}_rule.py`. Adding Java would create `java_decorators.py`, `java_ir.py`, `codepathfinder/java_rule.py` with `JavaServletRequest`, `JavaJDBCStatement` etc. ### Example rule ```python @go_rule(id="GO-SQLI-TAINT", severity="CRITICAL", cwe="CWE-89") def detect_sqli(): return flows( from_sources=[GoHTTPRequest.method("FormValue"), GoHTTPRequest.attr("URL.Path")], to_sinks=[GoSQLDB.method("Query", "Exec").tracks(0)], propagates_through=PropagationPresets.standard(), scope="global", ) ``` ## Test plan - [x] 13 tests: QueryType IR output, decorator metadata, language injection, non-dataflow matcher, IR compilation, JSON serialization - [x] 100% coverage on `go_rule.py` - [x] Full SDK suite: `python3 -m pytest tests/ -v` (381 passed) 🤖 Generated with [Claude Code](https://claude.ai/code)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Summary
Enables
GoHTTPRequest.attr("URL.Path")matching against Go statements and adds language scoping so Go rules only analyze Go functions.Stacked on: #634 (PR-05: type enrichment)
Changes
ir_types.go—DataflowIR.Languagefield ("go","python",""for any). PluralReceiverTypes/AttributeNamesonTypeConstrainedAttributeIRwithgetReceiverTypes()/getAttributeNames()helpers for backward compatibility.type_constrained_executor.go—Execute()now scans bothCallGraph.CallSites(Python) andCallGraph.Statements(Go). Matches enrichedstmt.AttributeAccesslike"net/http.Request.URL.Path"against(receiverType, attrName)combinations.matchesAttributeAccessupdated to use plural helpers.dataflow_executor.go— Language filter infindFunctionsWithSourcesAndSinks: whenDataflowIR.Languageis set, only functions with matchinggraph.Node.Languageare analyzed.Test plan
go test ./dsl/ -count=1go test ./graph/callgraph/builder/ -count=1golangci-lint run ./dsl/🤖 Generated with Claude Code