-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSC2134: Identity Hash Lookups #2134
Changes from 12 commits
3eff76b
a8c26d2
8b92df7
12431f1
f8dbf2b
d2b47a5
063b9f6
bc9b6c3
5049e55
6bb4a9e
f41ed02
3ee27d3
f28476f
1343e19
1fea604
e3b2ad3
c63edc7
2383a55
53f025e
21e93a1
e3ff802
acdb2b1
02ac0f3
ee10576
36a35a3
0a4c83d
fae6883
f951f31
96e43aa
df88b13
dfb37fc
0fd4fe2
7549c5d
6f81d37
922a20b
53bd384
f4a1e02
3702669
dd8a654
1963a24
ed67e26
3514437
36cb8ed
0444c80
887cd5e
577021f
b26a9ed
9fd6bd3
3031df7
3b8c57e
8f3e588
c6dd595
da876bb
0ac70b2
20c72a3
6119b9a
87a54e8
ffbfde8
5580a2a
a17c74f
027c2d7
6660768
4d1f2ea
c8527b7
57de107
9913f5b
33d22c3
3789d82
acf8d34
c401a4d
3877724
96e06b6
3edf5e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# MSC2134: Identity Hash Lookups | ||
|
||
[Issue #2130](https://github.com/matrix-org/matrix-doc/issues/2130) has been | ||
recently created in response to a security issue brought up by an independent | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
party. To summarise the issue, lookups (of matrix user ids) are performed using | ||
turt2live marked this conversation as resolved.
Show resolved
Hide resolved
|
||
non-hashed 3pids (third-party IDs) which means that the identity server can | ||
turt2live marked this conversation as resolved.
Show resolved
Hide resolved
|
||
identify and record every 3pid that the user wants to check, whether that | ||
address is already known by the identity server or not. | ||
|
||
If the 3pid is hashed, the identity service could not determine the address | ||
turt2live marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unless it has already seen that address in plain-text during a previous call of | ||
the /bind mechanism. | ||
|
||
Note that in terms of privacy, this proposal does not stop an identity service | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from mapping hashed 3pids to users, resulting in a social graph. However, the | ||
identity of the 3pid will at least remain a mystery until /bind is used. | ||
|
||
This proposal thus calls for the Identity Service’s /lookup API to use hashed | ||
3pids instead of their plain-text counterparts. | ||
|
||
## Proposal | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This proposal suggests making changes to the Identity Service API's lookup | ||
endpoints. Due to the nature of this proposal, the new endpoints should be on a | ||
`v2` path (we also drop the `/api` in order to preserve consistency across | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
other endpoints): | ||
|
||
- `/_matrix/identity/v2/lookup` | ||
- `/_matrix/identity/v2/bulk_lookup` | ||
|
||
`address` should no longer be in a plain-text format, but will now take a hash | ||
value, and the resulting digest should be encoded in unpadded base64. For | ||
example: | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python | ||
address = "user@example.org" | ||
pepper = "matrix" | ||
digest = hashlib.sha256((pepper + address).encode()).digest() | ||
result_address = unpaddedbase64.encode_base64(digest) | ||
print(result_address) | ||
CpvOgBf0hFzdqZD4ASvWW0DAefErRRX5y8IegMBO98w | ||
``` | ||
|
||
SHA-256 has been chosen as it is [currently used | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elsewhere](https://matrix.org/docs/spec/server_server/r0.1.2#adding-hashes-and-signatures-to-outgoing-events) | ||
in the Matrix protocol. Additionally a | ||
[pepper](https://en.wikipedia.org/wiki/Pepper_(cryptography)) must be prepended | ||
to the data before hashing in order to serve as a weak defense against existing | ||
rainbow tables. This pepper will be specified by the identity server in order | ||
to prevent a single rainbow table being generated for all identity servers. As | ||
time goes on, this algorithm may be changed provided a spec bump is performed. | ||
Then, clients making a request to `/lookup` must use the hashing algorithm | ||
defined in whichever version of the CS spec they and the IS have agreed to | ||
speaking. | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Identity servers can specify their own peppers, which can be handy if a rainbow table is released for their current one. Identity servers could also set a timer for rotating this value to further impede rainbow table publishing. As such, it must be possible for clients to be able to query what pepper an identity server requires before sending it hashes. Thus a new endpoint must be added: | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
GET /_matrix/identity/v2/lookup_pepper | ||
``` | ||
|
||
This endpoint takes no parameters, and simply returns the current pepper as a JSON object: | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
{ | ||
"pepper": "matrixrocks" | ||
} | ||
``` | ||
|
||
In addition, the pepper the client used must be appended as a parameter to the | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new `/lookup` and `/bulk_lookup` endpoints, ensuring that the client is using | ||
the right one. If it does not match what the server has on file (which may be | ||
the case is it rotated right after the client's request for it), then client | ||
will know to query the pepper again instead of just getting a response saying | ||
no contacts are registered on that identity server. | ||
|
||
Thus, a call to `/bulk_lookup` would look like the following: | ||
|
||
``` | ||
{ | ||
"threepids": [ | ||
[ | ||
"email", | ||
"user@example.org" | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
[ | ||
"msisdn", | ||
"123456789" | ||
], | ||
[ | ||
"email", | ||
"user2@example.org" | ||
] | ||
], | ||
"pepper": "matrixrocks" | ||
} | ||
``` | ||
|
||
If the pepper does not match the server's, the client should receive a `400 | ||
M_INVALID_PARAM` with the error `Provided pepper value does not match | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'$server_pepper'`. Clients should ensure they don't enter an infinite loop if | ||
they receive this error more than once even after changing to the correct | ||
pepper. | ||
|
||
No parameter changes will be made to /bind, but identity servers should keep a | ||
hashed value for each address it knows about in order to process lookups | ||
quicker. It is the recommendation that this is done during the act of binding. | ||
|
||
`v1` versions of these endpoints may be disabled at the discretion of the | ||
implementation, and should return a `M_FORBIDDEN` `errcode` if so. | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Tradeoffs | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* This approach means that the client now needs to calculate a hash by itself, but the belief | ||
is that most languages provide a mechanism for doing so. | ||
* There is a small cost incurred by doing hashes before requests, but this is outweighed by | ||
the privacy implications of sending plain-text addresses. | ||
|
||
## Potential issues | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This proposal does not force an identity service to stop handling plain-text | ||
requests, because a large amount of the matrix ecosystem relies upon this | ||
behavior. However, a conscious effort should be made by all users to use the | ||
privacy respecting endpoints outlined above. Identity services may disallow use | ||
of the v1 endpoint. | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Unpadded base64 has been chosen to encode the value due to its ubiquitous | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
support in many languages, however it does mean that special characters in the | ||
address will have to be encoded when used as a parameter value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. errrm.... there are no special characters to encode in base64? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @Half-Shot was referring to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so surely we should use url-safe base64 then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a non-issue given the hashes appear in the request body. Would advocate for taking out the special characters sentence entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. In that case, we should use URL safe unpadded base64 to avoid the vast majority of the concerns in MSC1884 (see the paragraphs explaining how software failing 50% of the time is bad) |
||
|
||
## Other considered solutions | ||
|
||
Ideally identity servers would never receive plain-text addresses, however it | ||
is necessary for the identity server to send an email/sms message during a | ||
bind, as it cannot trust a homeserver to do so as the homeserver may be lying. | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Additionally, only storing 3pid hashes at rest instead of the plain-text | ||
versions is impractical if the hashing algorithm ever needs to be changed. | ||
|
||
Bloom filters are an alternative method of providing private contact discovery, | ||
however does not scale well due to clients needing to download a large filter | ||
that needs updating every time a new bind is made. Further considered solutions | ||
are explored in https://signal.org/blog/contact-discovery/ Signal's eventual | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sentence no sense makes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it still makes no sense - reopened. You have the URL twice, and once in the middle of the sentence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's two different URLs guys. |
||
solution of using SGX is considered impractical for a Matrix-style setup. | ||
|
||
Bit out of scope for this MSC, but there was an argument for not keeping all | ||
IDs as hashed on disk in the identity server, that being if a hashing algorithm | ||
was broken, we couldn't update the hashing algorithm without having the | ||
plaintext 3PIDs. Well @toml helpfully said that we could just take the old | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hashes and rehash them in the more secure hashing algorithm, thus transforming | ||
the algo from ex. SHA256 to SHA256+SomeBetterAlg. This may spur an MSC in the | ||
future that supports this, unless it is just an implementation detail. | ||
|
||
## Conclusion | ||
|
||
This proposal outlines an effective method to stop bulk collection of user's | ||
contact lists and their social graphs without any disastrous side effects. All | ||
turt2live marked this conversation as resolved.
Show resolved
Hide resolved
|
||
functionality which depends on the lookup service should continue to function | ||
unhindered by the use of hashes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is almost there - thank you for the epic. The current draft reads really well.
My main remaining concerns are that we need to spell out the attacks and tradeoffs and conclusion rationale between the solutions more clearly. I’ve tried to do this in note form at https://gist.github.com/ara4n/8d5fe3030d9fad00111f9ec343e86feb - would it be possible to try to incorporate this?
Meanwhile, I agree that a rotating pepper hash lookups is the best approach here (having reasoned it through).
Otherwise, my only other remaining concern is that we should be protecting the IS db better by storing 3pids in hashed form (and thus also 3pid invites and other bindings). ie wherever we currently pass around 3pids instead we pass around a hash salted with a static salt for that IS. i don’t think we even need the raw 3pid for validation purposes, as we can validate using a nonce instead? I’d much rather we spent the time to figure out protecting the db rather than figuring out k-anon further. This could be a separate MSC though, but it feels like we should have thought it through enough to ensure that this MSC doesn’t design it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it, thanks!
This is something we could append on to
/hash_details
,or even use theWe don't want to reuselookup_pepper
from it for this purpose? Perhaps renaming it to something more generic in the process?lookup_pepper
of course. The salt shouldn't rotate, while the pepper should.Looking at the IS API docs, the following would need to be changed to enable storing hashed IDs at rest.
Endpoints that would already work are:
There's still the GDPR concern that if we do get compromised, we're obligated to notify everyone that hashes were taken. Either we use matrix as the communication medium (does the law disallow this?) or we send a message to Homeservers who do have the plaintext 3PIDs that they should send an email (this could be horribly abused by an evil IS though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right - thanks for doing the storing hashed ID analysis, this is excellent. i suggest we copy-paste this verbatim as a starting point for a new MSC so as to not block this one further.
I've asked @lampholder whether we can do data breach notifications via Matrix or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i've given this the FCP ✅on the assumption that the spelling-out-the-attack and the more concrete tradeoff comparison makes it into the MSC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one other gotcha sprang to mind which we should note: having written out a basic threat model, it becomes clear that a malicious IS could just fail to rotate the pepper (or reuse the same pepper). So the rotating pepper really buys us very little indeed unless clients check for pepper reuse, which seems onerous and also useless given they can’t tell about pepper reuse from before they connected.
So while we might as well keep the ability of the server to specify the pepper it uses for the hashes, in think there is limited use in bothering to rotate it.