pywrit 0.2.16__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.16/src/pywrit.egg-info → pywrit-0.2.18}/PKG-INFO +11 -4
- {pywrit-0.2.16 → pywrit-0.2.18}/README.md +10 -3
- {pywrit-0.2.16 → pywrit-0.2.18}/pyproject.toml +1 -1
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit/__init__.py +1 -1
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit/cli.py +115 -17
- {pywrit-0.2.16 → pywrit-0.2.18/src/pywrit.egg-info}/PKG-INFO +11 -4
- {pywrit-0.2.16 → pywrit-0.2.18}/tests/test_scan_go.py +10 -4
- {pywrit-0.2.16 → pywrit-0.2.18}/LICENSE +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/setup.cfg +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit/client.py +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit/errors.py +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit.egg-info/SOURCES.txt +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit.egg-info/dependency_links.txt +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit.egg-info/entry_points.txt +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit.egg-info/requires.txt +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/src/pywrit.egg-info/top_level.txt +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/tests/test_client.py +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/tests/test_scan_json.py +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/tests/test_scan_python.py +0 -0
- {pywrit-0.2.16 → pywrit-0.2.18}/tests/test_scan_tsjs.py +0 -0
- {pywrit-0.2.16 → 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
|
|
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 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),
|
|
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
|
|
|
@@ -222,7 +222,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
222
222
|
|
|
223
223
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
224
224
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
225
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
225
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
226
226
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
227
227
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
228
228
|
every decision.
|
|
@@ -237,9 +237,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
239
239
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
240
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
241
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
240
242
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
241
243
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
242
244
|
| `writ_receipts` | Read the tenant's audit log |
|
|
245
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
243
246
|
| `writ_policy` | Manage the verb policy |
|
|
244
247
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
245
248
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -251,6 +254,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
251
254
|
| `writ_principals` | List the tenant's principals |
|
|
252
255
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
253
256
|
| `writ_keys` | List API key metadata |
|
|
257
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
258
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
259
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
260
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
254
261
|
|
|
255
262
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
256
263
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -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
|
|
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 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),
|
|
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
|
|
|
@@ -199,7 +199,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
199
199
|
|
|
200
200
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
201
201
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
202
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
202
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
203
203
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
204
204
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
205
205
|
every decision.
|
|
@@ -214,9 +214,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
214
214
|
|---|---|
|
|
215
215
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
216
216
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
217
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
218
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
217
219
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
218
220
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
219
221
|
| `writ_receipts` | Read the tenant's audit log |
|
|
222
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
220
223
|
| `writ_policy` | Manage the verb policy |
|
|
221
224
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
222
225
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -228,6 +231,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
228
231
|
| `writ_principals` | List the tenant's principals |
|
|
229
232
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
230
233
|
| `writ_keys` | List API key metadata |
|
|
234
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
235
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
236
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
237
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
231
238
|
|
|
232
239
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
233
240
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -1395,18 +1395,24 @@ def _tsjs_scan_source(src, filename, parser):
|
|
|
1395
1395
|
return sites, gated
|
|
1396
1396
|
|
|
1397
1397
|
|
|
1398
|
-
# writ scan, Go (
|
|
1399
|
-
# rewritten). Same tree-sitter tier as TS/JS, same
|
|
1400
|
-
# extra plus the tree-sitter-go grammar; without the
|
|
1401
|
-
# missing-extra block counts Go files too. Slice 1 covers one
|
|
1402
|
-
# family, deliberately: database/sql Exec/ExecContext on a db/tx
|
|
1403
|
-
# GORM-shaped Create/Save/Update/Updates/Delete on a db handle,
|
|
1404
|
-
# client writes (Post/Put/Patch/Delete calls and
|
|
1405
|
-
# with a write method), and generated-client
|
|
1406
|
-
# stripe-go shape
|
|
1407
|
-
#
|
|
1408
|
-
#
|
|
1409
|
-
#
|
|
1398
|
+
# writ scan, Go (slices 1-4): deterministic and scan-only (Go files are
|
|
1399
|
+
# never rewritten). Same tree-sitter tier as TS/JS, same
|
|
1400
|
+
# `pywrit[polyglot]` extra plus the tree-sitter-go grammar; without the
|
|
1401
|
+
# extra the missing-extra block counts Go files too. Slice 1 covers one
|
|
1402
|
+
# write family, deliberately: database/sql Exec/ExecContext on a db/tx
|
|
1403
|
+
# handle, GORM-shaped Create/Save/Update/Updates/Delete on a db handle,
|
|
1404
|
+
# HTTP client writes (Post/Put/Patch/Delete calls and
|
|
1405
|
+
# NewRequest(-WithContext) with a write method), and generated-client
|
|
1406
|
+
# resource methods of the stripe-go shape
|
|
1407
|
+
# (<client>.<Resource>.<New|Update|Delete|Create> with an uppercase
|
|
1408
|
+
# middle segment). Slice 2 adds request-pipeline Call/RawRequest with a
|
|
1409
|
+
# write method as argument 0. Slice 3 adds import-aware package-level
|
|
1410
|
+
# generated clients (<pkg>.<New|Update|Delete|Create>, the pre-v87
|
|
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.
|
|
1410
1416
|
# ---------------------------------------------------------------------------
|
|
1411
1417
|
|
|
1412
1418
|
_GO_MAX_BYTES = 1000000 # larger files are almost always generated
|
|
@@ -1419,13 +1425,23 @@ _GO_TEST_DIRS = {"tests", "testing"}
|
|
|
1419
1425
|
# resource-segment rule.
|
|
1420
1426
|
_GO_PKG_ROOTS = {"http", "sql", "gorm"}
|
|
1421
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
|
+
|
|
1422
1437
|
# Classifier noise guards. Uppercase two-segment selectors (s.Info.
|
|
1423
1438
|
# Update) are ubiquitous in real code (structs like Params, Args, Options,
|
|
1424
1439
|
# Config); the stripe-go generated-client shape is three segments
|
|
1425
1440
|
# (client.Charges.New), so two-segment chains never fire the sdk rule.
|
|
1426
|
-
# The package-level pre-v87 shape (charge.New(params))
|
|
1427
|
-
# slice
|
|
1428
|
-
#
|
|
1441
|
+
# The package-level pre-v87 shape (charge.New(params)) fires only in
|
|
1442
|
+
# slice 3's import-aware branch below: the two-segment chain's root
|
|
1443
|
+
# must be an imported package whose path is resource-shaped, so a bare
|
|
1444
|
+
# local constructor (svc.New) never matches; see
|
|
1429
1445
|
# tests/fixtures/go/pkgclient.go.
|
|
1430
1446
|
_GO_STRUCTY_RES = {"params", "args", "arg", "opts", "options", "config",
|
|
1431
1447
|
"conf", "cfg", "settings", "props", "attrs", "info",
|
|
@@ -1459,6 +1475,47 @@ _GO_HANDLE_RX = _re.compile(r"(db|tx)$")
|
|
|
1459
1475
|
# write methods (Post/Put/Patch/Delete string or http.MethodX
|
|
1460
1476
|
# constant) fire, Get/Head and variables do not.
|
|
1461
1477
|
_GO_PIPELINE_METHODS = {"call", "rawrequest"}
|
|
1478
|
+
# Service/client/library-shaped import-path endings that must NOT fire
|
|
1479
|
+
# the slice-3 package-level generated-client rule: a two-segment
|
|
1480
|
+
# `<pkg>.<New|Update|Delete|Create>` call is a package-level resource
|
|
1481
|
+
# method only when the import path's last segment names a resource
|
|
1482
|
+
# (charge, invoice), so a path whose last segment ends in one of these
|
|
1483
|
+
# is plumbing, not a resource: paymentsvc.New(cfg) and client.New(...)
|
|
1484
|
+
# are constructors on a service/client package, not writes, and
|
|
1485
|
+
# internal/mock/fake packages are plumbing or test doubles. The check
|
|
1486
|
+
# is a suffix match against the import path's lowercase last segment
|
|
1487
|
+
# (never the local alias), so concatenated names (gensvc,
|
|
1488
|
+
# stripeclient, paymentsvc) are plumbing too, while real resource
|
|
1489
|
+
# names (charge, invoice, customer, subscription, account) do not end
|
|
1490
|
+
# this way and still fire, aliased or not
|
|
1491
|
+
# (acmeinvoice "example.com/acme/acme-payments/invoice").
|
|
1492
|
+
_GO_PKGCLIENT_NONRESOURCE = (
|
|
1493
|
+
# service- and client-shaped: the path's last segment is the
|
|
1494
|
+
# service or client itself, not a resource
|
|
1495
|
+
"svc", "service", "client", "server",
|
|
1496
|
+
# library- and layer-shaped: imports of plumbing, not resources
|
|
1497
|
+
"api", "sdk", "gateway", "internal", "pkg", "lib",
|
|
1498
|
+
# test doubles
|
|
1499
|
+
"mock", "fake", "stub",
|
|
1500
|
+
)
|
|
1501
|
+
|
|
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
|
|
1462
1519
|
|
|
1463
1520
|
|
|
1464
1521
|
class _GoFile:
|
|
@@ -1543,9 +1600,25 @@ def _go_write_method(call, f, idx):
|
|
|
1543
1600
|
ac[1][len("method"):] in _GO_HTTP_WRITE_METHODS
|
|
1544
1601
|
|
|
1545
1602
|
|
|
1603
|
+
def _go_import_resource_name(path):
|
|
1604
|
+
"""Last meaningful segment of a Go import path, lowercased: the
|
|
1605
|
+
package name as the compiler resolves it. A trailing semantic-
|
|
1606
|
+
import-versioning segment (github.com/stripe/stripe-go/v87 -> the
|
|
1607
|
+
path .../v87/charge ends in "charge" anyway; this folds a path that
|
|
1608
|
+
ENDS in vN, e.g. example.com/mod/v2 -> "mod", matching the module
|
|
1609
|
+
name a consumer would reference)."""
|
|
1610
|
+
seg = path.rstrip("/").rsplit("/", 1)[-1].lower()
|
|
1611
|
+
if _re.fullmatch(r"v\d+", seg):
|
|
1612
|
+
seg = path.rstrip("/").rsplit("/", 2)[-2].lower() \
|
|
1613
|
+
if "/" in path.rstrip("/") else seg
|
|
1614
|
+
return seg
|
|
1615
|
+
|
|
1616
|
+
|
|
1546
1617
|
def _go_classify(call, chain, f, pkg_paths=None):
|
|
1547
|
-
"""First match wins; returns (rule_id, kind). Slice-1 family
|
|
1548
|
-
|
|
1618
|
+
"""First match wins; returns (rule_id, kind). Slice-1 family, the
|
|
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).
|
|
1549
1622
|
|
|
1550
1623
|
`chain` is the raw (un-lowercased) callee chain. Handle receivers
|
|
1551
1624
|
match by convention on any receiver segment (db, tx, gormDB, r.db,
|
|
@@ -1569,6 +1642,10 @@ def _go_classify(call, chain, f, pkg_paths=None):
|
|
|
1569
1642
|
if tail in _GO_ORM_METHODS:
|
|
1570
1643
|
# GORM shape: db.Create / Save / Update / Updates / Delete
|
|
1571
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"
|
|
1572
1649
|
if tail in _GO_HTTP_VERBS:
|
|
1573
1650
|
if norm[0] == "http" and len(norm) == 2:
|
|
1574
1651
|
# package-level http.Post / Put / Patch / Delete
|
|
@@ -1592,6 +1669,27 @@ def _go_classify(call, chain, f, pkg_paths=None):
|
|
|
1592
1669
|
# pre-v87 shape (charge.New) is a later slice, not this
|
|
1593
1670
|
# branch: two-segment chains never reach it.
|
|
1594
1671
|
return "go-sdk-write", "sdk"
|
|
1672
|
+
if tail in _GO_RESOURCE_METHODS and len(chain) == 2 and \
|
|
1673
|
+
pkg_paths is not None and chain[0] in pkg_paths:
|
|
1674
|
+
# package-level generated client, the pre-v87 stripe-go shape
|
|
1675
|
+
# (slice 3): charge.New(params), invoice.Update("in_123", nil).
|
|
1676
|
+
# Import-aware on every axis: the root must be a package this
|
|
1677
|
+
# file imports; the path must be a real module (first segment
|
|
1678
|
+
# is a domain, containing a dot) so bare stdlib constructors
|
|
1679
|
+
# (errors.New, reflect.New, crypto/hmac hmac.New) never fire;
|
|
1680
|
+
# and the import path's last segment (not the local alias) must
|
|
1681
|
+
# be resource-shaped, not structy (_GO_STRUCTY_RES) and not
|
|
1682
|
+
# service/client/library-shaped (_GO_PKGCLIENT_NONRESOURCE). A
|
|
1683
|
+
# bare local `svc.New(cfg)` with no matching import never fires;
|
|
1684
|
+
# `paymentsvc.New(cfg)` on an imported service package never
|
|
1685
|
+
# fires.
|
|
1686
|
+
path = pkg_paths[chain[0]]
|
|
1687
|
+
if "." not in path.split("/", 1)[0]:
|
|
1688
|
+
return None # stdlib constructor, not a generated client
|
|
1689
|
+
last = _go_import_resource_name(path)
|
|
1690
|
+
if last not in _GO_STRUCTY_RES and not \
|
|
1691
|
+
last.endswith(_GO_PKGCLIENT_NONRESOURCE):
|
|
1692
|
+
return "go-pkgclient-write", "sdk"
|
|
1595
1693
|
if tail in _GO_PIPELINE_METHODS and len(norm) >= 2:
|
|
1596
1694
|
# request pipeline: <recv>.Call / .RawRequest with a write
|
|
1597
1695
|
# method as argument 0 (the stripe-go Backend shape:
|
|
@@ -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
|
|
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 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),
|
|
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
|
|
|
@@ -222,7 +222,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
222
222
|
|
|
223
223
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
224
224
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
225
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
225
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
226
226
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
227
227
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
228
228
|
every decision.
|
|
@@ -237,9 +237,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
239
239
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
240
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
241
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
240
242
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
241
243
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
242
244
|
| `writ_receipts` | Read the tenant's audit log |
|
|
245
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
243
246
|
| `writ_policy` | Manage the verb policy |
|
|
244
247
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
245
248
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -251,6 +254,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
251
254
|
| `writ_principals` | List the tenant's principals |
|
|
252
255
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
253
256
|
| `writ_keys` | List API key metadata |
|
|
257
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
258
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
259
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
260
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
254
261
|
|
|
255
262
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
256
263
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -30,7 +30,8 @@ HAVE_EXTRA = bool(cli._go_parsers())
|
|
|
30
30
|
_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
|
-
"go-http-request-write", "go-sdk-write", "go-pipeline-write"
|
|
33
|
+
"go-http-request-write", "go-sdk-write", "go-pipeline-write",
|
|
34
|
+
"go-pkgclient-write", "go-rawsql-write"}
|
|
34
35
|
_EXPECT = re.compile(r"//\s*expect:\s*([a-z0-9-]+)")
|
|
35
36
|
_FINDING = re.compile(
|
|
36
37
|
r"^ (?P<file>\S+\.go):(?P<line>\d+) \[(?P<kind>[a-z]+)\] "
|
|
@@ -112,13 +113,18 @@ class FixtureRulesTest(unittest.TestCase):
|
|
|
112
113
|
verbs = __import__("json").loads(policy.read_text())
|
|
113
114
|
self.assertEqual(code, 0)
|
|
114
115
|
n = len(_expected())
|
|
115
|
-
self.assertIn("go files scanned:
|
|
116
|
-
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)
|
|
117
118
|
self.assertIn("go gated: 0/%d (0%%)" % n, out)
|
|
118
119
|
self.assertIn(" db.go:13 [db] go-db-write deleteOrder(): "
|
|
119
120
|
"db.Exec(\"DELETE FROM orders WHERE id = $1\", id)", out)
|
|
120
121
|
self.assertIn(" sdk.go:6 [sdk] go-sdk-write chargeCard(): "
|
|
121
122
|
"sc.Charges.New(params)", out)
|
|
123
|
+
self.assertIn(" pkgclient.go:25 [sdk] go-pkgclient-write "
|
|
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)
|
|
122
128
|
for v in ("db.delete", "db.create", "http.submit", "sdk.charge",
|
|
123
129
|
"sdk.nested"):
|
|
124
130
|
self.assertEqual(verbs.get(v), "require_grant", v)
|
|
@@ -311,7 +317,7 @@ class JsonReportTest(unittest.TestCase):
|
|
|
311
317
|
self.assertEqual(code, 0, out)
|
|
312
318
|
doc = j.loads(out)
|
|
313
319
|
self.assertFalse(doc["go_hint"])
|
|
314
|
-
self.assertEqual(doc["files_scanned"],
|
|
320
|
+
self.assertEqual(doc["files_scanned"], 7)
|
|
315
321
|
go_findings = [f for f in doc["findings"]
|
|
316
322
|
if f["language"] == "go"]
|
|
317
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
|