<div dir="ltr">Hi there. First thanks for taking the time to thoroughly reply to it.<br><br>>> external_acl_type ldap_HTTP %LOGIN %URI<br>>> /usr/lib/squid/ext_ldap_group_<wbr>acl -D "cn=admin,dc=example,dc=com" -w<br>>> test -R -b "ou=authorization,dc=example,<wbr>dc=com" -B<br>>> "ou=people,dc=example,dc=com" -f<br>>> '(&(objectclass=groupOfNames)(<wbr>cn=%g)(member=uid=%u,ou=<wbr>people,dc=example,dc=com))'<br>>> -h <a href="http://ldap01.example.com" target="_blank">ldap01.example.com</a> -d<br>><br>><br>> Please be aware that the %URI format does not perform any type of shell<br>> or LDAP escaping to protect this helper lookup against shell-injection<br>> attacks.<div>><br>> It is possible that a remote client can end a URL with ')' followed by<br>> any LDAP commands they like and have that executed by your helper.<br></div><div><br></div><div>I was also concerned about shell injection and LDAP injection but:</div><div>- group value is not really passed as shell argument but read from stdin AFAIU</div><div>- I could not see ")" reflected in the LDAP filter. When performing the following request, for example:</div><div><br></div><div><p style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span>$ curl --proxy-negotiate --negotiate -u : <a href="http://web.example" target="_blank">http://web.example</a>")".com/</span></p></div><div><br></div><div>I see the following lines in the debug log:</div><div><br></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span>ext_ldap_group_acl.cc(579): pid=31325 :Connected OK</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span>ext_ldap_group_acl.cc(718): pid=31325 :group filter '(&(objectclass=groupOfNames)(<wbr>cn=web.example</span>\<a href="http://29.com" target="_blank">29.com</a>)(member=<wbr>uid=<span style="font-family:arial,sans-serif;font-size:small"> john_doe</span>,ou=people,dc=<wbr>example,dc=com))', searchbase 'ou=authorization,dc=example,<wbr>dc=com'</p></div><div><span><br></span></div><div>That's because "group" is ldap-escaped when building the LDAP search filter (<a href="https://github.com/squid-cache/squid/tree/master/helpers/external_acl/LDAP_group#L654" target="_blank">https://github.com/squid-<wbr>cache/squid/tree/master/<wbr>helpers/external_acl/LDAP_<wbr>group#L654</a>) AFAIU.<br></div><div><br>I have since the message was sent to the mailing list stopped using "%URI and changed to "%DST" - only because %URI will also add scheme and for SSL, port number. <br><br></div><div>Regardless, your point may still be valid for those passing argument to the binary. Minor pentests I did didn't show much of a security risk here.<br><br>> If you want to do things like this safely please upgrade to Squid-4<br>> where the logformat codes are available. Those codes provide<br>> customizable escaping and quoting styles so you can set one that<br>> protects LDAP against these attacks to be ued on the URI field value<br>> sent by Squid.<div><br></div><div>You mean <a href="http://www.squid-cache.org/Doc/config/logformat/" target="_blank">these</a> logformats are available to be used in acl / external acls @ squid.conf? Or?<br><br></div><div>..... </div><div><br></div><div>><br>> What is happening is that the helper expects the %LOGIN field to be<br>> followed by a list of space-separated 'words'. Each 'word' is a group<br>> name to be checked against the users account memberships. So the list of<br>> words is looked up individually until one matches or none left to check.</div><div><br></div><div><div>I forgot to mention that for the debugging I used the following:</div><div><br></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">external_acl_type ldap_HTTP %LOGIN %URI %METHOD %PORT</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">So it's perfectly in line with what you mentioned.</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">So in:</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:13px"><br></span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:13px">4) '(&(objectclass=groupOfNames)(</span><span style="font-family:arial,sans-serif;font-size:13px"><wbr>test=%test)(member=uid=%u,ou=</span><span style="font-family:arial,sans-serif;font-size:13px">p<wbr>eople,dc=example,dc=com))':</span></p><span style="font-size:13px">ERROR: Unknown filter template string %t</span><br style="font-size:13px"><span style="font-size:13px">ext_ldap_group_acl: ERROR: Failed to construct LDAP search filter.</span><br style="font-size:13px"><span style="font-size:13px">filter="(&(objectclass=</span><span style="font-size:13px">groupOf<wbr>Names)(test=?,?U", user="john_doe",</span><br style="font-size:13px"><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:13px">group="</span><a href="http://web.example.com/" rel="noreferrer" style="font-family:arial,sans-serif;font-size:13px" target="_blank">http://web.example.com/</a><span style="font-family:arial,sans-serif;font-size:13px"><wbr>"</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo">The garbage is here: <span style="font-size:13px;font-family:arial,sans-serif">?,?U",</span><span style="font-size:13px;font-family:arial,sans-serif"> </span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo"><font color="#ce7924"><br></font></p></div>><br>> So somehow the HTTP request URL/URI is the whole string:<br>>  "GET <a href="http://web.example.com/" target="_blank">http://web.example.com/</a> 80"<br>><br>> -> very odd. It is not even a valid HTTP request-line. Looks more like<br>> some outdated Squid-1.1 URL re-write helper is mangling the URL. But the<br>> order is slightly wrong even for that (GET would be after the actual URL).<br>></div><div><br></div><div>Sorry - that's because the "<span style="font-family:Menlo;font-size:12px">%URI %METHOD %PORT" was added as FORMAT, as I mentioned above.</span></div><div><font face="Menlo"><span style="font-size:12px"><br></span></font>><br>> Anyhow, that resuls in the ACL group helper receiving:<br>>  john_does GET <a href="http://web.example.com/" target="_blank">http://web.example.com/</a> 80<br>><br>> Meaning,<br>>  username: "john_doe"<br>>  group #1: "GET"<br>>  group #2: "<a href="http://web.example.com/" target="_blank">http://web.example.com/</a>"<br>>  group #3: "80"<br>><br>><br>>><br>>> This is all pretty much happening here<br>>> [<a href="https://github.com/squid-cache/squid/blob/master/helpers/external_acl/LDAP_group/ext_ldap_group_acl.cc#L638" target="_blank">https://github.com/squid-<wbr>cache/squid/blob/master/<wbr>helpers/external_acl/LDAP_<wbr>group/ext_ldap_group_acl.cc#<wbr>L638</a>]<br>>><br>>> So conclusions:<br>>> - %v and %u both map to "user", which is expected (historical reasons<br>>> & compatibility)<br>><br>> As documented.<br>><br>>> - %g and %a both map to "group", which is expected (historical reasons<br>>> & compatibility)<br>><br>> As documented.<br>><br>>> - any other template filter (%b, %c, %test, etc) is trash (only %a,<br>>> %u, %g, %v won't yield error)<br>><br>> Nod. The helper autor(s) reserve other %-code to be defined with any<br>> arbitrary meaning at any time. So there is simply no documented<br>> behaviour for them.<br>>  A you found v and a have old meanings that are still supported, though<br>> deprecated so removed from the documentation intentionally to prevent<br>> future use.<br>><br>><br>>> - when "" is passed to the acl ("acl <ACL_name> external ldap_HTTP<br>>> ""), the helper will attempt all FORMAT values, mapping then to<br>>> "group" (%a or %g)<br>><br>> It should mean Squid loads a file with undefined name (\0) and sends<br>> that files content as the list of group names. Each line in the file<br>> being a group name.</div><div><br></div><div>Oh, ok. Got that now.</div><div><br>><br>><br>>><br>>> Although I can move on with this for now, I would be actually more<br>>> relieved if I could use:<br>>> acl allow_HTTP_ACL external ldap_HTTP<br>>> <a_var_which_is_available_<wbr>here_representing_URI><br>>>  instead of<br>>> acl allow_HTTP_ACL external ldap_HTTP ""  + non-documented behavior of<br>>> ext_ldap_group_acl<br>><br>> Dont specify anything at all in that position. The %URI field you<br>> defined to be sent to the helper should be formatted in the place it<br>> expects to find a group name "word" as mentioned above.<br>><br>> Just use:<br>>  acl allow_HTTP_ACL external ldap_HTTP<br>></div><div><br></div><div>I had tried that early on without success - clearly the problem was somewhere else as this indeed proves to work now. Thanks.</div><div><br>><br>> Amos<br>><br>> ______________________________<wbr>_________________<br>> squid-users mailing list<br>> <a href="mailto:squid-users@lists.squid-cache.org" target="_blank">squid-users@lists.squid-cache.<wbr>org</a><br>> <a href="http://lists.squid-cache.org/listinfo/squid-users" target="_blank">http://lists.squid-cache.org/<wbr>listinfo/squid-users</a><br><br><br><br>-- <br><br>--------<br><br>Diogenes S. de Jesus</div></div></div>