|
| 1 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | +<HTML> |
| 3 | + <HEAD> |
| 4 | + <TITLE> [squid-dev] Issue with acl note (without -m) splitting helper tokens containing commas |
| 5 | + </TITLE> |
| 6 | + <LINK REL="Index" HREF="index.html" > |
| 7 | + <LINK REL="made" HREF="mailto:squid-dev%40lists.squid-cache.org?Subject=Re%3A%20%5Bsquid-dev%5D%20Issue%20with%20acl%20note%20%28without%20-m%29%20splitting%20helper%0A%20tokens%20containing%20commas&In-Reply-To=%3C10e9ebca-6fa4-48a9-9082-1c03eb97a792%40measurement-factory.com%3E"> |
| 8 | + <META NAME="robots" CONTENT="index,nofollow"> |
| 9 | + <style type="text/css"> |
| 10 | + pre { |
| 11 | + white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */ |
| 12 | + } |
| 13 | + </style> |
| 14 | + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
| 15 | + <LINK REL="Previous" HREF="010021.html"> |
| 16 | + <LINK REL="Next" HREF="010018.html"> |
| 17 | + </HEAD> |
| 18 | + <BODY BGCOLOR="#ffffff"> |
| 19 | + <H1>[squid-dev] Issue with acl note (without -m) splitting helper tokens containing commas</H1> |
| 20 | + <B>Alex Rousskov</B> |
| 21 | + <A HREF="mailto:squid-dev%40lists.squid-cache.org?Subject=Re%3A%20%5Bsquid-dev%5D%20Issue%20with%20acl%20note%20%28without%20-m%29%20splitting%20helper%0A%20tokens%20containing%20commas&In-Reply-To=%3C10e9ebca-6fa4-48a9-9082-1c03eb97a792%40measurement-factory.com%3E" |
| 22 | + TITLE="[squid-dev] Issue with acl note (without -m) splitting helper tokens containing commas">rousskov at measurement-factory.com |
| 23 | + </A><BR> |
| 24 | + <I>Mon Apr 20 18:59:14 UTC 2026</I> |
| 25 | + <P><UL> |
| 26 | + <LI>Previous message (by thread): <A HREF="010021.html">[squid-dev] Issue with acl note (without -m) splitting helper tokens containing commas |
| 27 | +</A></li> |
| 28 | + <LI>Next message (by thread): <A HREF="010018.html">[squid-dev] NO_SPECIAL_HANDLING define for HTTP methods |
| 29 | +</A></li> |
| 30 | + <LI> <B>Messages sorted by:</B> |
| 31 | + <a href="date.html#10022">[ date ]</a> |
| 32 | + <a href="thread.html#10022">[ thread ]</a> |
| 33 | + <a href="subject.html#10022">[ subject ]</a> |
| 34 | + <a href="author.html#10022">[ author ]</a> |
| 35 | + </LI> |
| 36 | + </UL> |
| 37 | + <HR> |
| 38 | +<!--beginarticle--> |
| 39 | +<PRE>On 2026-04-17 09:08, Andrey K wrote: |
| 40 | + |
| 41 | +><i> While working with annotations, I’ve noticed an inconsistency in how acl |
| 42 | +</I>><i> note (without the -m option) handles tokens received from helpers when |
| 43 | +</I>><i> they contain a comma. |
| 44 | +</I> |
| 45 | +I think it is important to note that there are several distinct players |
| 46 | +here, including: |
| 47 | + |
| 48 | +1. What annotations the helper sends to Squid. |
| 49 | + |
| 50 | +2. How helper response parser converts received helper response into |
| 51 | + transaction annotations. |
| 52 | + |
| 53 | +3. How the "note" ACL code interprets transaction annotations. |
| 54 | + These annotations may come from sources other than a helper. |
| 55 | + |
| 56 | + |
| 57 | +><i> According to the documentation, an ACL like this: |
| 58 | +</I>><i>     acl staff note group Staff:accountants,lawyers,security |
| 59 | +</I>><i> should match a helper response such as: |
| 60 | +</I>><i>     group="Staff:accountants,lawyers,security" |
| 61 | +</I> |
| 62 | +The above implies that helper response parser should not split group=X |
| 63 | +response fields (using comma as a delimiter). Do we document that |
| 64 | +anywhere? Did our helper response parser ever split such fields in the past? |
| 65 | + |
| 66 | +BTW, 2015 commit 76ee67ac used a very similar example. AFAICT by looking |
| 67 | +at that code, we did not apply value delimiters by default back then |
| 68 | +(i.e. when ACL_F_SUBSTRING a.k.a. "-m" flag was not set). The bug was |
| 69 | +introduced in 2017 commit 4eac3407 that replaced a possibly-nil |
| 70 | +`flags.delimiters()` with a never-nil `&delimiters.value`. |
| 71 | + |
| 72 | +The following comment suggests that we missed the fact that using the |
| 73 | +[default-initialized] value "without checking whether the option is |
| 74 | +enabled()" is a bug -- the corresponding "trick" never fully worked: |
| 75 | + |
| 76 | +```C++ |
| 77 | +// TODO: Some callers use .value without checking whether the option is |
| 78 | +// enabled(), accessing the (default-initialized or customized) default |
| 79 | +// value that way. This trick will stop working if we add valued options |
| 80 | +// that can be disabled (e.g., --with-foo=x --without-foo). |
| 81 | +``` |
| 82 | + |
| 83 | + |
| 84 | +><i> However, this is not the case. The helper's response is split into |
| 85 | +</I>><i> tokens using a comma as the default delimiter. As a result, only ACLs |
| 86 | +</I>><i> like the following will match: |
| 87 | +</I>><i>     acl staff note group lawyers |
| 88 | +</I>><i> |
| 89 | +</I>><i> This behavior occurs because in Acl::NoteCheck::matchNotes(), a comma is |
| 90 | +</I>><i> passed as the default delimiter to the expandListEntries() function |
| 91 | +</I> |
| 92 | +Agreed. |
| 93 | + |
| 94 | + |
| 95 | +><i> I would like to propose two changes: |
| 96 | +</I>><i> 1. Removing the default comma delimiter. |
| 97 | +</I> |
| 98 | +... and check enabled() before using the stored value, fixing the bug |
| 99 | +introduced in 2017 commit 4eac3407. |
| 100 | + |
| 101 | + |
| 102 | +><i> I am prepared to submit a simple PR to exclude this comma to fix the |
| 103 | +</I>><i> incorrect matching of strings containing commas. |
| 104 | +</I>><i> However, I realize this might be a breaking change for users who |
| 105 | +</I>><i> currently rely on this implicit splitting behavior. |
| 106 | +</I> |
| 107 | +Yes. We should disclose the bug fix in Squid release notes. |
| 108 | + |
| 109 | +We can also add code to warn admins (via a cache.log WARNING message) |
| 110 | +when a "note" ACL configured without "-m" looks at an annotation value |
| 111 | +containing a comma, but that requires more work. |
| 112 | + |
| 113 | + |
| 114 | +><i> 2. Supporting custom delimiters in helper responses. |
| 115 | +</I>><i> I also propose a PR to support a format where tag values can be passed |
| 116 | +</I>><i> as a list with a custom delimiter: |
| 117 | +</I>><i>     <key>=<delimiter>"<value1><delimiter><value2>..." |
| 118 | +</I>><i> For example: |
| 119 | +</I>><i>     group=,"group1,group2,group3" |
| 120 | +</I>><i>     clt_con_tag=;"tag1;tag2;tag3" |
| 121 | +</I>><i> In this PR, the helper response would be tokenized based on the |
| 122 | +</I>><i> specified custom delimiter, while still supporting delimiter escaping |
| 123 | +</I>><i> with a backslash (\). |
| 124 | +</I> |
| 125 | +I do not think this hack will work well as is, without syntax |
| 126 | +modifications because Squid already uses double quotes specially in this |
| 127 | +context. Overloading quotation meaning would be confusing/wrong. |
| 128 | + |
| 129 | +Overall, I am not excited about this hack, but let's start with these |
| 130 | +questions about its scope: |
| 131 | + |
| 132 | +* Can the same effect be achieved today by sending a helper response |
| 133 | +containing multiple same-name annotations? For example: |
| 134 | + |
| 135 | + group=group1 group=group2 group=group3 |
| 136 | + |
| 137 | +* If the "note" ACL bug is fixed, do we still need to allow helper to |
| 138 | +use custom value delimiters? |
| 139 | + |
| 140 | +* What would Squid do today if it receives a `group=,"a,b"` annotation |
| 141 | +from a helper? AFAICT from looking at |
| 142 | +Helper::Reply::parseResponseKeys(), Squid would silently treat the |
| 143 | +leading comma delimiter as the first character of the received |
| 144 | +annotation value and keep double quotes, right? |
| 145 | + |
| 146 | +* Squid does not treat backslashes in annotation values specially today, |
| 147 | +does it? If present, they become part of the annotation key or value, right? |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +HTH, |
| 152 | + |
| 153 | +Alex. |
| 154 | +</PRE> |
| 155 | + |
| 156 | +<!--endarticle--> |
| 157 | + <HR> |
| 158 | + <P><UL> |
| 159 | + <!--threads--> |
| 160 | + <LI>Previous message (by thread): <A HREF="010021.html">[squid-dev] Issue with acl note (without -m) splitting helper tokens containing commas |
| 161 | +</A></li> |
| 162 | + <LI>Next message (by thread): <A HREF="010018.html">[squid-dev] NO_SPECIAL_HANDLING define for HTTP methods |
| 163 | +</A></li> |
| 164 | + <LI> <B>Messages sorted by:</B> |
| 165 | + <a href="date.html#10022">[ date ]</a> |
| 166 | + <a href="thread.html#10022">[ thread ]</a> |
| 167 | + <a href="subject.html#10022">[ subject ]</a> |
| 168 | + <a href="author.html#10022">[ author ]</a> |
| 169 | + </LI> |
| 170 | + </UL> |
| 171 | + |
| 172 | +<hr> |
| 173 | +<a href="https://lists.squid-cache.org/listinfo/squid-dev">More information about the squid-dev |
| 174 | +mailing list</a><br> |
| 175 | +</body></html> |
0 commit comments