mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-26 03:38:47 +00:00
Merge commit from fork
On a profile with `extended-info-parsing` set, an inbound SIP INFO whose content type is `freeswitch/api-request` puts an FSAPI command in the request body and gets its output back in the 200 OK. The branch needs no dialog, and no `mod_sofia` authentication or ACL setting covers an out-of-dialog INFO. That same param also enables the in-dialog `session-event` half, so there is no way to keep one and not the other. The new per-profile `enable-info-api-request` param gates the api-request branch alone and is off unless set, leaving `session-event` reachable under `extended-info-parsing` as before. An INFO selecting the branch on a profile without the new param is answered 403 and logged with the source and the requested command; a permitted one is logged too, since the source address appears in no event the API path fires. Both lines print the body's first line, capped, rather than the whole body.
This commit is contained in:
1 parent
1fa330cafd
commit
fd911220be
5 files changed
+53
-1
No files matched your search
@@ -107,6 +107,10 @@
|
||||
<!-- extended info parsing -->
|
||||
<!-- <param name="extended-info-parsing" value="true"/> -->
|
||||
|
||||
<!-- with extended-info-parsing on, lets an INFO body of content type freeswitch/api-request
|
||||
run FreeSWITCH API commands, so enable only for trusted peers -->
|
||||
<!-- <param name="enable-info-api-request" value="true"/> -->
|
||||
|
||||
<!--<param name="aggressive-nat-detection" value="true"/>-->
|
||||
<!--
|
||||
There are known issues (asserts and segfaults) when 100rel is enabled.
|
||||
|
||||
@@ -107,6 +107,10 @@
|
||||
<!-- extended info parsing -->
|
||||
<!-- <param name="extended-info-parsing" value="true"/> -->
|
||||
|
||||
<!-- with extended-info-parsing on, lets an INFO body of content type freeswitch/api-request
|
||||
run FreeSWITCH API commands, so enable only for trusted peers -->
|
||||
<!-- <param name="enable-info-api-request" value="true"/> -->
|
||||
|
||||
<!-- lets an inbound MESSAGE to api+<command> run FreeSWITCH API commands, so enable only for trusted peers -->
|
||||
<!-- <param name="enable-chat-api-proto" value="true"/> -->
|
||||
|
||||
|
||||
@@ -148,6 +148,11 @@
|
||||
<!-- extended info parsing -->
|
||||
<!-- <param name="extended-info-parsing" value="true"/> -->
|
||||
|
||||
<!-- with extended-info-parsing on, lets an INFO body of content type
|
||||
freeswitch/api-request run FreeSWITCH API commands, so enable only
|
||||
for trusted peers -->
|
||||
<!-- <param name="enable-info-api-request" value="true"/> -->
|
||||
|
||||
<!-- lets an inbound MESSAGE to api+<command> run FreeSWITCH API commands,
|
||||
so enable only for trusted peers -->
|
||||
<!-- <param name="enable-chat-api-proto" value="true"/> -->
|
||||
|
||||
@@ -312,6 +312,7 @@ typedef enum {
|
||||
PFLAG_AUTH_CALLS_ACL_ONLY,
|
||||
PFLAG_USE_PORT_FOR_ACL_CHECK,
|
||||
PFLAG_ENABLE_CHAT_API_PROTO,
|
||||
PFLAG_ENABLE_INFO_API_REQUEST,
|
||||
|
||||
/* No new flags below this line */
|
||||
PFLAG_MAX
|
||||
|
||||
@@ -5612,6 +5612,12 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
|
||||
} else {
|
||||
sofia_clear_pflag(profile, PFLAG_EXTENDED_INFO_PARSING);
|
||||
}
|
||||
} else if (!strcasecmp(var, "enable-info-api-request")) {
|
||||
if (switch_true(val)) {
|
||||
sofia_set_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST);
|
||||
} else {
|
||||
sofia_clear_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST);
|
||||
}
|
||||
} else if (!strcasecmp(var, "nonce-ttl") && !zstr(val)) {
|
||||
profile->nonce_ttl = atoi(val);
|
||||
} else if (!strcasecmp(var, "max-auth-validity") && !zstr(val)) {
|
||||
@@ -9952,10 +9958,42 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
|
||||
return;
|
||||
|
||||
} else if (!strcasecmp(sip->sip_content_type->c_subtype, "api-request")) {
|
||||
char *cmd = strdup(sip->sip_payload->pl_data);
|
||||
char *cmd;
|
||||
char *arg;
|
||||
char network_ip[80] = "";
|
||||
int network_port = 0;
|
||||
size_t log_len;
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
|
||||
/* leaves the buffer empty when the message carries no address info */
|
||||
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
|
||||
|
||||
/* Both log lines below print the body's first line only, capped: the body comes
|
||||
from the request, has no length bound, and may hold line breaks. */
|
||||
log_len = strcspn(sip->sip_payload->pl_data, "\r\n");
|
||||
if (log_len > 256) {
|
||||
log_len = 256;
|
||||
}
|
||||
|
||||
if (!sofia_test_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
|
||||
"Profile [%s] rejected an INFO from %s:%d requesting a FreeSWITCH API command [%.*s]. "
|
||||
"Set enable-info-api-request=true on the profile to permit it.\n",
|
||||
profile->name, network_ip, network_port, (int) log_len, sip->sip_payload->pl_data);
|
||||
|
||||
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS_MSG(de->data->e_msg),
|
||||
TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)),
|
||||
TAG_END());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||
"Profile [%s] running a FreeSWITCH API command requested by an INFO from %s:%d [%.*s]\n",
|
||||
profile->name, network_ip, network_port, (int) log_len, sip->sip_payload->pl_data);
|
||||
|
||||
cmd = strdup(sip->sip_payload->pl_data);
|
||||
|
||||
switch_assert(cmd);
|
||||
SWITCH_STANDARD_STREAM(stream);
|
||||
switch_assert(stream.data);
|
||||
|
||||
Reference in new issue
Block a user