pywrit 0.2.17__tar.gz → 0.2.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pywrit-0.2.17/src/pywrit.egg-info → pywrit-0.2.18}/PKG-INFO +3 -3
- {pywrit-0.2.17 → pywrit-0.2.18}/README.md +2 -2
- {pywrit-0.2.17 → pywrit-0.2.18}/pyproject.toml +1 -1
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit/__init__.py +1 -1
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit/cli.py +40 -6
- {pywrit-0.2.17 → pywrit-0.2.18/src/pywrit.egg-info}/PKG-INFO +3 -3
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_scan_go.py +7 -4
- {pywrit-0.2.17 → pywrit-0.2.18}/LICENSE +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/setup.cfg +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit/client.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit/errors.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit.egg-info/SOURCES.txt +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit.egg-info/dependency_links.txt +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit.egg-info/entry_points.txt +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit.egg-info/requires.txt +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/src/pywrit.egg-info/top_level.txt +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_client.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_scan_json.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_scan_python.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_scan_tsjs.py +0 -0
- {pywrit-0.2.17 → pywrit-0.2.18}/tests/test_wrap.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pywrit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.18
|
|
4
4
|
Summary: Python client + CLI for Writ — the gate before the write
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://withwrit.com
|
|
@@ -61,7 +61,7 @@ install test.
|
|
|
61
61
|
| --- | --- | --- | --- |
|
|
62
62
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
63
63
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
64
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest
|
|
64
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest, package-level generated clients, and GORM Raw raw-SQL writes: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package, GORM Raw `db.Raw` / `tx.Raw` with a write-first SQL string literal. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
65
65
|
|
|
66
66
|
## 60-second quickstart: scan → wrap → gate
|
|
67
67
|
|
|
@@ -191,7 +191,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
191
191
|
|
|
192
192
|
pip install 'pywrit[polyglot]'
|
|
193
193
|
|
|
194
|
-
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered:
|
|
194
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GORM raw-SQL calls `db.Raw("INSERT INTO ...")` / `tx.Raw("DELETE FROM ...")` fire when argument 0 is a string literal (interpreted or backtick) whose first keyword is a write verb (INSERT, UPDATE, DELETE, REPLACE, TRUNCATE, MERGE), case-insensitive; a variable, a read-first literal (SELECT), a leading WITH (CTE), or a Raw call on a non-db/tx receiver never fires. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: WITH-CTE raw-SQL writes and other Go write patterns.
|
|
195
195
|
|
|
196
196
|
## GitHub Action
|
|
197
197
|
|
|
@@ -38,7 +38,7 @@ install test.
|
|
|
38
38
|
| --- | --- | --- | --- |
|
|
39
39
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
40
40
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
41
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest
|
|
41
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest, package-level generated clients, and GORM Raw raw-SQL writes: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package, GORM Raw `db.Raw` / `tx.Raw` with a write-first SQL string literal. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
42
42
|
|
|
43
43
|
## 60-second quickstart: scan → wrap → gate
|
|
44
44
|
|
|
@@ -168,7 +168,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
168
168
|
|
|
169
169
|
pip install 'pywrit[polyglot]'
|
|
170
170
|
|
|
171
|
-
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered:
|
|
171
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GORM raw-SQL calls `db.Raw("INSERT INTO ...")` / `tx.Raw("DELETE FROM ...")` fire when argument 0 is a string literal (interpreted or backtick) whose first keyword is a write verb (INSERT, UPDATE, DELETE, REPLACE, TRUNCATE, MERGE), case-insensitive; a variable, a read-first literal (SELECT), a leading WITH (CTE), or a Raw call on a non-db/tx receiver never fires. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: WITH-CTE raw-SQL writes and other Go write patterns.
|
|
172
172
|
|
|
173
173
|
## GitHub Action
|
|
174
174
|
|
|
@@ -1395,7 +1395,7 @@ def _tsjs_scan_source(src, filename, parser):
|
|
|
1395
1395
|
return sites, gated
|
|
1396
1396
|
|
|
1397
1397
|
|
|
1398
|
-
# writ scan, Go (slices 1-
|
|
1398
|
+
# writ scan, Go (slices 1-4): deterministic and scan-only (Go files are
|
|
1399
1399
|
# never rewritten). Same tree-sitter tier as TS/JS, same
|
|
1400
1400
|
# `pywrit[polyglot]` extra plus the tree-sitter-go grammar; without the
|
|
1401
1401
|
# extra the missing-extra block counts Go files too. Slice 1 covers one
|
|
@@ -1408,9 +1408,11 @@ def _tsjs_scan_source(src, filename, parser):
|
|
|
1408
1408
|
# middle segment). Slice 2 adds request-pipeline Call/RawRequest with a
|
|
1409
1409
|
# write method as argument 0. Slice 3 adds import-aware package-level
|
|
1410
1410
|
# generated clients (<pkg>.<New|Update|Delete|Create>, the pre-v87
|
|
1411
|
-
# stripe-go shape: charge.New(params)).
|
|
1412
|
-
#
|
|
1413
|
-
#
|
|
1411
|
+
# stripe-go shape: charge.New(params)). Slice 4 adds the GORM raw-SQL
|
|
1412
|
+
# helper: <db|tx>.Raw(<write SQL string literal>) graded on the
|
|
1413
|
+
# literal's first keyword. Wider Go coverage (os/io/fs writes, sqlx,
|
|
1414
|
+
# raw-SQL conditions on Exec, WITH-CTE raw-SQL writes, Go-specific
|
|
1415
|
+
# non-product suppression classes) ships in later slices.
|
|
1414
1416
|
# ---------------------------------------------------------------------------
|
|
1415
1417
|
|
|
1416
1418
|
_GO_MAX_BYTES = 1000000 # larger files are almost always generated
|
|
@@ -1423,6 +1425,15 @@ _GO_TEST_DIRS = {"tests", "testing"}
|
|
|
1423
1425
|
# resource-segment rule.
|
|
1424
1426
|
_GO_PKG_ROOTS = {"http", "sql", "gorm"}
|
|
1425
1427
|
|
|
1428
|
+
# Write-first SQL verbs for the slice-4 GORM raw-SQL grade: a Raw()
|
|
1429
|
+
# string literal is a write only when its first keyword (leading
|
|
1430
|
+
# whitespace stripped) is one of these, case-insensitive. Read-first
|
|
1431
|
+
# statements (SELECT, SHOW, DESCRIBE, EXPLAIN) never fire, and a
|
|
1432
|
+
# leading WITH (CTE) is deliberately not graded past in this slice:
|
|
1433
|
+
# it never fires, write tail or not.
|
|
1434
|
+
_GO_RAWSQL_WRITE_VERBS = ("insert", "update", "delete", "replace",
|
|
1435
|
+
"truncate", "merge")
|
|
1436
|
+
|
|
1426
1437
|
# Classifier noise guards. Uppercase two-segment selectors (s.Info.
|
|
1427
1438
|
# Update) are ubiquitous in real code (structs like Params, Args, Options,
|
|
1428
1439
|
# Config); the stripe-go generated-client shape is three segments
|
|
@@ -1489,6 +1500,24 @@ _GO_PKGCLIENT_NONRESOURCE = (
|
|
|
1489
1500
|
)
|
|
1490
1501
|
|
|
1491
1502
|
|
|
1503
|
+
def _go_rawsql_write(call, f):
|
|
1504
|
+
"""Slice-4 grade for the GORM Raw helper: the call is a write only
|
|
1505
|
+
when argument 0 is an interpreted or backtick string literal whose
|
|
1506
|
+
first keyword (leading whitespace stripped, case-insensitive) is a
|
|
1507
|
+
write verb in _GO_RAWSQL_WRITE_VERBS. A variable, a concatenation,
|
|
1508
|
+
a fmt.Sprintf call, or any non-literal first argument never fires
|
|
1509
|
+
(literal() returns None); read-first SQL (SELECT, SHOW, DESCRIBE,
|
|
1510
|
+
EXPLAIN) and a leading WITH (CTE) fall through as reads."""
|
|
1511
|
+
args = _go_args(call)
|
|
1512
|
+
if not args:
|
|
1513
|
+
return False
|
|
1514
|
+
lit = f.literal(args[0])
|
|
1515
|
+
if lit is None:
|
|
1516
|
+
return False
|
|
1517
|
+
words = lit.lstrip().split(None, 1)
|
|
1518
|
+
return bool(words) and words[0].lower() in _GO_RAWSQL_WRITE_VERBS
|
|
1519
|
+
|
|
1520
|
+
|
|
1492
1521
|
class _GoFile:
|
|
1493
1522
|
def __init__(self, src):
|
|
1494
1523
|
self.src = src
|
|
@@ -1587,8 +1616,9 @@ def _go_import_resource_name(path):
|
|
|
1587
1616
|
|
|
1588
1617
|
def _go_classify(call, chain, f, pkg_paths=None):
|
|
1589
1618
|
"""First match wins; returns (rule_id, kind). Slice-1 family, the
|
|
1590
|
-
slice-3 package-level generated-client family,
|
|
1591
|
-
request-pipeline family (Call / RawRequest)
|
|
1619
|
+
slice-3 package-level generated-client family, the slice-2
|
|
1620
|
+
request-pipeline family (Call / RawRequest), and the slice-4 GORM
|
|
1621
|
+
raw-SQL family (Raw with a write-first SQL literal).
|
|
1592
1622
|
|
|
1593
1623
|
`chain` is the raw (un-lowercased) callee chain. Handle receivers
|
|
1594
1624
|
match by convention on any receiver segment (db, tx, gormDB, r.db,
|
|
@@ -1612,6 +1642,10 @@ def _go_classify(call, chain, f, pkg_paths=None):
|
|
|
1612
1642
|
if tail in _GO_ORM_METHODS:
|
|
1613
1643
|
# GORM shape: db.Create / Save / Update / Updates / Delete
|
|
1614
1644
|
return "go-orm-write", "db"
|
|
1645
|
+
if tail == "raw" and _go_rawsql_write(call, f):
|
|
1646
|
+
# GORM raw SQL (slice 4): db.Raw / tx.Raw, only when the
|
|
1647
|
+
# literal SQL's first keyword is a write verb.
|
|
1648
|
+
return "go-rawsql-write", "db"
|
|
1615
1649
|
if tail in _GO_HTTP_VERBS:
|
|
1616
1650
|
if norm[0] == "http" and len(norm) == 2:
|
|
1617
1651
|
# package-level http.Post / Put / Patch / Delete
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pywrit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.18
|
|
4
4
|
Summary: Python client + CLI for Writ — the gate before the write
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://withwrit.com
|
|
@@ -61,7 +61,7 @@ install test.
|
|
|
61
61
|
| --- | --- | --- | --- |
|
|
62
62
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
63
63
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
64
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest
|
|
64
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest, package-level generated clients, and GORM Raw raw-SQL writes: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package, GORM Raw `db.Raw` / `tx.Raw` with a write-first SQL string literal. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
65
65
|
|
|
66
66
|
## 60-second quickstart: scan → wrap → gate
|
|
67
67
|
|
|
@@ -191,7 +191,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
191
191
|
|
|
192
192
|
pip install 'pywrit[polyglot]'
|
|
193
193
|
|
|
194
|
-
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered:
|
|
194
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GORM raw-SQL calls `db.Raw("INSERT INTO ...")` / `tx.Raw("DELETE FROM ...")` fire when argument 0 is a string literal (interpreted or backtick) whose first keyword is a write verb (INSERT, UPDATE, DELETE, REPLACE, TRUNCATE, MERGE), case-insensitive; a variable, a read-first literal (SELECT), a leading WITH (CTE), or a Raw call on a non-db/tx receiver never fires. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: WITH-CTE raw-SQL writes and other Go write patterns.
|
|
195
195
|
|
|
196
196
|
## GitHub Action
|
|
197
197
|
|
|
@@ -31,7 +31,7 @@ _BLOCK_EXTRA = {m: None for m in ("tree_sitter", "tree_sitter_go",
|
|
|
31
31
|
"tree_sitter_language_pack")}
|
|
32
32
|
_GO_RULES = {"go-db-write", "go-orm-write", "go-http-client-write",
|
|
33
33
|
"go-http-request-write", "go-sdk-write", "go-pipeline-write",
|
|
34
|
-
"go-pkgclient-write"}
|
|
34
|
+
"go-pkgclient-write", "go-rawsql-write"}
|
|
35
35
|
_EXPECT = re.compile(r"//\s*expect:\s*([a-z0-9-]+)")
|
|
36
36
|
_FINDING = re.compile(
|
|
37
37
|
r"^ (?P<file>\S+\.go):(?P<line>\d+) \[(?P<kind>[a-z]+)\] "
|
|
@@ -113,8 +113,8 @@ class FixtureRulesTest(unittest.TestCase):
|
|
|
113
113
|
verbs = __import__("json").loads(policy.read_text())
|
|
114
114
|
self.assertEqual(code, 0)
|
|
115
115
|
n = len(_expected())
|
|
116
|
-
self.assertIn("go files scanned:
|
|
117
|
-
self.assertIn("go write sites: %d in
|
|
116
|
+
self.assertIn("go files scanned: 7 skipped: 0 (scan only, no --apply)", out)
|
|
117
|
+
self.assertIn("go write sites: %d in 11 function(s)" % n, out)
|
|
118
118
|
self.assertIn("go gated: 0/%d (0%%)" % n, out)
|
|
119
119
|
self.assertIn(" db.go:13 [db] go-db-write deleteOrder(): "
|
|
120
120
|
"db.Exec(\"DELETE FROM orders WHERE id = $1\", id)", out)
|
|
@@ -122,6 +122,9 @@ class FixtureRulesTest(unittest.TestCase):
|
|
|
122
122
|
"sc.Charges.New(params)", out)
|
|
123
123
|
self.assertIn(" pkgclient.go:25 [sdk] go-pkgclient-write "
|
|
124
124
|
"legacyCharge(): charge.New(params)", out)
|
|
125
|
+
self.assertIn(" rawsql.go:16 [db] go-rawsql-write "
|
|
126
|
+
"backfillUsers(): db.Raw(\"INSERT INTO audit_log "
|
|
127
|
+
"(event) VALUES ('x')\")", out)
|
|
125
128
|
for v in ("db.delete", "db.create", "http.submit", "sdk.charge",
|
|
126
129
|
"sdk.nested"):
|
|
127
130
|
self.assertEqual(verbs.get(v), "require_grant", v)
|
|
@@ -314,7 +317,7 @@ class JsonReportTest(unittest.TestCase):
|
|
|
314
317
|
self.assertEqual(code, 0, out)
|
|
315
318
|
doc = j.loads(out)
|
|
316
319
|
self.assertFalse(doc["go_hint"])
|
|
317
|
-
self.assertEqual(doc["files_scanned"],
|
|
320
|
+
self.assertEqual(doc["files_scanned"], 7)
|
|
318
321
|
go_findings = [f for f in doc["findings"]
|
|
319
322
|
if f["language"] == "go"]
|
|
320
323
|
self.assertEqual(len(go_findings), len(_expected()), doc)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|