Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
docs: refresh the v1 API audit against HEAD and rewrite it in plain terms (#21195)
Danny Xu5c65af471684
diff --git a/docs/design/v1-api-audit-2026-08.md b/docs/design/v1-api-audit-2026-08.mdindex c0c4de4502..86d4dbb085 100644--- a/docs/design/v1-api-audit-2026-08.md+++ b/docs/design/v1-api-audit-2026-08.md@@ -1,188 +1,290 @@-# Bytebase v1 API — consolidated audit+# Bytebase v1 API — audit-Against `main` @ `93671b00b0` (2026-08-04). 36 proto files, 205 RPCs.+What's wrong with the v1 API, in plain terms.-**Method.** Four parallel implementation-focused audits (multi-resource authz, CUSTOM-auth-enforcement, list/pagination correctness, field-behavior vs. reality), plus my own mechanical-sweeps and an independent run of Google's [api-linter](https://github.com/googleapis/api-linter).-The first audit was proto-only; this pass compares **the declared contract against what the-backend actually does**, which is where everything serious lives.+Audited against `93671b00b0` (2026-08-04); every finding below re-verified against `fd4ef828e6`+(2026-08-18), with HEAD line numbers. Findings are code-traced, not runtime-proven, except where+noted. Nothing here is patched yet. Fixed findings are removed and listed at the end.-**Verification legend.** ✅ = I read the code myself and confirmed the full chain.-◐ = agent-traced with exact citations, structurally consistent, not runtime-proven.+## The short version++| | Problem | Severity |+|---|---|---|+| T10 | A stolen session can change your password and switch off your 2FA | HIGH |+| T2 | Schema diff reads a second database without checking permission on it | HIGH |+| T15 | Rotating a leaked cloud credential can silently do nothing | HIGH |+| T13 | "Waiting for my approval" can show an empty page with a live Load More | HIGH |+| T14 | Paging through issues across projects skips some and repeats others | HIGH |+| T9 | On Cloud, 2FA codes can be guessed without limit, and no failed login is recorded | MED |+| T18a | Test-environment rights can cancel a running production migration | MED |+| T12 | Anonymous callers can enumerate emails, relay mail, and read your LDAP config | MED |+| T16 | Four `BatchGet` RPCs behave four different ways when an item is missing | MED |+| T18b | Concurrent permission edits silently lose one side, including a revoke | MED |+| T11 | A create-permission check is skipped on `allow_missing` updates | MED |+| T17 | Typing `"` in a search box breaks search | MED |+| T18c | Three smaller ones: broken filter, unpaginated list, half-finished delete | MED |----# TIER 2 — Cross-project authorization gaps+## Getting in, and staying in++### T9 · On Cloud, 2FA codes can be guessed without limit — MED++The password and MFA lockouts work by counting failed-login rows in the audit log. On Cloud the+sign-in page doesn't send a workspace ID, and with no workspace the audit row is never written — so+the counter reads zero forever and the limits never fire. `auth_service.go:180-189`++**This does not expose passwords on Cloud.** SaaS forces `DisallowPasswordSignin = true`+unconditionally (`auth_service.go:1624-1627`), and Cloud accounts are created with a random 32-byte+bcrypt hash (`:2049-2056`), so there is no guessable password to find. Email-code login — the actual+Cloud primary factor — carries its own attempt counter in the database, independent of the audit log:+5 tries per code, code destroyed on exhaustion, 10-minute expiry, constant-time compare, hashed at+rest (`verifyEmailCode`, `:1962-1984`). That path is properly protected.++**What is exposed is the second factor.** `completeMFALogin` gates on `checkMFALockout`+(`auth_service.go:1076`), which is the audit-row counter — inert on Cloud for the same reason. The+MFA temp token is a stateless JWT valid for 5 minutes and is not single-use, so an attacker holding+one can spend the whole window guessing TOTP codes (a 10⁶ space) or recovery codes with nothing+counting the misses. Reaching that point requires already passing the email-code step, i.e. access to+the victim's inbox — which is precisely the situation the second factor exists to survive.++Secondary: **no failed-login record is written on Cloud at all**, so there is nothing to alert or+investigate on.-**Shared root cause.** The ACL authorizes exactly ONE resource per request — `parent`, else-`name`, else `resource`, else `project`, and only if that field carries a `resource_reference`-annotation (`backend/api/v1/acl.go:667-685`). Any *second* resource name in the body is invisible-to it. `DiffSchema` (fix already written, patch `04`) was one instance; these are the rest.-The related CUSTOM-auth variant — the interceptor checks nothing at all, so the handler must-authorize every branch itself — was T4 (`SearchIssues`), now fixed.+Self-hosted is fixed and tested ([#21189](https://github.com/bytebase/bytebase/pull/21189)) — there+the finding was genuinely HIGH, because password signin is allowed. **Fix:** in SaaS, resolve the+workspace from the request host before authenticating, or count MFA failures somewhere other than+the audit log.-### T8 ◐ HIGH — two RPCs enforce nothing at all+### T10 · A borrowed session becomes permanent account takeover — HIGH-- **`CreateWorksheet`** (`worksheet_service.go:39-103`) — resolves the caller, checks the project exists, optionally checks the database belongs to it, then writes. No `CheckPermission`, no membership test; `parent` has no `resource_reference` so the interceptor contributes nothing. A bare member plants arbitrary SQL into any project's shared worksheet list, where legitimate members may open and run it.-- **`AIService.Chat`** (`ai_service.go:37-51`) — the `aiSetting.Enabled` toggle is the entire gate; the service holds no `iamManager`. Not a schema-exfiltration path (it dereferences no database or sheet), but it is unmetered use of the org's LLM endpoint on the org's key by any principal, with no rate limit and no audit.+Changing your own password doesn't require the current password, and switching off your own 2FA+doesn't require a code. So anyone who gets a session — stolen laptop, shared browser, leaked token —+converts that temporary access into permanent ownership of the account. Refresh tokens are revoked+on password change, but the attacker's own access token keeps working.++The frontend work in [#21193](https://github.com/bytebase/bytebase/pull/21193) split these screens+apart, but the backend is unchanged: there is still no current-password or recent-auth field on the+API. **Fix:** require the current password (or a fresh OTP) on both paths.+`user_service.go:371-378` (password), `:395-411` (MFA)----# TIER 3 — Authentication mechanism failures+## Doing more than you're allowed++### T2 · The permission check only looks at one resource per request — HIGH++The ACL interceptor authorizes exactly one resource name per request: `parent`, else `name`, else+`resource`, else `project`. Any *second* resource named in the body is invisible to it.++One live case: `DiffSchema` takes both a database and a changelog, and the changelog can belong to a+different project. Only the first is checked, so a caller can read schema out of a project they have+no access to. Every other known case is closed inside the handler; this is the last one, and the+parked patch `04` fixes it.++The real fix is the general one — teach the interceptor to collect *every* annotated resource field,+so the next second-resource field doesn't reopen the hole. `acl.go:708-726`,+`database_service.go:1047-1105`++### T18a · Test-environment rights can cancel a production migration — MED++`BatchCancelTaskRuns` checks your permission against the stage *you claim in the URL*, then cancels+task runs by ID without ever confirming those IDs belong to that stage. So permission to cancel in+test is enough to kill an in-flight production migration in the same project. Sibling handlers get+this right by reading the environment off the actual rows. `rollout_service.go:1034-1143`-### T9 ◐ HIGH — password and MFA brute-force lockout is inert+### T11 · A create check is skipped on `allow_missing` updates — MED-`checkPasswordLockout`/`checkMFALockout` count **audit-log rows** for failed logins-(`auth_service.go:826-834`, filtering `payload->>'method' = '/bytebase.v1.AuthService/Login'`-with non-zero status).+`UpdateGroup(allow_missing=true)` creates a group when none exists, but the create-permission check+is short-circuited for CUSTOM-auth RPCs, so nothing is verified. Harmless today only because every+member can create groups anyway — but the code comment right above it claims the check happens,+which is how this survives review.-✅ I confirmed the load-bearing half: a failed credential check returns at-`auth_service.go:145-148`, **before** `common.SetAuditWorkspaceID(ctx, workspaceID)` at `:169` —-the only such call on this path. The agent traced the rest: with no workspace in context, no-resources (the ACL interceptor returned early for `allow_without_credential`) and a nil response,-the audit interceptor's `parents` list stays empty and the write loop never runs.+Same root cause, wider: 15 of the 45 CUSTOM RPCs declare a `permission` annotation that is never+enforced. It's decorative, and it reads as protection. `acl.go:252-254`, `group_service.go:172-177`-If that holds, `passwordMaxFailedAttempts = 10/10min` and `mfaMaxFailedAttempts = 5/5min` never-fire — unlimited unauthenticated password and TOTP brute force against `/v1/auth/login`, with no-rate-limiting middleware anywhere in the stack (`backend/server/echo_routes.go:37-103`) and **no-failed-login record for detection**. No test covers the lockout.+---++## The API says OK and does nothing-**This one deserves a runtime check before anything else** — it is cheap to confirm (attempt 11-bad logins, see whether attempt 11 is refused) and it is the difference between "hardened" and-"no lockout at all".+### T15 · `update_mask` is ignored in four places — HIGH-### T10 ◐ HIGH — self password change and MFA disable require no re-authentication+The worst one: **rotating a leaked cloud credential can silently no-op.** `UpdateDataSource` decides+what to write based on the `authentication_type` in the request rather than the mask or the stored+value, so a request carrying only a new GCP credential falls through an empty branch and writes+nothing. You get HTTP 200 and the compromised key stays live. `instance_service.go:1346-1388`-`user_service.go:383-438`: on the self branch all checks are skipped by design. `case "password"`-calls `validatePassword`, which checks only the *policy* (`:282-295`), never the current password;-the sole guard is rejecting a new password identical to the old (`:435-438`). `case "mfa_enabled": false`-disables MFA with no OTP challenge unless workspace `Require_2Fa` is set. One borrowed session-becomes permanent account takeover. Contrast the email reset flow, which requires the code *and*-revokes all refresh tokens (`auth_service.go:1629`).+The other three lose data rather than fail to save it:-### T11 ◐ MED — the `allow_missing` create-permission guard is dead for every CUSTOM RPC+- **`UpdateSetting` replaces whole settings.** Updating your Slack config wipes stored Feishu, WeCom,+ Lark, DingTalk and Teams secrets — and it *validates* the mask path first, then ignores it. For+ environments the replace cascades into every instance and database. `setting_service.go:508-512`+- **`UpdateDatabaseCatalog` never reads a mask at all** and replaces the whole config column, wiping+ other schemas' classification and masking. Its proto comment refers to an `update_mask` field that+ doesn't exist. `database_catalog_service.go:96-139`+- **`UpdateIssue` implements four fields** and silently drops the rest, so `update_mask=["status"]`+ returns 200 and does nothing. `issue_service.go:883-910`-`acl.go:190-193` copies `AuthMethod` into the secondary create-check context, and `acl.go:246`-short-circuits it. So `UpdateGroup(allow_missing=true)` creates a group with no create check —-under a comment asserting the opposite (`group_service.go:167-177`: *"Permission check is now-handled by the ACL interceptor which verifies both bb.groups.update and bb.groups.create"*).-Masked today only because `bb.groups.create` is in the member role anyway.+Underneath: some Update RPCs reject unknown mask paths, others ignore them, in four different error+wordings. There's no shared validator.-Related: 20 of the 44 CUSTOM RPCs also declare `(bytebase.v1.permission)`, which is **dead-annotation** — it is never enforced for non-IAM auth methods.+### T18b · Concurrent permission edits silently lose one side — MED-**CUSTOM enforcement tally across all 44:** 27 ENFORCES · 14 PARTIAL · 2 DOES-NOT-ENFORCE.+`IamPolicy` has an etag for exactly this, and the docs promise it triggers ABORTED — but the+handlers only check the etag on the *request wrapper*, never the one inside the policy. A normal+read-modify-write round-trips the policy etag and has it silently discarded, so two admins editing+permissions at once means one edit vanishes. If the lost edit was a revoke, access stays granted.-### T12 ◐ MED — unauthenticated surface+The saved-query path already implements this correctly, so the pattern is in-tree.+`project_service.go:586`, `workspace_service.go:437`-12 RPCs are `allow_without_credential`. Worth attention:+### T18c-i · Deleting several projects can half-finish — MED-- **`GetActuatorInfo`** takes `name` as-is and `acl.go:126` returns before the workspace-mismatch check at `:155`, so `GET /v1/workspaces/{anyID}/actuator/info` returns *that* workspace's default project ID, user/instance counts, external URL, and security posture (SSO configured, signup disallowed, 2FA required).-- **`Signup`** answers `AlreadyExists` for a registered email *before* the `DisallowSignup` check (`auth_service.go:272` vs `:297`) — a clean user-enumeration oracle in SaaS, contradicting the care taken in `RequestPasswordReset` and `SendEmailLoginCode`.-- **`SendEmailLoginCode`** deliberately skips the existence check for `LOGIN` (`:1759`), and the 60s cooldown is keyed per `(email, purpose)` — so it is an unauthenticated mail relay to arbitrary recipients over the customer's SMTP.-- **`ListIdentityProviders`** returns any named workspace's SSO config to anonymous callers — secrets redacted, but LDAP **host, port, bind DN, base DN, user filter** exposed. (Correction to a plausible worse reading: the empty-`parent` branch is *not* a cross-tenant dump; `store/idp.go:167-171` applies `WHERE workspace IS NULL`.)+`BatchDeleteProjects` purges in a loop with no transaction. A failure partway leaves some projects+irreversibly purged, and the error names only the one that failed — not the ones already gone.+`project_service.go:485-489`----# TIER 4 — Correctness bugs+## Lists that return the wrong rows-### T13 ◐ HIGH — filter-after-pagination (the `SearchProjects` bug is not unique)+### T13 · Issue filters run after the page is cut — HIGH-Same shape as the one already fixed in patch `03`:+`approval_status` and `current_approver` never reach SQL. The database returns a full page, the page+token is minted, and *then* non-matching issues are dropped in Go. So filtering by "waiting for my+approval" in a busy workspace shows an empty list with a live "Load more" button underneath.-- **`ListIssues` / `SearchIssues`** — `approval_status` and `current_approver` are applied in Go during conversion (`issue_service_converter.go:29-41`) *after* the page and token are computed (`issue_service.go:273-280`, `:347-354`). This is the "My Issues" page (`MyIssuesPage.tsx:91`), and unlike the project store, `stores/app/issue.ts` has **no** empty-page workaround. Filtering by "waiting for my approval" in a large workspace renders an empty list with a live "Load more" button.-- **`SearchWorksheets`** — worse: `store.ListWorkSheets` has *zero* visibility predicate (`store/worksheet.go:106-155`), so other users' PRIVATE worksheets are fetched, counted toward the page, then dropped (`worksheet_service.go:318-342`).+This is the default My Issues view, and there's no empty-page workaround on the frontend.+`issue_service_converter.go:29-41`, `issue_service.go:139-148`-### T14 ◐ HIGH — cross-project issue pagination skips and duplicates rows+(Same shape as the `SearchProjects` bug that parked patch `03` fixes — also still unmerged.)-`issue.id` is per-project (`LATEST.sql:293-310`, `PRIMARY KEY (project, id)`), but the cross-project-sort is `ORDER BY issue.id DESC` (`store/issue.go:323`, `:400-406`). Ties are the dominant case,-not an edge case, so `LIMIT/OFFSET` may order a tie group differently between pages — rows are-silently omitted from one page and duplicated into another. "My Issues" always sends `projects/-`.-Needs a unique tiebreaker, e.g. `(issue.project, issue.id)`.+### T14 · Paging issues across projects skips and repeats rows — HIGH-Softer variant (T-low): nine stores paginate on `created_at`, which is `DEFAULT now()` —-transaction time, so same-transaction rows tie exactly.+Issue IDs restart from 1 in each project, but the cross-project list sorts by ID alone. Issues from+different projects constantly share an ID, and tied rows can land in a different order on each query+— so paging forward drops some issues entirely and shows others twice. My Issues always queries+across all projects, so this is the common path, not an edge case.-### T15 ◐ HIGH — `update_mask` silently ignored+**Fix:** sort by `(project, id)`, which is the primary key. `store/issue.go:323`-- **`UpdateDataSource` credential rotation no-ops.** `instance_service.go:1304`/`:1343` switch on the **request's** `authentication_type`; a mask carrying only `gcp_credential` leaves it zero-valued, falls to an empty `default:`, and writes nothing — HTTP 200 while the compromised credential stays live.-- **`UpdateIssue`** implements only title/description/labels/draft (`issue_service.go:884`); `status`, `type`, `plan`, `risk_level`, `role_grant` are writable in proto with no case, so `update_mask=["status"]` returns 200 and does nothing.-- **`UpdateSetting`** ignores the mask entirely for 5 of 8 settings (full replace, `setting_service.go:509-513`). `update_mask=["value.app_im.slack"]` wipes stored Feishu/WeCom/Lark/DingTalk/Teams secrets. For `ENVIRONMENT` the replace cascades into `UpdateInstance` + `BatchUpdateDatabases` across every instance and database (`:430`, `:437`).-- **`UpdateDatabaseCatalog`** names an `update_mask` that doesn't exist in the request (already reported) and full-replaces the config column, wiping other schemas' classification and masking config.-- Four Update RPCs silently ignore unknown mask paths; four others reject them. Inconsistent contract.+### T16 · Four `BatchGet` RPCs, four behaviors — MED-### T16 ◐ MED — `BatchGet*`: four RPCs, four different behaviors, none documented+Ask for five databases and get three back, with no way to tell which two are missing. Ask for five+projects with one missing and the entire call 404s. `BatchGetUsers` returns store order, not request+order. `BatchGetGroups` swallows every error, so a database failure is indistinguishable from "that+group doesn't exist."-| RPC | missing entry | no-permission entry |-|---|---|---|-| `BatchGetDatabases` | silently skipped | silently skipped |-| `BatchGetProjects` | **whole batch 404s** | whole batch 403s |-| `BatchGetUsers` | silently skipped, **store order** | n/a |-| `BatchGetGroups` | silently skipped | **all errors swallowed** (a DB failure looks like "absent") |+None of this is documented, and the responses are bare repeated lists — so any client matching+`names[i]` to `results[i]` silently mis-attributes data. Contradicts AIP-231.++### T18c-ii · Two smaller list bugs — MED++- **The query-history `instance ==` filter always returns nothing.** It compares an instance name+ against a longer stored value using `LIKE` with no wildcard. The proto documents the broken form.+ `store/query_history.go:255-256`+- **`ListTaskRuns` has no pagination and no limit** — and its documented wildcard parent pulls an+ entire rollout in one call, on the table that grows fastest. `store/task_run.go:65-131`++### T17 · Typing a quote breaks search — MED++The frontend builds CEL filter strings by interpolating raw user input. There's an escaping helper+that exists precisely for this, used at 6 sites; 11 others still interpolate raw. Type a `"` in+those search boxes and search fails with `InvalidArgument`. It also allows filter-semantics+injection — not a privilege boundary, since the filter only narrows an already-authorized list.-Responses are bare `repeated X` with no ordering or omission contract, so any client zipping-`names[i]` to `results[i]` mis-attributes data. Contradicts AIP-231.+Worst site: `accessGrant.ts:35` interpolates SQL statement text raw, while lines 38-40 right next to+it do it safely.-### T17 ◐ MED — frontend builds CEL filters without escaping+---++## What anonymous callers can learn++### T12 · The unauthenticated surface — MED++12 RPCs allow calls with no credentials. Four are worth attention:-`frontend/src/utils/v1/cel.ts:12-22` exists precisely for this and documents the hazard — but only-2 of 14 call sites use it. The other 12 (`stores/app/project.ts:36`, `instance.ts:41,53,56`,-`user.ts:35`, `group.ts:35`, `serviceAccount.ts:41`, `plan.ts:19`, `accessGrant.ts:35`,-`utils.ts:65,136,142`) interpolate raw. Typing a `"` in those search boxes breaks search with-`InvalidArgument`; it also allows filter-semantics injection (not a privilege boundary — the-filter only narrows an already-authorized list).+- **Email enumeration.** `Signup` answers "already registered" *before* it checks whether signup is+ even allowed, so anyone can test whether an email has an account — on a workspace with signup+ disabled. `auth_service.go:328-334`+- **Open mail relay.** `SendEmailLoginCode` will send to any address over the customer's SMTP.+ [#21177](https://github.com/bytebase/bytebase/pull/21177) added a domain check, but it only+ applies if the domain-restriction license feature is on, enforcement is enabled, *and* a domain+ list is set — no default deployment qualifies. The 60s cooldown is per recipient, so volume scales+ with the address list. `user_service.go:753-785`+- **LDAP config disclosure.** `ListIdentityProviders` hands any caller the SSO config for any+ workspace ID they guess: LDAP host, port, bind DN, base DN, user filter, plus OAuth/OIDC endpoints+ and client IDs. Passwords and secrets are redacted. `idp_service.go:55-85`, `:526-535`+- **Workspace-existence oracle.** `GetAuthenticationRestriction` (which replaced the actuator leak,+ now fixed) is anonymous by design and doesn't need membership. Naming a real workspace returns+ 200, a fake one returns `InvalidArgument`. The pre-login page genuinely needs most of these+ fields; the oracle is the part worth closing. `auth_service.go:140-179`-### T18 ◐ MED — other+### T18c-iii · `CheckRelease` error codes leak existence — MED · ✅ read myself-- **`CheckRelease` target rejection is an existence oracle** ✅ — a target database that exists in another project returns `InvalidArgument` ("does not belong to project", `release_service_check.go:95-97`, emitted after the row fetch), while a nonexistent one returns `NotFound` — so `bb.releases.check` on any one project distinguishes which `instances/{i}/databases/{d}` names exist workspace-wide. Contrast the `NotFound` convention the `BatchCreateRevisions` fix adopted for the same shape. Introduced alongside the otherwise-correct target scoping in [#21102](https://github.com/bytebase/bytebase/pull/21102); the fix should land with a regression test asserting `NotFound` for both existing and nonexistent foreign targets.-- **`BatchDeleteProjects` partial purge** (`project_service.go:504-508`): soft-delete is one statement, hard-delete is a loop; a mid-loop failure leaves some projects irreversibly purged and the rest soft-deleted, with no indication which.-- **`BatchCancelTaskRuns`** authorizes a caller-asserted stage but cancels by UID without `PlanUID`/`Environment` predicates (`rollout_service.go:1073-1110`), so test-environment rights can cancel in-flight production migrations. Sibling handlers derive the environment from real rows.-- **`SearchQueryHistories` `instance ==` filter always matches zero rows** — `store/query_history.go:247` uses `LIKE` with no `%` against a longer stored string; the proto documents the broken form (`query_history_service.proto:68,75`).-- **`ListTaskRuns` is unpaginated in the proto and unbounded in the store** (`rollout_service.proto:257`, `store/task_run.go:99-121`) — and `task_run` is the canonical unbounded-growth table, with a documented wildcard parent that fetches an entire rollout.-- **Worksheet write and delete are gated on `bb.worksheets.get`** (`worksheet_service.go:664-675`), which SQL Editor Read User holds — that role can rewrite and hard-delete any PROJECT_WRITE worksheet.-- **`IamPolicy.etag` is decorative**: handlers check `SetIamPolicyRequest.etag` (field 3) but never `IamPolicy.etag` (field 2), so the natural read-modify-write round-trip never triggers ABORTED and concurrent edits silently lose one side — including a role revocation.+Point it at a database in someone else's project and you get `InvalidArgument`; point it at one that+doesn't exist and you get `NotFound`. So permission to check releases on any single project lets you+map which databases exist workspace-wide. [#21102](https://github.com/bytebase/bytebase/pull/21102)+added a third distinguishable error that also leaks instance ownership.++**Fix:** return `NotFound` for both, matching the convention `BatchCreateRevisions` already adopted,+with a regression test. `release_service_check.go:92-111`----# TIER 5 — Structural / AIP+## Structural / AIP (not re-run)++Numbers below are the 2026-08-04 baseline; the worksheet→saved-query rename has since moved some of+this surface. Re-measure before acting.-Objective run of Google's api-linter: **3808 raw findings**, but 2060 are `field-behavior-required`-(the repo opts out via `FIELD_NOT_REQUIRED` in `buf.yaml`), 1027 are missing comments, and 144 are-Google-internal java/package rules. **567 substantive**, concentrated in `database_service` (63),-`rollout_service` (58), `subscription_service` (44), `instance_service` (42).+An api-linter run produced 3808 raw findings, of which **567 are substantive** — the rest are opted-out+field-behavior rules, missing comments, and Google-internal package rules. They concentrate in+`database_service`, `rollout_service`, `subscription_service`, and `instance_service`. It confirms+the hand audit rather than contradicting it: the same 12 unpaginated List RPCs, the same 7 `state`+fields missing `OUTPUT_ONLY`, the same enum zero-value naming. Also still open: 28 RPCs lack the+mandated `// Permissions required:` comment, and 22 files have string fields with no protovalidate+constraints.-It independently confirms the first audit rather than contradicting it: the same 12 unpaginated-List RPCs, the same 7 `state` fields missing `OUTPUT_ONLY`, the same enum zero-value naming-(`FORMAT_UNSPECIFIED` → `EXPORT_FORMAT_UNSPECIFIED`), and the `schemaString`/`sdlSchema`/`changelogs`-HTTP patterns in `database_service` that match no declared resource pattern. It adds a cleaner-framing for 30 `name` fields: they want `IDENTIFIER`.+----Still open from the first pass: 28 of 205 RPCs lack the mandated `// Permissions required:`-comment; 22 files have string fields and zero protovalidate constraints despite-`VALIDATION_STANDARDS.md`.+## What I'd do, in order++1. **Require re-authentication for password change and 2FA disable (T10).** It's the one finding+ here that turns a temporary compromise into a permanent one, and it affects both deployments.+2. **Fix the ACL class, not the instance (T2).** Teach the interceptor to collect every annotated+ resource field, then annotate `DiffSchema`. Otherwise the next second-resource field reopens it.+3. **Make credential rotation fail loudly (T15).** A security operation that returns 200 and does+ nothing is worse than one that errors.+4. **Close the SaaS half of T9.** Lower severity than it first looked — Cloud's primary factor is+ protected independently — but the second factor currently has no attempt limit, and no failed+ login is recorded anywhere.+5. **Fail closed on auth annotations, and put api-linter in CI.** Reject+ `AUTH_METHOD_UNSPECIFIED` at startup; make a `permission` on a CUSTOM RPC either enforced or a+ build error, since 15 are decorative. None of Tier 5 was visible to `buf lint`'s BASIC profile,+ which is why it accumulated.----# What I'd do, in order--1. **Runtime-confirm T9.** Eleven bad logins. If the eleventh is accepted, there is no lockout and that outranks everything else here.-2. **Close the multi-resource ACL class, not the instances** (the pending `DiffSchema` patch): teach `getResourceFromRequest` to collect *every* `resource_reference`d field including oneof and repeated members, then annotate `DiffSchemaRequest.changelog`. Every known instance is now closed handler-side — `Revision.release/file/task_run` (provenance must name the authorized database's own project) and `CheckReleaseRequest.targets` (targets validated against the parent project) — but the interceptor-level generalization is what keeps the next second-resource field from reopening the class. `UpdateDatabase`'s project-transfer case (`acl.go:604-624`) is the in-repo precedent.-3. **Fail closed**: reject `AUTH_METHOD_UNSPECIFIED` at startup; make `permission` on a CUSTOM RPC either enforced or a build error, since 20 of them are currently decorative.-4. **Wire api-linter into CI** at the 474-finding baseline. None of Tier 5 was visible to `buf lint`'s `BASIC` profile, which is why it accumulated.--**Note on scope.** Tier 2–3 are security issues in a shipped product, and everything here is-still a report — untouched. Resolved findings are removed from this document (T1/T3 earlier;-T2 via the INPUT_ONLY read-path fix; T5/T6 via the sheet-blob scoping PR-[#21143](https://github.com/bytebase/bytebase/pull/21143) — `sheet_blob_ref` gives sheets a-per-project ownership model enforced by the store's scoped accessors, and `BatchCreateRevisions`-now rejects provenance naming any project but the authorized database's own, without echoing the-hash; design in `sheet-blob-scoping.md` and `sheet-history-on-database-transfer.md`. T7 via the-project-instances integration [#21102](https://github.com/bytebase/bytebase/pull/21102), which-landed after this audit's baseline: every `CheckRelease` target — database, project-form, or-database group — is validated against the request's parent project before any schema read or-check runs, so `bb.releases.check` covers everything the RPC touches. Its rejection error-code carries a residual existence oracle, tracked as a T18 item). The three patches from earlier in the session-(`SearchProjects` proto comment, `SearchProjects` pagination, `DiffSchema` ACL) remain parked-and still apply cleanly.+## Already resolved++| Finding | Resolution |+|---|---|+| T1, T3 | Fixed earlier in the session |+| T2 (INPUT_ONLY) | Read-path fix |+| T5, T6 | [#21143](https://github.com/bytebase/bytebase/pull/21143) — `sheet_blob_ref` gives sheets per-project ownership; `BatchCreateRevisions` rejects foreign-project provenance without echoing the hash |+| T7 | [#21102](https://github.com/bytebase/bytebase/pull/21102) — every `CheckRelease` target validated against the parent project before any schema read (its error codes still leak existence — T18c-iii) |+| T8 `CreateWorksheet` | [#21169](https://github.com/bytebase/bytebase/pull/21169) — `CreateSavedQuery` is now IAM-enforced; Workspace Member holds no saved-query permission, and new queries start creator-private |+| T12 `GetActuatorInfo` | [#21184](https://github.com/bytebase/bytebase/pull/21184) — anonymous access and the `name` field removed; workspace now comes from the token (the narrower surface that replaced it is T12) |+| T13 `SearchWorksheets` | [#21160](https://github.com/bytebase/bytebase/pull/21160) + [#21178](https://github.com/bytebase/bytebase/pull/21178) — visibility predicate pushed into SQL before `LIMIT` |+| T18 worksheet write/delete | [#21169](https://github.com/bytebase/bytebase/pull/21169) + [#21181](https://github.com/bytebase/bytebase/pull/21181) — per-verb permissions; SQL Editor Read User can no longer rewrite or delete |+| T9 (self-hosted) | [#21189](https://github.com/bytebase/bytebase/pull/21189) — failed logins are audited and the lockout is tested end-to-end (SaaS remainder above) |++**`AIService.Chat` — accepted, not fixed** (2026-08-18). `Chat` requires an authenticated workspace+principal and touches no database or sheet, so the only exposure is LLM spend. On Cloud the feature+is free on Bytebase's own key, so no customer budget is at risk and abuse is our own spend-management+problem. Self-hosted, the admin supplies the org's key when enabling it, so org-wide use by members+is the intended model. The missing per-user rate limit and audit are accepted with that disposition.++The three patches from earlier in the session (`SearchProjects` proto comment, `SearchProjects`+pagination, `DiffSchema` ACL) remain parked and still apply — none landed independently, and all+three targets are still present at HEAD.