Skip to content

Commit 7e4119a

Browse files
committed
hrw4u: disallow inbound.url.{} as an operator
When one uses inbound.url.{} as an operator, for instance: REMAP { inbound.url.host = "example.com"; } hrw4u turns this into set-destination which modifies the outbound URL, making the naming actively misleading. inbound.url reads from the pristine client URL (CLIENT-URL) which is immutable — ATS provides no mechanism to set it. So, removing this as an operator, but keeping it as a valid condition.
1 parent a65725d commit 7e4119a

12 files changed

Lines changed: 16 additions & 18 deletions

doc/admin-guide/configuration/hrw4u.en.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ cond %{INBOUND:<C>} {in,out}bound.conn.<c> inbound (:r
282282

283283
- ``inbound.req.<header>`` → ``CLIENT-HEADER`` - Headers from the client request
284284
- ``outbound.req.<header>`` → ``SERVER-HEADER`` - Headers in the request sent to origin
285-
- ``inbound.url.<part>`` → ``CLIENT-URL`` - URL from the original client request
285+
- ``inbound.url.<part>`` → ``CLIENT-URL`` - URL from the original client request (which is immutable)
286286
- ``outbound.url.<part>`` → ``SERVER-URL`` - URL in the request sent to origin (after remapping)
287287
- ``nexthop.<field>`` → ``NEXT-HOP`` - Network destination info (host, port, strategy)
288288

@@ -319,7 +319,7 @@ add-header X-bar foo inbound.{req,resp}.x-Bar += "bar" Add the header t
319319
counter my_stat counter("my_stat") Increment internal counter
320320
rm-client-header X-Foo inbound.req.X-Foo = "" Remove a client request header
321321
rm-cookie foo {in,out}bound.cookie.foo = "" Remove the cookie named foo
322-
rm-destination <C> inbound.url.<C> = "" Remove an URL component, ``C`` is path, query etc.
322+
rm-destination <C> outbound.url.<C> = "" Remove an URL component, ``C`` is path, query etc.
323323
rm-header X-Foo {in,out}bound.req.X-Foo = "" Context sensitive header removal
324324
rm-destination QUERY ... remove_query("foo,bar") Remove specified query keys
325325
rm-destination QUERY ... [I] keep_query("foo,bar") Keep only specified query keys
@@ -330,7 +330,7 @@ set-config <name> 12 set-config("name", 17) Set a configurat
330330
set-conn-dscp 8 inbound.conn.dscp = 8 Set the DSCP value for the connection
331331
set-conn-mark 17 inbound.conn.mark = 17 Set the MARK value for the connection
332332
set-cookie foo bar {in,out}bound.cookie.foo = "bar" Set a request/response cookie named foo
333-
set-destination <C> bar {in,out}bound.url.<C> = "bar" Set a URL component, <:ref:`C<admin-plugins-header-rewrite-url-parts>`> is path, query etc.
333+
set-destination <C> bar outbound.url.<C> = "bar" Set a URL component, <:ref:`C<admin-plugins-header-rewrite-url-parts>`> is path, query etc.
334334
set-header X-Bar foo inbound.{req,resp}.X-Bar = "foo" Assign a client request/origin response header
335335
set-plugin-cntl <C> <T> set-plugin-cntl(<C>) = <T> Set the plugin control <C> to <T>, see <:ref:`C<admin-plugins-header-rewrite-plugin-cntl>`>
336336
set-redirect <Code> <URL> set-redirect(302, "\https://...") Set a redirect response
@@ -1075,7 +1075,7 @@ Remove Client Query Parameters
10751075
The following ruleset removes any query parameters set by the client.::
10761076

10771077
REMAP {
1078-
inbound.url.query = "";
1078+
outbound.url.query = "";
10791079
}
10801080

10811081
Remove only a few select query parameters::

tools/hrw4u/src/generators.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def generate_context_mappings(self) -> dict[str, dict[SectionType | frozenset[Se
7272
},
7373
"URL_CONTEXT_MAP":
7474
{
75-
SectionType.REMAP: "inbound.url.",
76-
frozenset({SectionType.PRE_REMAP, SectionType.READ_REQUEST, SectionType.SEND_REQUEST}): "outbound.url."
75+
frozenset({SectionType.REMAP, SectionType.PRE_REMAP, SectionType.READ_REQUEST, SectionType.SEND_REQUEST}): "outbound.url."
7776
}
7877
}
7978

tools/hrw4u/src/hrw_symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def op_to_hrw4u(self, cmd: str, args: list[str], section: SectionType | None, op
480480
if len(args) > 1:
481481
func = "keep_query" if op_state.invert else "remove_query"
482482
return f"{func}({self._rewrite_inline_percents(args[1], section)})"
483-
return 'inbound.url.query = ""'
483+
return f'{self.get_prefix_for_context("destination_ops", section)}query = ""'
484484

485485
toks = [cmd] + args
486486
line = " ".join(toks)

tools/hrw4u/src/tables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"inbound.resp.": MapParams(target=HeaderOperations.OPERATIONS, add=True, validate=Validator.http_header_name(), sections={SectionType.READ_RESPONSE, SectionType.SEND_RESPONSE}),
4848
"inbound.status.reason": MapParams(target="set-status-reason", validate=Validator.quoted_or_simple(), sections=HTTP_SECTIONS),
4949
"inbound.status": MapParams(target="set-status", validate=Validator.range(0, 999), sections=HTTP_SECTIONS),
50-
"inbound.url.": MapParams(target=HeaderOperations.DESTINATION_OPERATIONS, upper=True, validate=Validator.suffix_group(SuffixGroup.URL_FIELDS), sections=HTTP_SECTIONS),
5150
"outbound.cookie.": MapParams(target=HeaderOperations.COOKIE_OPERATIONS, validate=Validator.http_token(), sections={SectionType.SEND_REQUEST, SectionType.READ_RESPONSE, SectionType.SEND_RESPONSE}),
5251
"outbound.req.": MapParams(target=HeaderOperations.OPERATIONS, add=True, validate=Validator.http_header_name(), sections={SectionType.SEND_REQUEST, SectionType.READ_RESPONSE, SectionType.SEND_RESPONSE}),
5352
"outbound.resp.": MapParams(target=HeaderOperations.OPERATIONS, add=True, validate=Validator.http_header_name(), sections={SectionType.READ_RESPONSE, SectionType.SEND_RESPONSE}),
@@ -156,7 +155,7 @@
156155
"header_condition": ("HEADER_CONTEXT_MAP", "inbound.resp."),
157156
"header_ops": ("HEADER_CONTEXT_MAP", "inbound.resp."),
158157
"cookie_ops": "inbound.cookie.",
159-
"destination_ops": ("URL_CONTEXT_MAP", "inbound.url.")
158+
"destination_ops": ("URL_CONTEXT_MAP", "outbound.url.")
160159
}
161160

162161
# Operator command mappings for reverse resolution

tools/hrw4u/tests/data/examples/all-nonsense.ast.txt

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tools/hrw4u/tests/data/examples/all-nonsense.input.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ PRE_REMAP {
6060

6161
REMAP {
6262
if (from.url.host == "old.example.com" with NOCASE) {
63-
inbound.url.host = "new.example.com";
63+
outbound.url.host = "new.example.com";
6464
keep_query("id,utm_campaign");
6565
}
6666

6767
if (to.url.path ~ /(?i)^\/legacy\//) {
68-
inbound.url.path = "/v2/";
68+
outbound.url.path = "/v2/";
6969
remove_query("debug,trace");
7070
}
7171

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(program (programItem (section REMAP { (sectionBody (statement inbound.url.query = (value "") ;)) (sectionBody (statement (functionCall remove_query ( (argumentList (value "foo,bar")) )) ;)) (sectionBody (statement (functionCall keep_query ( (argumentList (value "foo,bar")) )) ;)) })) <EOF>)
1+
(program (programItem (section REMAP { (sectionBody (statement outbound.url.query = (value "") ;)) (sectionBody (statement (functionCall remove_query ( (argumentList (value "foo,bar")) )) ;)) (sectionBody (statement (functionCall keep_query ( (argumentList (value "foo,bar")) )) ;)) })) <EOF>)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
REMAP {
2-
inbound.url.query = "";
2+
outbound.url.query = "";
33
remove_query("foo,bar");
44
keep_query("foo,bar");
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tests/data/ops/bad_path.fail.input.txt:2:2: error: Invalid suffix 'ATH' for group 'URL_FIELDS'. Must be one of: HOST, PATH, PORT, QUERY, SCHEME, URL
2-
2 | inbound.url.ath="foo";
2+
2 | outbound.url.ath="foo";
33
| ^
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
REMAP {
2-
inbound.url.ath="foo";
2+
outbound.url.ath="foo";
33
}

0 commit comments

Comments
 (0)