Judge site data table reads by the fields the spec declares (ADR 0007 amendment)
With data_tables in acceptance.json, a public route over a site data table fails check 33 only when the table read holds a personal field by the spec or the classifier. The table is resolved from a literal GetTableByKey key; an unresolved read falls back to any declared table being personal. Without data_tables every read stays personal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8b8afc044d
commit
945ca508e0
@ -49,3 +49,20 @@ Consequences:
|
||||
- First-party plugins keep the default name list and warnings only.
|
||||
|
||||
Keywords: personal data classifier, deterministic classifier, personalKind, sampleKind, migrationColumns, personalTables, personalSettings, site data table, DataTables, ListRows, GetRow, FindRowByField, GetPluginSettings, check 33, check 36, check 37, visitor form, free text, inet, cidr, notes column, WO-100, gap 5, gap 6, gap 7, acceptance.json
|
||||
|
||||
## Amendment 2026-11-22: declared site data tables
|
||||
|
||||
Since orchestrator WO-099 the spec declares the site data tables a plugin reads (`data_tables[]`
|
||||
with `key` and `fields[]`), and the rule above refused the events plugin's public `/events.ics`
|
||||
feed. When the spec has `data_tables`, a site data table read counts as personal only when the
|
||||
table it reads has a field marked `personal` or one the classifier calls personal (by name or
|
||||
sample shape), so a public route over an `events` table passes and one over a table with an
|
||||
`email` field fails even when the spec marks it not personal. The table is resolved from the
|
||||
literal key of a `GetTableByKey` call in the same function; a read whose table cannot be resolved
|
||||
statically counts as personal when any declared table is, and a literal key the spec does not
|
||||
declare counts as personal. Without `data_tables` in the spec the earlier rule stands: every read
|
||||
is personal. Fixtures `events-datatable-pass` and `subscribers-datatable-fail`, test
|
||||
`TestPluginRoutesJudgeSiteDataTablesByTheirDeclaredFields`. Declared data table fields also join
|
||||
the personal names the log and egress rules use.
|
||||
|
||||
Keywords: data_tables, declared site data table, dataTableReadPersonal, personalDataTables, GetTableByKey, events.ics, events-datatable-pass, subscribers-datatable-fail
|
||||
|
||||
@ -54,7 +54,11 @@ type acceptanceSpec struct {
|
||||
Host string `json:"host"`
|
||||
Sends []string `json:"sends"`
|
||||
} `json:"outbound_hosts"`
|
||||
Settings []acceptanceField `json:"settings"`
|
||||
Settings []acceptanceField `json:"settings"`
|
||||
DataTables []struct {
|
||||
Key string `json:"key"`
|
||||
Fields []acceptanceField `json:"fields"`
|
||||
} `json:"data_tables"`
|
||||
} `json:"spec"`
|
||||
}
|
||||
|
||||
@ -94,6 +98,9 @@ type pluginSource struct {
|
||||
personalTables map[string]bool
|
||||
// personalSettings is true when a plugin setting holds personal data.
|
||||
personalSettings bool
|
||||
// personalDataTables maps each site data table the spec declares to
|
||||
// whether it holds a personal field; nil when the spec declares none.
|
||||
personalDataTables map[string]bool
|
||||
// sends maps an outbound host to the normalised names the spec lets it receive.
|
||||
sends map[string]map[string]bool
|
||||
// declFile maps each function declaration to the file that holds it.
|
||||
@ -248,6 +255,12 @@ func (src *pluginSource) indexSpec() {
|
||||
addFields(r.Fields, strings.EqualFold(r.Method, "POST") && (r.Access == "public" || r.Access == "visitor"))
|
||||
}
|
||||
src.personalSettings = addFields(s.Settings, false)
|
||||
if len(s.DataTables) > 0 {
|
||||
src.personalDataTables = map[string]bool{}
|
||||
for _, dt := range s.DataTables {
|
||||
src.personalDataTables[dt.Key] = addFields(dt.Fields, false)
|
||||
}
|
||||
}
|
||||
markTable := func(table string, cols []string) {
|
||||
for _, c := range cols {
|
||||
src.personal[normName(c)] = c
|
||||
@ -481,6 +494,7 @@ func (src *pluginSource) personalRefs(f *pluginFile, n ast.Node) []string {
|
||||
// sqlc query or the table's generated row type.
|
||||
func (src *pluginSource) storedPersonalReads(n ast.Node) []string {
|
||||
seen := map[string]bool{}
|
||||
scope := n
|
||||
ast.Inspect(n, func(n ast.Node) bool {
|
||||
switch x := n.(type) {
|
||||
case *ast.CallExpr:
|
||||
@ -488,10 +502,10 @@ func (src *pluginSource) storedPersonalReads(n ast.Node) []string {
|
||||
if t, ok := src.readQueries[sel.Sel.Name]; ok {
|
||||
seen[t+" ("+sel.Sel.Name+")"] = true
|
||||
}
|
||||
// Site data tables have fields nobody declares, so in a generated
|
||||
// plugin every read of one counts as personal.
|
||||
if src.generated && siteDataTableReads[sel.Sel.Name] && strings.Contains(shortExpr(sel.X), "DataTables") {
|
||||
seen["site data table ("+sel.Sel.Name+")"] = true
|
||||
if label, personal := src.dataTableReadPersonal(scope); personal {
|
||||
seen["site data table "+label+"("+sel.Sel.Name+")"] = true
|
||||
}
|
||||
}
|
||||
if src.personalSettings && sel.Sel.Name == "GetPluginSettings" {
|
||||
seen["plugin settings ("+sel.Sel.Name+")"] = true
|
||||
@ -513,6 +527,48 @@ func (src *pluginSource) storedPersonalReads(n ast.Node) []string {
|
||||
|
||||
var siteDataTableReads = map[string]bool{"ListRows": true, "GetRow": true, "FindRowByField": true}
|
||||
|
||||
// dataTableReadPersonal decides whether a site data table read inside n reads
|
||||
// personal data. Without data_tables in the spec every read is personal. With
|
||||
// them, the tables n names by a literal GetTableByKey key decide; a read whose
|
||||
// table cannot be resolved is personal when any declared table is.
|
||||
func (src *pluginSource) dataTableReadPersonal(n ast.Node) (string, bool) {
|
||||
if src.personalDataTables == nil {
|
||||
return "", true
|
||||
}
|
||||
var keys []string
|
||||
ast.Inspect(n, func(c ast.Node) bool {
|
||||
call, ok := c.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
sel, ok := call.Fun.(*ast.SelectorExpr)
|
||||
if !ok || sel.Sel.Name != "GetTableByKey" || len(call.Args) != 2 {
|
||||
return true
|
||||
}
|
||||
if lit, ok := call.Args[1].(*ast.BasicLit); ok && lit.Kind == token.STRING {
|
||||
if k, err := strconv.Unquote(lit.Value); err == nil {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
if len(keys) == 0 {
|
||||
for k, personal := range src.personalDataTables {
|
||||
if personal {
|
||||
return k + " ", true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
for _, k := range keys {
|
||||
personal, declared := src.personalDataTables[k]
|
||||
if personal || !declared {
|
||||
return k + " ", true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func sortedKeys(m map[string]bool) []string {
|
||||
out := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
|
||||
@ -359,3 +359,12 @@ func TestPluginClassifierOverridesTheSpecsPersonalFlags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginRoutesJudgeSiteDataTablesByTheirDeclaredFields(t *testing.T) {
|
||||
if got := checkPluginRoutes(pluginRuleFixture(t, "events-datatable-pass")); len(got) != 0 {
|
||||
t.Fatalf("a public route over the events data table must pass: %v", got)
|
||||
}
|
||||
wantFindings(t, checkPluginRoutes(pluginRuleFixture(t, "subscribers-datatable-fail")), map[string]string{
|
||||
"handler.go:25": "reads personal data from table site data table subscribers (ListRows)",
|
||||
})
|
||||
}
|
||||
|
||||
7
testdata/pluginrules/events-datatable-pass/acceptance.json
vendored
Normal file
7
testdata/pluginrules/events-datatable-pass/acceptance.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{"version": 1, "name": "upcoming-events-5d1e22",
|
||||
"spec": {
|
||||
"blocks": [{"key": "upcoming_events", "source": "data_table:events", "fields": []}],
|
||||
"data_tables": [{"key": "events", "fields": [{"name": "title", "sample": "Roof safety open day", "personal": false}, {"name": "starts_at", "sample": "2026-12-05T10:00", "personal": false}, {"name": "location", "sample": "The yard, Ballarat", "personal": false}]}],
|
||||
"routes": [{"method": "GET", "path": "/events.ics", "access": "public", "fields": []}],
|
||||
"outbound_hosts": [], "settings": []
|
||||
}}
|
||||
41
testdata/pluginrules/events-datatable-pass/handler.go
vendored
Normal file
41
testdata/pluginrules/events-datatable-pass/handler.go
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
||||
"git.dev.alexdunmow.com/block/pluginsdk/route"
|
||||
)
|
||||
|
||||
const pluginName = "upcoming-events-5d1e22"
|
||||
|
||||
// Registration is the plugin entry registration.
|
||||
var Registration = plugin.PluginRegistration{
|
||||
Name: pluginName,
|
||||
Version: "1.0.0",
|
||||
HTTPHandler: newHTTPHandler,
|
||||
}
|
||||
|
||||
var current plugin.CoreServices
|
||||
|
||||
func newHTTPHandler(deps plugin.CoreServices) http.Handler {
|
||||
current = deps
|
||||
r := route.New(pluginName)
|
||||
r.Handle(http.MethodGet, "/events.ics", route.Public, handleList)
|
||||
return r
|
||||
}
|
||||
|
||||
func handleList(w http.ResponseWriter, r *http.Request) {
|
||||
table, err := current.DataTables.GetTableByKey(r.Context(), "events")
|
||||
if err != nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
rows, err := current.DataTables.ListRows(r.Context(), table.ID, 100, 0)
|
||||
if err != nil {
|
||||
http.Error(w, "could not load rows", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(rows)
|
||||
}
|
||||
4
testdata/pluginrules/events-datatable-pass/plugin.mod
vendored
Normal file
4
testdata/pluginrules/events-datatable-pass/plugin.mod
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
name = "upcoming-events-5d1e22"
|
||||
version = "1.0.0"
|
||||
kind = "plugin"
|
||||
private = true
|
||||
8
testdata/pluginrules/subscribers-datatable-fail/acceptance.json
vendored
Normal file
8
testdata/pluginrules/subscribers-datatable-fail/acceptance.json
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
{"version": 1, "name": "newsletter-9a0b11",
|
||||
"spec": {
|
||||
"blocks": [{"key": "subscribers", "source": "data_table:subscribers", "fields": []}],
|
||||
"data_tables": [{"key": "events", "fields": [{"name": "title", "sample": "Open day", "personal": false}]},
|
||||
{"key": "subscribers", "fields": [{"name": "email", "sample": "jo@example.com", "personal": false}, {"name": "joined", "sample": "2026-11-01", "personal": false}]}],
|
||||
"routes": [{"method": "GET", "path": "/subscribers", "access": "public", "fields": []}],
|
||||
"outbound_hosts": [], "settings": []
|
||||
}}
|
||||
41
testdata/pluginrules/subscribers-datatable-fail/handler.go
vendored
Normal file
41
testdata/pluginrules/subscribers-datatable-fail/handler.go
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
||||
"git.dev.alexdunmow.com/block/pluginsdk/route"
|
||||
)
|
||||
|
||||
const pluginName = "newsletter-9a0b11"
|
||||
|
||||
// Registration is the plugin entry registration.
|
||||
var Registration = plugin.PluginRegistration{
|
||||
Name: pluginName,
|
||||
Version: "1.0.0",
|
||||
HTTPHandler: newHTTPHandler,
|
||||
}
|
||||
|
||||
var current plugin.CoreServices
|
||||
|
||||
func newHTTPHandler(deps plugin.CoreServices) http.Handler {
|
||||
current = deps
|
||||
r := route.New(pluginName)
|
||||
r.Handle(http.MethodGet, "/subscribers", route.Public, handleList)
|
||||
return r
|
||||
}
|
||||
|
||||
func handleList(w http.ResponseWriter, r *http.Request) {
|
||||
table, err := current.DataTables.GetTableByKey(r.Context(), "subscribers")
|
||||
if err != nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
rows, err := current.DataTables.ListRows(r.Context(), table.ID, 100, 0)
|
||||
if err != nil {
|
||||
http.Error(w, "could not load rows", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(rows)
|
||||
}
|
||||
4
testdata/pluginrules/subscribers-datatable-fail/plugin.mod
vendored
Normal file
4
testdata/pluginrules/subscribers-datatable-fail/plugin.mod
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
name = "newsletter-9a0b11"
|
||||
version = "1.0.0"
|
||||
kind = "plugin"
|
||||
private = true
|
||||
Loading…
x
Reference in New Issue
Block a user