ishaaaan17 opened a new pull request, #14003:
URL: https://github.com/apache/trafficserver/pull/14003

   Follow-up to #13918 addressing remaining areas where `requestUrl` becomes 
stale after a plugin replaces the URL object (as noted by @bryancall).
   
   ### Problem
   When a remap plugin (such as `header_rewrite` with `set-destination URL`) 
rewrites the destination URL, `TSHttpHdrUrlSet()` deallocates the old `URLImpl` 
and assigns a newly allocated `URLImpl` to the request header.
   
   This left stale `requestUrl` handles in three scenarios:
   1. **Chained plugins on a single remap line** (`RemapPlugins.cc`):
      `RemapPlugins::run_plugin()` cached `_request_url` once at remap 
initialization before any plugins executed. Subsequent plugins on the same 
remap line received the deallocated `_request_url->m_url_impl` in 
`rri.requestUrl`. If a subsequent plugin (such as a second `header_rewrite` 
instance) accessed `rri->requestUrl` (e.g. via `rm-destination QUERY`), Traffic 
Server crashed with an SDK sanity assertion abort.
   2. **`%{URL:...}` condition in remap rules** (`conditions.cc`):
      When `set-destination URL` was executed earlier in a remap rule, 
`ConditionUrl` still retrieved `res._rri->requestUrl` rather than the updated 
header URL, evaluating against the deallocated URL object.
   3. **`set-redirect` operator in remap rules** (`operators.cc`):
      When `set-destination URL` ran before `set-redirect`, 
`OperatorSetRedirect::exec()` accessed and parsed into the stale 
`res._rri->requestUrl`. Additionally, `RemapPlugins::run_plugin()` read 
`_s->remap_redirect` from the pre-cached `_request_url`.
   
   ### Solution
   1. **`src/proxy/http/remap/RemapPlugins.cc`**:
      - Refresh `_request_url = _request_header->url_get()` on each plugin 
invocation before populating `rri.requestUrl`.
      - Refresh `_request_url = _request_header->url_get()` prior to reading 
`_s->remap_redirect` when `rri.redirect` is set.
   2. **`plugins/header_rewrite/conditions.cc`**:
      - In `ConditionUrl::append_value`, check `res.changed_url` before reading 
`res._rri->requestUrl`, falling back to `TSHttpHdrUrlGet()` matching 
`OperatorSetDestination`.
   3. **`plugins/header_rewrite/operators.cc`**:
      - In `OperatorSetRedirect::exec`, check `res.changed_url` before reading 
`res._rri->requestUrl`, falling back to `TSHttpHdrUrlGet()`.
   4. **Regression Test**:
      - Added 
`tests/uranium_tests/pluginTest/header_rewrite/header_rewrite_remap_url.test.yaml`
 verifying all three scenarios.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to