Subject: Re: Docs: Encourage strong server verification with SCRAM

From: "Jonathan S. Katz" <[email-masked]>
Date: Thu, 25 May 2023 13:48:28 -0400

On 5/25/23 1:29 PM, Stephen Frost wrote:
> Greetings,
> 
> * Jacob Champion ([email-masked]) wrote:
>> On 5/24/23 05:04, Daniel Gustafsson wrote:
>>>> On 23 May 2023, at 23:02, Stephen Frost <[email-masked]> wrote:
>>>> Perhaps more succinctly- maybe we should be making adjustments to the
>>>> current language instead of just adding a new paragraph.
>>>
>>> +1
>>
>> I'm 100% on board for doing that as well, but the "instead of"
>> suggestion makes me think I didn't explain my goal very well. For
>> example, Stephen, you said
>>
>>> I have to admit that the patch as presented strikes me as a warning
>>> without really providing steps for how to address the issues mentioned
>>> though; there's a reference to what was just covered at the bottom but
>>> nothing really new.
>>
>> but the last sentence of my patch *is* the suggested step:
>>
>>> +      ... It's recommended to employ strong server
>>> +      authentication, using one of the above anti-spoofing measures, to prevent
>>> +      these attacks.
> 
> I was referring specifically to that ordering as not being ideal or in
> line with the rest of the flow of that section.  We should integrate the
> concerns higher in the section where we outline the reason these things
> matter and then follow those with the specific steps for how to address
> them, not give a somewhat unclear reference from the very bottom back up
> to something above.

Caught up on this exchange. Some of my comments may be out-of-order.

Overall, +1 to tightening the language around the docs in this area.

However, to paraphrase Stephen, I think the language, as currently 
written, makes the problem sound scarier than it actually is, and I 
agree that we should just inline it above. There may also be some 
follow-up development work we can do to mitigate the issues.

I think it's fine for us to recommend using channel binding, but if 
we're concerned about server spoofing / rogue servers, we should also 
recommend using sslmode=verify-full to ensure server-identity. That 
doesn't necessarily help in the case the server itself has gone rogue, 
but that mitigates the MITM risk. The SCRAM RFC is also very clear that 
you should be using TLS[1].

I really don't think the "startup packet" is an actual issue, but I 
think recommending good TLS / channel binding mitigates this.

For the iteration count, I'm generally ambivalent here. I think again, 
if you're using good TLS, this is most likely mitigated. If you're 
connecting to a rogue server using good TLS, you likely have other 
issues to deal with. However, there may be a libpq feature here that 
lets a client specify a minimum iteration count it will accept for 
purposes of SCRAM.

Thanks,

Jonathan

[1] https://www.rfc-editor.org/rfc/rfc5802#section-9

---

From: Jacob Champion <[email-masked]>
Date: Thu, 25 May 2023 12:27:06 -0700

On Thu, May 25, 2023 at 10:48 AM Jonathan S. Katz <[email-masked]> wrote:
> agree that we should just inline it above.

How does v2 look? I more or less divided the current text into a local
section and a network section. (I'm still not clear on where in the
current text you're wanting me to inline a sudden aside on SCRAM; it
doesn't really seem to fit in any of the existing paragraphs.)

--Jacob
From 96dee3dead97d38afd0d8139f5c9954ab76dfcba Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email-masked]>
Date: Mon, 22 May 2023 16:46:23 -0700
Subject: [PATCH v2] docs: encourage strong server verification with SCRAM

The server verification in libpq's SCRAM implementation can be subverted
in various ways. While mitigations for some of the issues exist, it's
probably wise for most users to combine it with strong server
authentication, to avoid entering a SCRAM exchange with an untrusted
server. Recommend that in the docs.
---
 doc/src/sgml/runtime.sgml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index dbe23db54f..35993ffff2 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -1994,6 +1994,20 @@ pg_dumpall -p 5432 | psql -d postgres -p 5433
    the socket.
   </para>
 
+  <para>
+   An additional avenue for server spoofing is via the network. Active attackers
+   who successfully insert themselves between the client and the real server can
+   not only read data coming from the client, as above, but also read data
+   coming from the server or tamper with data sent by either peer. The strongest
+   form of password authentication
+   (<link linkend="auth-password">scram-sha-256</link> in combination with
+   <literal>channel_binding=require</literal>) can provide partial mitigation,
+   but the current SCRAM implementation in libpq cannot protect the entire
+   authentication exchange, and an active attacker can retrieve a hashed
+   password from the client for offline analysis, even if they cannot complete
+   the exchange successfully.
+  </para>
+
   <para>
    To prevent spoofing on TCP connections, either use
    SSL certificates and make sure that clients check the server's certificate,
-- 
2.25.1