Eclipse Ditto resolved policy view discloses non-readable content of imported, namespace root and referenced policy entries
Description
The resolved policy view of Eclipse Ditto (GET /api/2/policies/{policyId}?policy-view=resolved, also available as policy-view header via WebSocket and connections) returns the effective policy: the policy itself merged with the entries it imports and with the entries of the namespace root policies that apply to its namespace.
The view does not apply the READ permissions of the policies the merged content comes from:
- Directly imported and namespace root entries are only checked per entry, and only require READ on some part of the entry in its source policy. The merged result is then filtered with the permissions of the requested (importing) policy only. A caller who may read only part of an entry in the source policy (e.g. only its
subjects, or everything except itsresourcesbecause READ on them is revoked) therefore receives the complete entry. - Entries of transitive imports (
transitiveImports) and of the imports of namespace root policies are only checked against the intermediate policy, never against the policy they originate from. - Content copied into an entry by
references(subjects, resources and namespaces of the referenced entry) is not checked against the READ permissions on the referenced entry at all, also for references to another entry of the same policy.
In all cases the resolved view can contain subjects, resources and granted/revoked permissions that are hidden from the caller when they read the originating policy directly.
Severity: Low.
Details
PolicyCommandEnforcement#filterResponse handles a RetrievePolicyResponse with policy-view=resolved in two steps:
mergeAndDropUnreadablemerges imported and namespace root entries into the policy and removes each entry the caller may not read in its source policy. The check,hasSourceSideRead, is a partial permission check:
``java src.getEnforcer().hasPartialPermissions( PoliciesResourceType.policyResource("/entries/" + label), authCtx, Permission.READ); ``
It is true as soon as the caller may read the entry or any part of it, so the entry is kept as a whole.
- The merged policy is then filtered by
getJsonViewForPolicyQueryCommandResponsewith the enforcer of the requested policy, not of the source policy. A caller with READ onpolicy:/of the requested policy sees every field of every kept entry. The READ permissions of the source policy on the fields of the entry (policy:/entries/<label>/subjects,.../resources, ...) are never applied.
A direct GET /api/2/policies/{sourcePolicyId} filters the same entry field by field with the source policy's enforcer and correctly hides the parts the caller may not read.
Content of policies further away than the direct imports and namespace root policies is not covered by these checks at all:
- For transitive imports and the imports of namespace root policies, the merged entry (e.g.
imported-<B>-imported-<C>-<label>) is only checked against the intermediate policyB(step 1) and the requested policy (step 2). The READ permissions ofCare never applied, even if the caller has no READ onCat all. - When
referencesare resolved (PolicyImporter#resolveAllReferences), the subjects, resources and namespaces of the referenced entry are copied into the referencing entry. The referencing entry, an own entry of the requested policy or an entry of an imported policy, is only checked with the READ permissions on itself, never with those on the referenced entry. This also applies to references to another entry of the same policy (e.g. a READ revoke onpolicy:/entries/HIDDEN/resourcesdoes not hide the resources an entry referencingHIDDENgets copied from it).
The issue can be reached in these ways:
- Declared policy imports: the caller may read a policy that imports another policy. Adding an import requires unrestricted READ on the imported entries (
PolicyImportsPreEnforcer). So this case requires that the caller is not the one who added the import, or that the caller's READ on the source policy was restricted after the import was added, or that importable entries were added to the source policy afterwards. - Namespace root policies: the caller may read any policy in a namespace for which namespace root policies are configured (
ditto.policies.namespace-policies), and has partial READ on an entry of such a root policy, or any READ restriction in a policy a root policy imports. No import needs to be added. - Transitive imports and
references: the caller may read a policy which transitively imports, or references an entry of, a policy whose content the caller may not (completely) read. Here the caller does not need any READ on that policy. This includes references between entries of the requested policy itself, if the caller may not read all of the referenced entry.
The resolved policy view was introduced in Ditto 3.9.0. Ditto 3.8.x and earlier do not have it and are not affected.
Proof of concept
Using the deployment/docker docker-compose setup, which enables pre-authentication and exposes the gateway directly on port 8081:
- As
nginx:ditto, create a source policy. Its entryxis importable.nginx:alicemay read the policy, except theresourcesof entryx:
``sh curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ http://localhost:8080/api/2/policies/org.example:source -d '{ "entries": { "admin": { "subjects": { "nginx:ditto": { "type": "admin" } }, "resources": { "policy:/": { "grant": ["READ", "WRITE"], "revoke": [] } }, "importable": "never" }, "alice": { "subjects": { "nginx:alice": { "type": "user" } }, "resources": { "policy:/": { "grant": ["READ"], "revoke": [] }, "policy:/entries/x/resources": { "grant": [], "revoke": ["READ"] } }, "importable": "never" }, "x": { "subjects": { "nginx:service-account": { "type": "service" } }, "resources": { "thing:/attributes/secret-path": { "grant": ["READ", "WRITE"], "revoke": [] } }, "importable": "implicit" } } }' ``
- As
nginx:ditto, create a policy that imports the source policy and letsnginx:aliceread it:
``sh curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ http://localhost:8080/api/2/policies/org.example:importing -d '{ "entries": { "admin": { "subjects": { "nginx:ditto": { "type": "admin" } }, "resources": { "policy:/": { "grant": ["READ", "WRITE"], "revoke": [] } } }, "alice": { "subjects": { "nginx:alice": { "type": "user" } }, "resources": { "policy:/": { "grant": ["READ"], "revoke": [] } } } }, "imports": { "org.example:source": {} } }' ``
- As
nginx:alice, read entryxdirectly from the source policy.resourcesis hidden, as configured:
```sh curl -H 'x-ditto-pre-authenticated: nginx:alice' \ localhost/
-> {"subjects":{"nginx:service-account":{"type":"service"}},"importable":"implicit"}
```
- As
nginx:alice, read the resolved view of the importing policy:
``sh curl -H 'x-ditto-pre-authenticated: nginx:alice' \ 'http://localhost:8081/api/2/policies/org.example:importing?policy-view=resolved' ``
Vulnerable versions return the imported entry imported-org.example:source-x including its resources:
``json "imported-org.example:source-x": { "subjects": { "nginx:service-account": { "type": "service" } }, "resources": { "thing:/attributes/secret-path": { "grant": ["READ", "WRITE"], "revoke": [] } }, "importable": "implicit" } ``
Patched versions return the entry without resources, the same as step 3.
The same applies to entries of namespace root policies, which appear in the resolved view as nsimported-<rootPolicyId>-<label>.
- Variant with
references: asnginx:ditto, create a policy with an own entry referencing entryxof the source policy, whichnginx:alicemay read:
```sh curl -u ditto:ditto -X PUT -H 'Content-Type: application/json' \ localhost/
curl -H 'x-ditto-pre-authenticated: nginx:alice' \ 'localhost/
Vulnerable versions return the resources of x copied into the own entry local:
``json "local": { "subjects": { "nginx:service-account": { "type": "service" }, "nginx:bob": { "type": "user" } }, "resources": { "thing:/attributes/secret-path": { "grant": ["READ", "WRITE"], "revoke": [] } }, "references": [ { "import": "org.example:source", "entry": "x" } ] } ``
Patched versions return local without the resources of x.
The same applies to entries of transitively imported policies (transitiveImports) and of policies imported by namespace root policies, independent of the caller's READ on the intermediate policy.
Impact
Incorrect authorization (CWE-863) leading to exposure of information (CWE-200) in the resolved policy view.
An authenticated caller can read content of imported, transitively imported, namespace root and referenced policy entries that the policy it originates from does not allow them to read: the entry's subjects (e.g. user, group or service account IDs), resources and granted/revoked permissions. This tells them who has which access to which resources and can help to prepare further attacks. The issue does not allow modifying policies, and does not grant access to Things or other resources.
Impacted are deployments that let callers read a policy whose resolved view contains content of another policy the caller may not (completely) read, i.e. where
- callers have partial READ on importable entries of a directly imported or namespace root policy (READ on only some parts of an entry, or READ with a more specific READ revoke inside the entry), or
- policies use
transitiveImports, namespace root policies import other policies, or entries usereferencesto entries of other policies, and the caller may not read everything in those other policies.
Not impacted:
- callers with no READ at all on a directly imported or namespace root entry: such entries are removed from the resolved view,
- the default (
original) policy view, - Ditto 3.8.x and earlier.
Workarounds
Until a patched version is deployed, do one of the following:
- Reject requests with the
policy-viewquery parameter or header set toresolvedin a reverse proxy in front of the Ditto gateway (this covers the HTTP API only, not WebSocket or connections), or - grant callers who may read a policy READ on everything that policy imports or references (including transitive imports and the imports of namespace root policies), or no READ at all on directly imported entries, and do not revoke READ on parts of importable entries.
Patches
Fixed in Eclipse Ditto 3.9.9: the resolved policy view now restricts all content copied from other entries to what the caller may READ in the policy it originates from. Every policy contributing to the view (the requested policy itself, declared imports, transitive imports, namespace root policies and their imports, policies referenced by references) is restricted to the caller's READ view of it before being merged, and directly imported and namespace root entries are additionally filtered field by field in the same way as a direct read of the source policy. Own entries of the requested policy without references are returned exactly as in the default policy view.