Skip to content

Commit b330ddc

Browse files
committed
change slack action to only report on whitelisted host name
1 parent bc8a41a commit b330ddc

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

  • x-pack
    • plugins/actions/server/builtin_action_types
    • test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types

x-pack/plugins/actions/server/builtin_action_types/slack.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ describe('validateActionTypeSecrets()', () => {
7474
}).toThrowErrorMatchingInlineSnapshot(
7575
`"error validating action type secrets: [webhookUrl]: expected value of type [string] but got [number]"`
7676
);
77+
78+
expect(() => {
79+
validateSecrets(actionType, { webhookUrl: 'fee-fi-fo-fum' });
80+
}).toThrowErrorMatchingInlineSnapshot(
81+
`"error validating action type secrets: error configuring slack action: unable to parse host name from webhookUrl"`
82+
);
7783
});
7884

7985
test('should validate and pass when the slack webhookUrl is whitelisted', () => {
@@ -95,16 +101,16 @@ describe('validateActionTypeSecrets()', () => {
95101
actionType = getActionType({
96102
configurationUtilities: {
97103
...configUtilsMock,
98-
ensureWhitelistedUri: url => {
99-
throw new Error(`target url is not whitelisted`);
104+
ensureWhitelistedHostname: url => {
105+
throw new Error(`target hostname is not whitelisted`);
100106
},
101107
},
102108
});
103109

104110
expect(() => {
105111
validateSecrets(actionType, { webhookUrl: 'https://api.slack.com/' });
106112
}).toThrowErrorMatchingInlineSnapshot(
107-
`"error validating action type secrets: error configuring slack action: target url is not whitelisted"`
113+
`"error validating action type secrets: error configuring slack action: target hostname is not whitelisted"`
108114
);
109115
});
110116
});

x-pack/plugins/actions/server/builtin_action_types/slack.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { URL } from 'url';
78
import { curry } from 'lodash';
89
import { i18n } from '@kbn/i18n';
910
import { schema, TypeOf } from '@kbn/config-schema';
@@ -66,8 +67,17 @@ function valdiateActionTypeConfig(
6667
configurationUtilities: ActionsConfigurationUtilities,
6768
secretsObject: ActionTypeSecretsType
6869
) {
70+
let url: URL;
6971
try {
70-
configurationUtilities.ensureWhitelistedUri(secretsObject.webhookUrl);
72+
url = new URL(secretsObject.webhookUrl);
73+
} catch (err) {
74+
return i18n.translate('xpack.actions.builtin.slack.slackConfigurationErrorNoHostname', {
75+
defaultMessage: 'error configuring slack action: unable to parse host name from webhookUrl',
76+
});
77+
}
78+
79+
try {
80+
configurationUtilities.ensureWhitelistedHostname(url.hostname);
7181
} catch (whitelistError) {
7282
return i18n.translate('xpack.actions.builtin.slack.slackConfigurationError', {
7383
defaultMessage: 'error configuring slack action: {message}',

x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/slack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function slackTest({ getService }: FtrProviderContext) {
9494
name: 'A slack action',
9595
actionTypeId: '.slack',
9696
secrets: {
97-
webhookUrl: 'http://slack.mynonexistent.com',
97+
webhookUrl: 'http://slack.mynonexistent.com/other/stuff/in/the/path',
9898
},
9999
})
100100
.expect(400)
@@ -103,7 +103,7 @@ export default function slackTest({ getService }: FtrProviderContext) {
103103
statusCode: 400,
104104
error: 'Bad Request',
105105
message:
106-
'error validating action type secrets: error configuring slack action: target url "http://slack.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts',
106+
'error validating action type secrets: error configuring slack action: target hostname "slack.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts',
107107
});
108108
});
109109
});

0 commit comments

Comments
 (0)