Summary
immich is vulnerable to account hijacking through oauth2, because the state
parameter is not being checked.
Details
the oauth2 state parameter is similar to a csrf token, so when the user starts the login flow this unpredictable token is generated and somehow saved in the browser session and passed to the identity provider, which will return the state paramter when redirecting the user back to immich. before the user is logged in that parameter needs to be verified to make sure the login was actively initiated by the user in this browser session.
on it's own, this wouldn't be too bad, but when immich uses the /user-settings page as a redirect_uri, it will automatically link the accounts if the user was already logged in. This means that if someone has an immich instance with a public oauth provider (like google), an attacker can - for example - embed a hidden iframe in a webpage or even just send the victim a forged oauth login url with a code that logs the victim into the attackers oauth account and redirects back to immich and links the accounts. after this, the attacker can log into the victims account using their own oauth credentials.
PoC
Assuming an immich instance at https://immich.example.com
and oauth at https://login.example.com
and a user with email [email protected]
and a user with email [email protected]
that has an account at https://login.example.com
, the attacker can initiate the oauth flow by opening https://login.example.com/ui/oauth2?client_id=immich&scope=openid%20email%20profile&response_type=code&redirect_uri=https%3A%2F%2Fimmich.example.com%2Fuser-settings&state=gibberish
, note that state=gibberish
is a valid state parameter, because the one generated by the immich web app - while being unpredictable, as it should be - does not do anything. The attacker now logs in on https://login.example.com
, but does not allow the redirect back to immich on their end (various methods to do this without much effort, for example blocking the immich.example.com domain on their own machine for the purpose of the exploit), the oauth flow tries to send them back to immich by redirecting to https://immich.example.com/user-settings?code=<code>&state=gibberish
. They can set up a script to generate these urls continously and send them to users by hiding them behind url shorteners, but they can also embed the url in a (hidden) iframe on a website they control that the user visits ("hey, I made this tool for immich that allows you to do xyz, take a look at demo.attacker.com"). When the url is loaded in the browser of a logged in user, their account gets linked to the attacker's account.
Impact
All immich instances with publicly accessible oauth2 providers (google, etc) are affected. This likely includes most instances set up with cloudflare access that people consider private-ish, unless they have some additional rules like an account/email whitelist. In theory, if you don't trust your friends then private instances are affected as well in a way. If the attacker manages to hijack an admin account this way, they could change the oauth instance to one they control and start logging into arbitrary accounts and lock out the admin by disabling password login and deleting all other sessions via settings. The admin would need to take back control using the host system. (While I have confirmed the PoC described earlier I have not explored the further paths just mentioned)
Summary
immich is vulnerable to account hijacking through oauth2, because the
state
parameter is not being checked.Details
the oauth2 state parameter is similar to a csrf token, so when the user starts the login flow this unpredictable token is generated and somehow saved in the browser session and passed to the identity provider, which will return the state paramter when redirecting the user back to immich. before the user is logged in that parameter needs to be verified to make sure the login was actively initiated by the user in this browser session.
on it's own, this wouldn't be too bad, but when immich uses the /user-settings page as a redirect_uri, it will automatically link the accounts if the user was already logged in. This means that if someone has an immich instance with a public oauth provider (like google), an attacker can - for example - embed a hidden iframe in a webpage or even just send the victim a forged oauth login url with a code that logs the victim into the attackers oauth account and redirects back to immich and links the accounts. after this, the attacker can log into the victims account using their own oauth credentials.
PoC
Assuming an immich instance at
https://immich.example.com
and oauth athttps://login.example.com
and a user with email[email protected]
and a user with email[email protected]
that has an account athttps://login.example.com
, the attacker can initiate the oauth flow by openinghttps://login.example.com/ui/oauth2?client_id=immich&scope=openid%20email%20profile&response_type=code&redirect_uri=https%3A%2F%2Fimmich.example.com%2Fuser-settings&state=gibberish
, note thatstate=gibberish
is a valid state parameter, because the one generated by the immich web app - while being unpredictable, as it should be - does not do anything. The attacker now logs in onhttps://login.example.com
, but does not allow the redirect back to immich on their end (various methods to do this without much effort, for example blocking the immich.example.com domain on their own machine for the purpose of the exploit), the oauth flow tries to send them back to immich by redirecting tohttps://immich.example.com/user-settings?code=<code>&state=gibberish
. They can set up a script to generate these urls continously and send them to users by hiding them behind url shorteners, but they can also embed the url in a (hidden) iframe on a website they control that the user visits ("hey, I made this tool for immich that allows you to do xyz, take a look at demo.attacker.com"). When the url is loaded in the browser of a logged in user, their account gets linked to the attacker's account.Impact
All immich instances with publicly accessible oauth2 providers (google, etc) are affected. This likely includes most instances set up with cloudflare access that people consider private-ish, unless they have some additional rules like an account/email whitelist. In theory, if you don't trust your friends then private instances are affected as well in a way. If the attacker manages to hijack an admin account this way, they could change the oauth instance to one they control and start logging into arbitrary accounts and lock out the admin by disabling password login and deleting all other sessions via settings. The admin would need to take back control using the host system. (While I have confirmed the PoC described earlier I have not explored the further paths just mentioned)