trafficserver icon indicating copy to clipboard operation
trafficserver copied to clipboard

added tslua script TS_LUA_RESPONSE_TRANSFORM hook ats coredump

Open syzh opened this issue 2 years ago • 3 comments

I add en empty TS_LUA_RESPONSE_TRANSFORM hook function and open redirect options, ats cordump when upstream response 302.

-- request-hook.lua
function do_remap()
    ts.hook(TS_LUA_RESPONSE_TRANSFORM, do_append_transform)

    ts.http.resp_cache_transformed(0)
    ts.http.resp_cache_untransformed(1)
end

function do_append_transform(data, eos)
    return data, eos
end

remap.conf

map http://www.test.com http://192.168.2.192 @plugin=tslua.so @pparam=/usr/local/etc/trafficserver/request-hook.lua

records.conf

CONFIG proxy.config.http.number_of_redirections INT 1
CONFIG proxy.config.http.redirect.actions STRING routable:follow,private:follow

CONFIG proxy.config.diags.output.diag STRING SL
CONFIG proxy.config.diags.output.debug STRING SL
CONFIG proxy.config.diags.output.error STRING SL
CONFIG proxy.config.diags.output.fatal STRING SL
CONFIG proxy.config.diags.output.alert STRING L
CONFIG proxy.config.diags.debug.enabled INT 3
CONFIG proxy.config.diags.debug.tags STRING http | dns | ts_lua
-- some other config

Fatal: HttpSM.cc:5522: failed assertion transform_info.vc == nullptr traffic_server: received signal 6 (Aborted) traffic_server - STACK TRACE: /usr/local/bin/traffic_server(_Z19crash_logger_invokeiP9siginfo_tPv+0xd8)[0x55d8b6fccb18] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f1f6f146520] /lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f1f6f19aa7c] /lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f1f6f146476] /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f1f6f12c7f3] /usr/local/lib/libtscore.so.9(_Z11ink_warningPKcz+0x0)[0x7f1f6fce5b36] /usr/local/lib/libtscore.so.9(_Z17ats_base64_encodePKhmPcmPm+0x0)[0x7f1f6fce1b49] /usr/local/bin/traffic_server(_ZN6HttpSM17do_transform_openEv+0x47)[0x55d8b70a8055] /usr/local/bin/traffic_server(_ZN12HttpTransact52handle_no_cache_operation_on_forward_server_responseEPNS_5StateE+0xe2b)[0x55d8b70f8887] /usr/local/bin/traffic_server(_ZN12HttpTransact37handle_forward_server_connection_openEPNS_5StateE+0xca1)[0x55d8b70f40a9] /usr/local/bin/traffic_server(_ZN12HttpTransact27handle_response_from_serverEPNS_5StateE+0x43a)[0x55d8b70f0e26] /usr/local/bin/traffic_server(_ZN12HttpTransact14HandleResponseEPNS_5StateE+0xc3c)[0x55d8b70eea26] /usr/local/bin/traffic_server(_ZN6HttpSM32call_transact_and_set_next_stateEPFvPN12HttpTransact5StateEE+0x84)[0x55d8b70b2e98] /usr/local/bin/traffic_server(_ZN6HttpSM17handle_api_returnEv+0x194)[0x55d8b708ef94] /usr/local/bin/traffic_server(_ZN6HttpSM17state_api_calloutEiPv+0xda8)[0x55d8b708ec18] /usr/local/bin/traffic_server(_ZN6HttpSM23do_api_callout_internalEv+0x242)[0x55d8b70a7ebc] /usr/local/bin/traffic_server(_ZN6HttpSM14do_api_calloutEv+0x2b)[0x55d8b70be92d] /usr/local/bin/traffic_server(_ZN6HttpSM33state_read_server_response_headerEiPv+0xd50)[0x55d8b7091e4a] /usr/local/bin/traffic_server(_ZN6HttpSM12main_handlerEiPv+0x390)[0x55d8b7096882] /usr/local/bin/traffic_server(_ZN12Continuation11handleEventEiPv+0xeb)[0x55d8b6fd2a13] /usr/local/bin/traffic_server(+0x74a283)[0x55d8b73d0283] /usr/local/bin/traffic_server(+0x74b91c)[0x55d8b73d191c] /usr/local/bin/traffic_server(_ZN18UnixNetVConnection11net_read_ioEP10NetHandlerP7EThread+0x2f)[0x55d8b73d3d73] /usr/local/bin/traffic_server(_ZN10NetHandler18process_ready_listEv+0x9f)[0x55d8b73c38e9] /usr/local/bin/traffic_server(_ZN10NetHandler15waitForActivityEl+0x4cc)[0x55d8b73c4000] /usr/local/bin/traffic_server(_ZN7EThread15execute_regularEv+0x46f)[0x55d8b741b071] /usr/local/bin/traffic_server(_ZN7EThread7executeEv+0x11e)[0x55d8b741b2ba] /usr/local/bin/traffic_server(+0x7938d6)[0x55d8b74198d6] /lib/x86_64-linux-gnu/libc.so.6(+0x94b43)[0x7f1f6f198b43] /lib/x86_64-linux-gnu/libc.so.6(+0x126a00)[0x7f1f6f22aa00]

syzh avatar May 12 '23 15:05 syzh

I found an exception on the HttpSM.cc:5522 transform_info.vc == nullptr line when the request is redirected to the Location address

comment out redirect config is ok

CONFIG proxy.config.http.number_of_redirections INT 1
CONFIG proxy.config.http.redirect.actions STRING routable:follow,private:follow

ats version Traffic Server 9.2.0

syzh avatar May 12 '23 15:05 syzh

What would you like to accomplish? In that case, there is no response body to transform inside an internal redirect. So the transform will fail.

You can add a read response hook inside do_remap. And then you can conditionally add the response transform inside the read response hook handler function. You will only call the response transform handler function when the response status code is status 200.

Will this work for your use case?

shukitchan avatar May 12 '23 19:05 shukitchan

This issue has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community.

github-actions[bot] avatar May 12 '24 01:05 github-actions[bot]