Skip to content

Commit 2bc7782

Browse files
committed
out_azure_logs_ingestion: validate auth_url override
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent efb10f4 commit 2bc7782

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

plugins/out_azure_logs_ingestion/azure_logs_ingestion_conf.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,60 @@
2626
#include "azure_logs_ingestion.h"
2727
#include "azure_logs_ingestion_conf.h"
2828

29+
static int validate_auth_url_override(struct flb_output_instance *ins,
30+
flb_sds_t auth_url_override)
31+
{
32+
int ret;
33+
int result;
34+
char *protocol = NULL;
35+
char *host = NULL;
36+
char *port = NULL;
37+
char *uri = NULL;
38+
39+
result = -1;
40+
41+
ret = flb_utils_url_split(auth_url_override, &protocol, &host, &port, &uri);
42+
if (ret == -1 || protocol == NULL || host == NULL) {
43+
flb_plg_error(ins, "property 'auth_url' has an invalid URL");
44+
goto cleanup;
45+
}
46+
47+
if (strcasecmp(protocol, "https") == 0) {
48+
result = 0;
49+
goto cleanup;
50+
}
51+
52+
if (strcasecmp(protocol, "http") != 0) {
53+
flb_plg_error(ins, "property 'auth_url' must use http or https");
54+
goto cleanup;
55+
}
56+
57+
if (strcmp(host, "localhost") == 0 || strcmp(host, "127.0.0.1") == 0) {
58+
result = 0;
59+
goto cleanup;
60+
}
61+
62+
flb_plg_error(ins,
63+
"property 'auth_url' must use https or an explicit loopback "
64+
"http endpoint");
65+
66+
cleanup:
67+
if (protocol != NULL) {
68+
flb_free(protocol);
69+
}
70+
if (host != NULL) {
71+
flb_free(host);
72+
}
73+
if (port != NULL) {
74+
flb_free(port);
75+
}
76+
if (uri != NULL) {
77+
flb_free(uri);
78+
}
79+
80+
return result;
81+
}
82+
2983
struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
3084
struct flb_config *config)
3185
{
@@ -92,6 +146,12 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
92146
}
93147

94148
if (ctx->auth_url_override) {
149+
ret = validate_auth_url_override(ins, ctx->auth_url_override);
150+
if (ret == -1) {
151+
flb_az_li_ctx_destroy(ctx);
152+
return NULL;
153+
}
154+
95155
ctx->auth_url = flb_sds_create(ctx->auth_url_override);
96156
if (!ctx->auth_url) {
97157
flb_errno();

0 commit comments

Comments
 (0)