🐛 Forward only backend rows to the admin console audit log (#13361)

Any signed-in profile can push events with any allowlisted name through
the browser endpoint and point them at any organization or member. The
admin console consumer forwarded those rows like real ones, so a user
could add forged entries to another organization's audit log.

The consumer now forwards an allowlisted row only when its source is
"backend". Browser rows count as skipped, so the cursor still passes
them. Every allowlisted name has a backend producer; the six names the
Admin Console browser used to send are recorded by its server now
(penpot/penpot-nitrate#901).

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Juanfran 2026-11-26 13:24:46 +01:00 committed by GitHub
parent 9c61a5bd9d
commit 1ebb5ee6d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 9 deletions

View File

@ -10,9 +10,9 @@
It reads the stream from its own cursor and ingests the allowlisted
events, enriched with the name of their team and the emails of the
profiles they mention (the admin console shows people, not ids). The
events outside the allowlist, and the telemetry shadows, count as
skipped for the cursor: they are passed over and never reach the
destination.
events outside the allowlist, the rows the browser pushed and the
telemetry shadows count as skipped for the cursor: they are passed
over and never reach the destination.
The allowlist lives here: it is this consumer's contract, not the
producer's (the producer only inserts rows). The component starts the
@ -26,7 +26,6 @@
[app.common.uuid :as uuid]
[app.config :as cf]
[app.db :as db]
[app.loggers.audit :as audit]
[app.loggers.audit.consumers :as consumers]
[app.metrics :as mtx]
[app.nitrate :as nitrate]
@ -35,7 +34,15 @@
(def event-names
"The event names the admin console archives. Each consumer owns its
filter now: the producer only inserts the row, and this consumer
decides on read which events concern it."
decides on read which events concern it.
Only rows with `source` \"backend\" are archived. Any signed-in
profile can push a row with any of these names through the browser
endpoint (`push-audit-events`, `source` \"frontend\") and point it at
any organization or member, so a browser row is never evidence that
the action happened. Every name here has a backend producer; there is
no browser exception. The telemetry shadows are skipped by the same
rule."
#{"accept-organization-invitation"
"accept-organization-invitation-from"
"accept-team-invitation"
@ -224,7 +231,7 @@
a send failure."
[cfg rows]
(let [events (filterv #(and (contains? event-names (:name %))
(not (audit/telemetry-shadow-source? (:source %))))
(= "backend" (:source %)))
rows)
total (count rows)
skipped (- total (count events))
@ -258,8 +265,8 @@
(defn- process-chunk
"Send one chunk to the admin console. Returns {:processed :skipped}:
the row outside the allowlist (and the telemetry shadows) count as
skipped. Throws on failure, same contract as the nexus one."
the rows outside the allowlist, or not recorded by the backend, count
as skipped. Throws on failure, same contract as the nexus one."
[cfg rows]
(let [decoded (mapv consumers/decode-row rows)
_ (l/trc :hint "consumer events chunk"

View File

@ -35,7 +35,8 @@
[cuerdas.core :as str]
[integrant.core :as ig]
[mockery.core :refer [with-mocks]]
[promesa.exec :as px])
[promesa.exec :as px]
[yetti.request])
(:import
io.prometheus.client.Counter
io.prometheus.client.Counter$Child
@ -408,6 +409,47 @@
(t/is (false? (:called? @admin-console-mock)))
(t/is (= 0 (unread-count consumer/admin-console)))))))
(def ^:private browser-request
(reify
yetti.request/IRequest
(get-header [_ name]
(case name
"x-forwarded-for" "127.0.0.44"
"x-real-ip" "127.0.0.43"
nil))))
(t/deftest consumer-admin-console-skips-allowlisted-names-from-the-browser
;; Any signed-in profile can call the browser endpoint and name any
;; organization in the props. Only the backend records what really
;; happened, so a browser row never reaches an organization's log: it
;; counts as skipped and the cursor passes it.
(let [prof (th/create-profile* 14 {:is-active true})
props {:organization-id (str (uuid/next))
:member-id (str (uuid/next))}]
(th/with-audit-config #{:admin-console}
(let [out (th/command!
(with-meta {::th/type :push-audit-events
::rpc/profile-id (:id prof)
:events [{:name "delete-organization-member"
:type "action"
:timestamp (ct/now)
:props props}]}
{:app.http/request browser-request}))]
(t/is (nil? (:error out))))
;; The browser row is really in the buffer: what follows skips it,
;; it is not missing.
(t/is (= ["frontend"]
(mapv :source (th/db-exec! ["SELECT source FROM audit_log
WHERE name = 'delete-organization-member'"]))))
(insert-audit-row (:id prof) "delete-organization-member" props "backend")
(with-mocks [admin-console-mock {:target 'app.nitrate/call :return nil}]
(run-admin-console)
(t/is (:called? @admin-console-mock))
(let [[_ _ params] (:call-args @admin-console-mock)]
(t/is (= [["delete-organization-member" "backend"]]
(mapv (juxt :name :source) (:events params)))))
(t/is (= 0 (unread-count consumer/admin-console)))))))
(t/deftest consumer-admin-console-error-still-lets-nexus-drain
(let [prof (th/create-profile* 12 {:is-active true})]
(with-redefs [cf/flags #{:nexus :admin-console}]