Eclipse Ditto Thing events and subscription filters disclose field values the subscriber may not read
Description
Eclipse Ditto delivers Thing events (WebSocket, Server-Sent Events, connections) containing field values which the policy does not allow the subscriber to read, and which a retrieve of the same Thing correctly filters out. It also evaluates subscription filters, placeholders and enrichment on behalf of the subscriber on the unfiltered event. This affects:
- Subscribers with several subjects (e.g. a user subject and a group/role subject extracted from the same JWT, or a connection target with several authorization subjects): a
READrevoke for one subject is not applied when another subject of the same authorization context is grantedREAD. - Subscribers with partial
READaccess (since 3.9.0, partial access events): the event payload is filtered, but not everything evaluated on behalf of the subscriber. - Receivers of live commands: a live command (e.g. a live
ModifyAttributes) is delivered with its whole payload to every subscriber withREADon the command's path, even ifREADis revoked for a part of the payload — also for a subscriber with a single subject.
Severity: High.
Details
When a Thing event is created, the things service attaches the subjects allowed to read it to the event's headers:
ThingCommandEnforcement#addEffectedReadSubjectsToThingSignalsetsread-granted-subjects, determined for each subject on its own: a subject is included when it is grantedREADon the event's resource (or, since 3.9.0, on some part of it), regardless of revokes of other subjects. Noread-revoked-subjectsare set for Thing events.- Since 3.9.0, the readable paths of each partially granted subject are attached as well, again per subject.
The event delivery then grants access to the whole subscriber as soon as one of its subjects is included:
StreamingSessionActor#isSessionAllowedToReceiveSignal(WebSocket, SSE) and connectivity'sSignalFiltercallAuthorizationContext#isAuthorized(readGrantedSubjects, readRevokedSubjects), which allows delivery if any subject is granted and none is revoked. As the revoked subjects are empty, one granted subject suffices.PartialAccessPathResolver#resolveAccessiblePaths(3.9.x) returns the unfiltered payload if any subject of the subscriber has unrestrictedREAD, and otherwise the union of the readable paths of its subjects. A revoke of another subject is never subtracted.
Independently of the payload filtering, the following are evaluated on the unfiltered event, so they reveal fields the subscriber cannot read, also for a subscriber with a single, partially granted subject:
- RQL filters of WebSocket/SSE subscriptions and of connection target topics (e.g.
eq(attributes/secret,"s1")delivers the event only if the hidden value matches), - the
_contextof SSE events (fields=_context), thing-jsonplaceholders in connection header mappings and payload mapper conditions,- pre-defined extra fields of events and live messages, which are not filtered for revokes.
Furthermore:
- live events are not filtered for partial
READaccess at all, and events deleting a field (or mergingnullinto it) are delivered to subscribers who may not read that field; - live commands get their readers from
LiveSignalEnforcement#addEffectedReadSubjectsToThingLiveSignal, which only considers the command's own path, and their payload is never filtered; - the readable paths of partially granted subjects are calculated with all policy entries, also with those restricted to other namespaces (
namespaces), so such a grant widens what is delivered for Things in any namespace; - a partially granted subject which can read none of the fields of the Thing is not listed with the readable paths, and therefore treated as unrestricted, i.e. it receives the whole event.
Retrieving a Thing is not affected: there, the policy is evaluated for the authorization context as a whole, so the revoke of one subject applies to the request.
Proof of concept
Using the deployment/docker docker-compose setup, which enables pre-authentication and exposes the gateway directly on port 8081 (the gateway accepts several comma-separated pre-authenticated subjects, which stands in for e.g. a JWT yielding several subjects):
- Create a policy where
nginx:aliceis grantedREADonthing:/,nginx:group-xhasREADrevoked onthing:/attributes/secretandnginx:carolis only grantedREADonthing:/attributes/pub, plus a Thing using it:
```sh curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ localhost/
curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ localhost/
- Retrieving the Thing as the authorization context
{nginx:alice, nginx:group-x}correctly omitssecret:
```sh curl -H 'x-ditto-pre-authenticated: nginx:alice,nginx:group-x' \ localhost/
{"thingId":"org.example:poc","policyId":"org.example:poc","attributes":{"pub":"p0"}}
```
- Subscribe for events of the Thing as the same authorization context, and as
nginx:carolwith a filter on the field she cannot read:
```sh curl -N -H 'Accept: text/event-stream' -H 'x-ditto-pre-authenticated: nginx:alice,nginx:group-x' \ 'localhost/
curl -N -H 'Accept: text/event-stream' -H 'x-ditto-pre-authenticated: nginx:carol' \ 'localhost/
- Modify the attributes as admin:
``sh curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ http://localhost:8080/api/2/things/org.example:poc/attributes/secret -d '"s1"' curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ http://localhost:8080/api/2/things/org.example:poc/attributes -d '{ "pub": "p2", "secret": "s2" }' ``
Vulnerable versions send both values of secret to {nginx:alice, nginx:group-x}:
`` data:{"thingId":"org.example:poc","attributes":{"secret":"s1"}} data:{"thingId":"org.example:poc","attributes":{"pub":"p2","secret":"s2"}} ``
and (3.9.x) an event to nginx:carol, confirming the value of secret and containing it in _context:
`` data:{"thingId":"org.example:poc","attributes":{"pub":"p2"},"_context":{"topic":"org.example/poc/things/twin/events/modified","path":"/attributes","value":{"pub":"p2","secret":"s2"},"headers":{...}}} ``
The correct result is no event for the first modification and {"pub":"p2"} for the second one to {nginx:alice, nginx:group-x}, and no event to nginx:carol, as her filter refers to a field she cannot read.
The same applies to a WebSocket session (START-SEND-EVENTS, START-SEND-LIVE-EVENTS) and to connection targets, and to all Thing events whose payload contains the restricted resource (e.g. ThingModified, ThingMerged, AttributesModified).
Impact
Incorrect authorization (CWE-863): disclosure of Thing field values to event subscribers and receivers of live commands which the policy does not allow them to read, either because a READ revoke applies to another subject of their authorization context, or because they are only partially granted READ. Only values of Things the subscriber may at least partially read are disclosed, and only while events for them are emitted. The severity is nevertheless rated High: with partial access events enabled (the default since 3.9.0), a subscriber with only partial READ receives the full values of non-readable fields of every emitted event and can select the fields to disclose via subscription filters, and as Things are usually updated frequently, this typically discloses all non-readable fields which are written.
Not impacted:
- retrieving Things (
GET, retrieve commands) and searching Things, - authorization of modifying commands and of live messages (only the delivery of live commands is affected, see above),
- subscribers with unrestricted
READon the Thing and no revoked subject.
Workarounds
Until a patched version is deployed:
- do not rely on a
READrevoke for one subject to restrict what another subject of the same authorization context may read: add the revoke to the policy entry of every subject which is grantedREADon the resource as well; - do not grant partial
READaccess on Things containing fields which must stay confidential towards these subjects, or disable partial access events (THING_EVENT_PARTIAL_ACCESS_EVENTS_ENABLED=false) — note that partially granted subjects then receive no events for these Things; - do not send live commands containing fields whose
READis revoked for subjects subscribed to live commands of the Thing; - do not restrict policy entries granting partial
READto namespaces (namespaces).
Patches
Fixed in Eclipse Ditto 3.9.9: the things service attaches, per subject, the paths whose READ is revoked to every Thing event, live event and modifying live command, calculated with the policy entries applicable to the Thing's namespace; partially granted subjects which can read nothing are no longer receivers. Gateway and connectivity remove the paths revoked for any subject of the subscriber, and evaluate filters, placeholders, _context and extra fields only on the part of the event the subscriber may read. An event is not delivered if the subscriber may read nothing at its path. A live command is never altered: it is not delivered to a subscriber who may not read all of it.