<div dir="ltr"><div>Henning: forgot about your remark: "And as Juha mentioned, it is also not good from a security POV to keep sending the password hash again and again."</div><div><br></div><div>If I haven't missed something, Juha said it is not good to ask the user again for introducing the password in the (soft)phone app. The hashed response (with nonce, realm, password) has to be sent always over the network, no matter the stale parameter value. So it is just the inconvenience of the person to type the password, it doesn't impact at all what is sent over the network.</div><div><br></div><div>Cheers,<br></div><div>Daniel<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 11:10 PM Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>Henning: it is what I said that I expect the db query is done later, so we actually do not assert the fact that the username and password used with the stalled nonce are correct, as per specs. To follow the specs, even when the nonce is expired, we have to fetch the password from database, compute the response and if it is correct, then add stale=true. Otherwise, not having valid username and password, the parameter must not be set, to force the UA to ask for new username and password.</div><div><br></div><div>But, doing an sql query in case of an expired nonce can expose the server to sort of useless (and quite time expensive) operations. Moreover, for an attacker will be easier to reuse an expired nonce and keep trying new passwords until getting stale=true, meaning that it has discovered the password.</div><div><br></div><div>With the above considerations, to make it specs compliant, the code has to be extended that even in the case of expired nonce, the auth_db (and the other auth* variants) has to go further to compute the response and if there was a match, then add stale=true. As it is right now, if someone sends an expired nonce with an incorrect password, the stale=true is added, even it shouldn't as per specs.</div><div><br></div><div>Therefore adding that flag now is not bringing benefits in my opinion and can be even more trouble maker.</div><div><br></div><div>Cheers,<br></div><div>Daniel<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 7:30 PM Henning Westerholt <<a href="mailto:hw@skalatan.de" target="_blank">hw@skalatan.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div bgcolor="#FFFFFF">
<p>Hello,<br>
</p>
<p>I did a quick check in the code, this is the path:<br>
</p>
<p>auth_check() -> digest_authenticate_hdr() -> auth_api.pre_auth() -> check for stale nonce etc..</p>
<p>DB calls are done later in the code path. So it looks that there is no possibility to do a DB DOS just with this path.</p>
<p>And as Juha mentioned, it is also not good from a security POV to keep sending the password hash again and again.<br>
</p>
<p>Cheers,</p>
<p>Henning<br>
</p>
<p><br>
</p>
<div class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-cite-prefix">Am 02.07.19 um 19:04 schrieb Daniel-Constantin Mierla:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hello,</div>
<div>I am not sure if this option is actually implemented according to the specs. iirc, stale=true should be set when the server checks the username and password and all is ok, but the nonce is expired. afaik, the check for nonce expiration is done before hiting
 the database to fetch the password and check the response. In UA side the stale=true would just make the app rebuild the response without prompting for password again, because the server said that with the expired nonce all was ok, from user/password point
 of view.</div>
