Skip to content

Commit a47918d

Browse files
authored
[ResponseOps][Alerting] xpack.actions.proxyUrl is not validated as a URL at startup (#141970)
* Adding validation * Removing error
1 parent 0b4a942 commit a47918d

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

x-pack/plugins/actions/server/config.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ describe('config validation', () => {
163163
`);
164164
});
165165

166+
test('validates proxyUrl', () => {
167+
const proxyUrl = 'https://test.com';
168+
const badProxyUrl = 'bad url';
169+
let validated: ActionsConfig;
170+
171+
validated = configSchema.validate({ proxyUrl });
172+
expect(validated.proxyUrl).toEqual(proxyUrl);
173+
expect(getValidatedConfig(mockLogger, validated).proxyUrl).toEqual(proxyUrl);
174+
expect(mockLogger.warn.mock.calls).toMatchInlineSnapshot(`Array []`);
175+
176+
validated = configSchema.validate({ proxyUrl: badProxyUrl });
177+
expect(validated.proxyUrl).toEqual(badProxyUrl);
178+
expect(getValidatedConfig(mockLogger, validated).proxyUrl).toEqual(badProxyUrl);
179+
expect(mockLogger.warn.mock.calls).toMatchInlineSnapshot(`
180+
Array [
181+
Array [
182+
"The confguration xpack.actions.proxyUrl: bad url is invalid.",
183+
],
184+
]
185+
`);
186+
});
187+
166188
// Most of the customHostSettings tests are in ./lib/custom_host_settings.test.ts
167189
// but this one seemed more relevant for this test suite, since url is the one
168190
// required property.

x-pack/plugins/actions/server/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ export type ActionsConfig = TypeOf<typeof configSchema>;
127127
export function getValidatedConfig(logger: Logger, originalConfig: ActionsConfig): ActionsConfig {
128128
const proxyBypassHosts = originalConfig.proxyBypassHosts;
129129
const proxyOnlyHosts = originalConfig.proxyOnlyHosts;
130+
const proxyUrl = originalConfig.proxyUrl;
131+
132+
if (proxyUrl) {
133+
try {
134+
new URL(proxyUrl);
135+
} catch (err) {
136+
logger.warn(`The confguration xpack.actions.proxyUrl: ${proxyUrl} is invalid.`);
137+
}
138+
}
130139

131140
if (proxyBypassHosts && proxyOnlyHosts) {
132141
logger.warn(

0 commit comments

Comments
 (0)