Securing our home labs: Home Assistant code review
Home Assistant's OAuth2/IndieAuth flow accepted arbitrary client identifiers and a client-controlled state value, so an attacker could craft a link that sent a victim's authorization code to an attacker-controlled server. The stolen code could then be exchanged for access and refresh tokens, potentially leading to remote code execution on the instance.
Published on github.blog
Alvaro Munoz·@pwntester
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the OAuth state parameter was a client-controlled, decodable JSON blob whose hassUrl field told the client-side JavaScript where to POST the authorization code, and no allow-list restricted accepted clients or instance URLs.
Impact
An attacker could obtain valid access and refresh tokens, which the text says could potentially result in remote code execution on the Home Assistant instance.
What the attacker needed
Victim clicks a crafted link; victim logs in to their instance; attacker runs a server
The fix
Home Assistant added a limitHassInstance option, enabled by default, that restricts which hassUrl and clientId values are accepted from the OAuth2 state, and it was fixed in the 2023.8 release.
How it was found
- Craft an authorization link whose state value points hassUrl at an attacker-controlled server while keeping the legitimate client_id and redirect_uri.
- Send the link to a victim and get them to log in to their own Home Assistant instance.
- The victim sees a normal-looking consent message naming their own instance.
- After login, the browser sends the authorization code to the attacker's server.
- The attacker exchanges the code at the /auth/token endpoint for access and refresh tokens.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you log in to an app using another service, the app gets a short-lived code that it swaps for a key to your account. Here the app trusted a value in the link to decide where to send that code, so a crafted link could send it to the attacker instead. With that code the attacker could get their own key to the victim's smart-home system.
What is OAuth / SSO?
Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.