<div><br>
</div>
<div>But if we hit the database for every expired nonce, then we expose the server to kind of a DoS processing.</div>
<div><br>
</div>
<div>Moreover, the latest recommendations in security is to disclose as less as possible what was not "correct", avoiding responses like "invalid user id" or "invalid password".</div>
<div><br>
</div>
<div>The lack of stale=true means that the UA should build again the authorization header from scratch with all the attributes.</div>
<div><br>
</div>
<div>I won't be against enabling this option if it would be for a "trusted" endpoint, but for servers exposed to the wild world, it may create some security concerns.</div>
<div><br>
</div>
<div>Therefore for the moment I would suggest to wait for more feedback from community, along with checking if the stale=true is implemented as per spec or is half brewed option.</div>
<div><br>
</div>
<div>Cheers,<br>
</div>
<div>Daniel<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 6:48 PM Henning Westerholt <<a href="mailto:hw@skalatan.de" target="_blank">hw@skalatan.de</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hello Juha,<br>
<br>
sounds like a good idea to me, we should integrate it to the default cfg.<br>
<br>
Just a small comment, I think this would be match the current behaviour <br>
more closely (only return stale=true, don't use qop=auth).<br>
<br>
!                       case -4:<br>
!                               auth_challenge("$fd", 16);<br>
!                               exit;<br>
<br>
<br>
Cheers,<br>
<br>
Henning<br>
<br>
Am 02.07.19 um 17:15 schrieb Juha Heinanen:<br>
<br>
> Several people are complaining on baresip git that Kamailio is among<br>
> those SIP servers that don't handle stale nonce properly, i.e., don't<br>
> include stale=true flag in WWW-Authenticate header of 401 response.<br>
><br>
> I have tried to tell that Kamailio does what it has been configured to<br>
> do, but the response is that "by default" Kamailio works incorrectly.  "By<br>
> default" I guess refers to the example Kamailio kamailio.cfg in etc dir.<br>
><br>
> How about adding stale nonce handling to the example config, for<br>
> example, like in below?<br>
><br>
> -- Juha<br>
><br>
> *** kamailio.cfg      2019-06-13 17:17:17.182148989 +0300<br>
> --- /tmp/kamailio.cfg 2019-07-02 18:02:02.947183503 +0300<br>
> ***************<br>
> *** 745,753 ****<br>
>    <br>
>       if (is_method("REGISTER") || from_uri==myself) {<br>
>               # authenticate requests<br>
> !             if (!auth_check("$fd", "subscriber", "1")) {<br>
> !                     auth_challenge("$fd", "0");<br>
> !                     exit;<br>
>               }<br>
>               # user authenticated - remove auth header<br>
>               if(!is_method("REGISTER|PUBLISH"))<br>
> --- 745,759 ----<br>
>    <br>
>       if (is_method("REGISTER") || from_uri==myself) {<br>
>               # authenticate requests<br>
> !             switch (auth_check("$fd", "subscriber", "1")) {<br>
> !                     case 1:<br>
> !                             break;<br>
> !                     case -4:<br>
> !                             auth_challenge("$fd", 17);<br>
> !                             exit;<br>
> !                     default:<br>
> !                             auth_challenge("$fd", "0");<br>
> !                             exit;<br>
>               }<br>
>               # user authenticated - remove auth header<br>
>               if(!is_method("REGISTER|PUBLISH"))<br>
><br>
> _______________________________________________<br>
> Kamailio (SER) - Users Mailing List<br>
> <a href="mailto:sr-users@lists.kamailio.org" target="_blank">
sr-users@lists.kamailio.org</a><br>
> <a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
<br>
-- <br>
Henning Westerholt - <a href="https://skalatan.de/blog/" rel="noreferrer" target="_blank">
https://skalatan.de/blog/</a><br>
Kamailio services - <a href="https://skalatan.de/services" rel="noreferrer" target="_blank">
https://skalatan.de/services</a><br>
<br>
_______________________________________________<br>
Kamailio (SER) - Users Mailing List<br>
<a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote>
</div>
<br clear="all">
<br>
-- <br>
<div dir="ltr" class="gmail-m_3276745465291915021gmail-m_502469823950902870gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>Daniel-Constantin Mierla - <a href="http://www.asipto.com" target="_blank">
http://www.asipto.com</a></div>
<div><a href="http://twitter.com/#!/miconda" target="_blank">http://twitter.com/#!/miconda</a> -
<a href="http://www.linkedin.com/in/miconda" target="_blank">
http://www.linkedin.com/in/miconda</a></div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="gmail-m_3276745465291915021gmail-m_502469823950902870mimeAttachmentHeader"></fieldset>
<pre class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-quote-pre">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
<a class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
</blockquote>
<pre class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-signature" cols="72">-- 
Henning Westerholt - <a class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-txt-link-freetext" href="https://skalatan.de/blog/" target="_blank">https://skalatan.de/blog/</a>
Kamailio services - <a class="gmail-m_3276745465291915021gmail-m_502469823950902870moz-txt-link-freetext" href="https://skalatan.de/services" target="_blank">https://skalatan.de/services</a></pre>
</div>

</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail-m_3276745465291915021gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Daniel-Constantin Mierla - <a href="http://www.asipto.com" target="_blank">http://www.asipto.com</a></div><div><a href="http://twitter.com/#!/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/miconda</a></div></div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Daniel-Constantin Mierla - <a href="http://www.asipto.com" target="_blank">http://www.asipto.com</a></div><div><a href="http://twitter.com/#!/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/miconda</a></div></div></div></div></div>