Am I affected?
This record states its affected versions in a form that can't be compared automatically.
Description
Improperly Controlled Modification of Dynamically-Determined Object Attributes vulnerability in the device API, device forms, signing key and product forms and JITP settings in nerves-hub nerves_hub_web allows an authenticated user who manages devices in any organization to write into other organizations via submitted org_id, product_id and deployment_id fields. The device API create and update actions and the dashboard device forms pass the request parameters to NervesHub.Devices.Device.changeset/2, which casts the organization, product, deployment group and update state as given. The signing key and product forms merge the session's organization into the submitted parameters so that a submitted org_id wins, and the JITP changeset accepts any product_id. Each request requires the manage role only in the user's own organization, and any account can create one.
A device placed on another organization's deployment group, or moved into its product, is sent that organization's firmware with a download URL. The user cannot change or control devices that already belong to the other organization, and cannot upload firmware to it.
This issue affects nerves_hub: from 1.0.0 before 2.5.3.
Technical analysis
1. Device API and device forms. NervesHubWeb.API.DeviceController.create/2 sets org_id and product_id from the route, then hands the rest of the request to Device.changeset/2; update/2 hands the whole request over. The changeset casts org_id, product_id, deployment_id, deleted_at and the server-managed update state, so an update can move the device into another organization's product and either request can place it on another organization's deployment group. The device settings form in NervesHubWeb.Components.DevicePage.SettingsTab and the new device form in NervesHubWeb.Live.Devices.New reach the same changeset with the same effect.
2. Signing key and product forms. NervesHubWeb.Live.Org.SigningKeys and NervesHubWeb.Live.Products.New build their parameters with Enum.into(submitted, %{"org_id" => session_org_id}), so a submitted org_id overrides the session's, and the key or product is created in the organization named by the client.
3. JITP settings. NervesHub.Devices.CACertificate.JITP.changeset/2 casts any product_id, through the API and the dashboard, so devices the certificate authority provisions are created in another organization's product.
4. Firmware delivery. When a planted device connects, NervesHub.ManagedDeployments checks its deployment group membership by firmware version, platform and architecture only, all reported by the device, so it stays on the foreign group and is sent that group's current release with a download URL.
Proof of concept
As an admin of organization A, with organization B having an active deployment group whose current release is firmware B:
POST /api/orgs/<A>/products/<A's product>/deviceswith{"identifier": "planted", "deployment_id": <B's deployment group ID>}. The device is created in A, on B's deployment group.- Create a device key for it, then connect it, reporting the platform and architecture of firmware B. When the deployment runs, the device is sent an update for firmware B with its download URL.
- To move a device instead,
PUT /api/orgs/<A>/products/<A's product>/devices/<identifier>with{"org_id": <B's ID>, "product_id": <B's product ID>}. The response is201, and the device is now in B's product.
Weaknesses & attack patterns
Weakness
CWE-639
·
Authorization Bypass Through User-Controlled Key
in catalog →
MITRE ↗
CWE-915
·
Improperly Controlled Modification of Dynamically-Determined Object Attributes
in catalog →
MITRE ↗
Attack patterns
CAPEC-77
·
Manipulating User-Controlled Variables
MITRE ↗
Any user who manages devices in an organization of their own can attach their device to another organization's deployment group and receive its firmware, move devices into that organization's product, add firmware signing keys and products to it, and have a certificate authority provision devices into its product. Devices that already belong to the other organization are not controlled, and no firmware can be uploaded to it.
Affected — ghcr.io / nerves-hub/nerves-hub Container registry ↗
modules · source files · routines
Affected — Nerves Hub Repository ↗
modules · source files · routines
Affected — GitHub / nerves-hub/nerves_hub_web Repository ↗
modules · source files · routines
Solutions
The fixed release's migration takes every device off a deployment group that belongs to a different product and logs each one. Upgrading undoes nothing else done this way. After upgrading, check the database for devices whose organization does not own their product, for signing keys in org_keys whose created_by_id has never been a member of the key's organization, and for certificate authorities whose JITP product belongs to another organization, and remove what you do not recognize. A device moved wholly into another organization, and a product added to one, leave nothing that sets them apart, so review your organization's devices and products as well.
References
Credits
CVSS breakdown
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N