Skip to content

Commit ebb5e34

Browse files
authored
hrw4u: Fix u4wrh HEADER value resolution missing section context (#13068)
* hrw4u: Fix u4wrh HEADER value resolution missing section context _handle_set_rm_operation was passing None as the section to _rewrite_inline_percents, causing %{HEADER:...} in operator values to always resolve to the default inbound.resp. prefix instead of the correct context-dependent prefix. * Address Copilot's review
1 parent edb548b commit ebb5e34

7 files changed

Lines changed: 57 additions & 3 deletions

tools/hrw4u/src/hrw_symbols.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,14 @@ def repl(match: re.Match) -> str:
231231

232232
return repl
233233

234-
def _handle_set_rm_operation(self, cmd: str, toks: list[str], prefix: str, qualifier: str, context: str) -> str:
234+
def _handle_set_rm_operation(
235+
self, cmd: str, toks: list[str], prefix: str, qualifier: str, section: SectionType | None = None) -> str:
235236
if cmd.startswith("rm-"):
236237
return f'{prefix}{qualifier} = ""'
237238
if len(toks) < 3:
238239
raise SymbolResolutionError(" ".join(toks), f"Missing value for {cmd}")
239240
value = " ".join(toks[2:])
240-
value = self._rewrite_inline_percents(value, None)
241+
value = self._rewrite_inline_percents(value, section)
241242
return f"{prefix}{qualifier} = {value}"
242243

243244
def _handle_operator_command(
@@ -260,7 +261,7 @@ def _handle_operator_command(
260261
prefix = self.get_prefix_for_context(context_type, section)
261262

262263
processed_qualifier = qualifier_processor(qualifier)
263-
return self._handle_set_rm_operation(cmd, toks, prefix, processed_qualifier, op_context)
264+
return self._handle_set_rm_operation(cmd, toks, prefix, processed_qualifier, section)
264265

265266
if lhs_key.endswith("."):
266267
if len(toks) < 2:

tools/hrw4u/tests/data/ops/exceptions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33

44
# QSA (Query String Append) is a reverse-only test
55
qsa.input: u4wrh
6+
# HEADER value context is reverse-only (forward uses explicit SERVER-HEADER)
7+
header_value_context.input: u4wrh
68
# HTTP-CNTL valid bools can not reverse back to the original input
79
http_cntl_valid_bools.input: hrw4u
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(program (programItem (section SEND_REQUEST { (sectionBody (statement outbound.req.X-From-Client = (value "{inbound.req.X-Source}") ;)) (sectionBody (statement outbound.req.X-From-Server = (value "{outbound.req.X-Source}") ;)) })) (programItem (section READ_RESPONSE { (sectionBody (statement outbound.resp.X-From-Client = (value "{inbound.req.X-Source}") ;)) (sectionBody (statement outbound.resp.X-From-Server = (value "{outbound.req.X-Source}") ;)) })) (programItem (section SEND_RESPONSE { (sectionBody (statement inbound.resp.X-From-Client = (value "{inbound.req.X-Source}") ;)) (sectionBody (statement inbound.resp.X-From-Server = (value "{outbound.req.X-Source}") ;)) })) <EOF>)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SEND_REQUEST {
2+
outbound.req.X-From-Client = "{inbound.req.X-Source}";
3+
outbound.req.X-From-Server = "{outbound.req.X-Source}";
4+
}
5+
6+
READ_RESPONSE {
7+
outbound.resp.X-From-Client = "{inbound.req.X-Source}";
8+
outbound.resp.X-From-Server = "{outbound.req.X-Source}";
9+
}
10+
11+
SEND_RESPONSE {
12+
inbound.resp.X-From-Client = "{inbound.req.X-Source}";
13+
inbound.resp.X-From-Server = "{outbound.req.X-Source}";
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cond %{SEND_REQUEST_HDR_HOOK} [AND]
2+
set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
3+
set-header X-From-Server "%{SERVER-HEADER:X-Source}"
4+
5+
cond %{READ_RESPONSE_HDR_HOOK} [AND]
6+
set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
7+
set-header X-From-Server "%{SERVER-HEADER:X-Source}"
8+
9+
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
10+
set-header X-From-Client "%{CLIENT-HEADER:X-Source}"
11+
set-header X-From-Server "%{SERVER-HEADER:X-Source}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SEND_REQUEST {
2+
outbound.req.X-Auth = "{outbound.req.X-Token}";
3+
outbound.req.X-Info = "val={outbound.req.X-Detail}";
4+
}
5+
6+
READ_RESPONSE {
7+
outbound.resp.X-Auth = "{outbound.resp.X-Token}";
8+
outbound.resp.X-Info = "val={outbound.resp.X-Detail}";
9+
}
10+
11+
SEND_RESPONSE {
12+
inbound.resp.X-Auth = "{inbound.resp.X-Token}";
13+
inbound.resp.X-Info = "val={inbound.resp.X-Detail}";
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cond %{SEND_REQUEST_HDR_HOOK} [AND]
2+
set-header X-Auth %{HEADER:X-Token}
3+
set-header X-Info "val=%{HEADER:X-Detail}"
4+
5+
cond %{READ_RESPONSE_HDR_HOOK} [AND]
6+
set-header X-Auth %{HEADER:X-Token}
7+
set-header X-Info "val=%{HEADER:X-Detail}"
8+
9+
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
10+
set-header X-Auth %{HEADER:X-Token}
11+
set-header X-Info "val=%{HEADER:X-Detail}"

0 commit comments

Comments
 (0)