Skip to content

Commit e2f4963

Browse files
authored
Merge branch 'master' into master
2 parents 123083d + 0d143d4 commit e2f4963

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Changed
4848
* Renamed reference to the RBAC backend/plugin from ``enterprise`` to ``default``. Updated st2api
4949
validation to use the new value when checking RBAC configuration. Removed other references to
5050
enterprise for RBAC related contents. (improvement)
51+
* Remove authentication headers ``St2-Api-Key``, ``X-Auth-Token`` and ``Cookie`` from webhook payloads to
52+
prevent them from being stored in the database. (security bug fix) #4983
53+
54+
Contributed by @potato and @knagy
5155

5256
Fixed
5357
~~~~~

st2api/st2api/controllers/v1/webhooks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
urljoin = urlparse.urljoin
2020

2121
from st2common import log as logging
22+
from st2common.constants.auth import HEADER_API_KEY_ATTRIBUTE_NAME, HEADER_ATTRIBUTE_NAME
2223
from st2common.constants.triggers import WEBHOOK_TRIGGER_TYPES
2324
from st2common.models.api.trace import TraceContext
2425
from st2common.models.api.trigger import TriggerAPI
@@ -126,6 +127,7 @@ def post(self, hook, webhook_body_api, headers, requester_user):
126127
permission_type=permission_type)
127128

128129
headers = self._get_headers_as_dict(headers)
130+
headers = self._filter_authentication_headers(headers)
129131

130132
# If webhook contains a trace-tag use that else create create a unique trace-tag.
131133
trace_context = self._create_trace_context(trace_tag=headers.pop(TRACE_TAG_HEADER, None),
@@ -219,6 +221,10 @@ def _get_headers_as_dict(self, headers):
219221
headers_dict[key] = value
220222
return headers_dict
221223

224+
def _filter_authentication_headers(self, headers):
225+
auth_headers = [HEADER_API_KEY_ATTRIBUTE_NAME, HEADER_ATTRIBUTE_NAME, 'Cookie']
226+
return {key: value for key, value in headers.items() if key not in auth_headers}
227+
222228
def _log_request(self, msg, headers, body, log_method=LOG.debug):
223229
headers = self._get_headers_as_dict(headers)
224230
body = str(body)

st2api/tests/unit/controllers/v1/test_webhooks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,26 @@ def get_webhook_trigger(name, url):
320320
self.assertTrue(controller._is_valid_hook('with_leading_trailing_slash'))
321321
self.assertTrue(controller._is_valid_hook('with/mixed/slash'))
322322

323+
@mock.patch.object(TriggerInstancePublisher, 'publish_trigger', mock.MagicMock(
324+
return_value=True))
325+
@mock.patch.object(WebhooksController, '_is_valid_hook', mock.MagicMock(
326+
return_value=True))
327+
@mock.patch.object(HooksHolder, 'get_triggers_for_hook', mock.MagicMock(
328+
return_value=[DUMMY_TRIGGER_DICT]))
329+
@mock.patch('st2common.transport.reactor.TriggerDispatcher.dispatch')
330+
def test_authentication_headers_should_be_removed(self, dispatch_mock):
331+
headers = {
332+
'Content-Type': 'application/x-www-form-urlencoded',
333+
'St2-Api-Key': 'foobar',
334+
'X-Auth-Token': 'deadbeaf',
335+
'Cookie': 'foo=bar'
336+
}
337+
338+
self.app.post('/v1/webhooks/git', WEBHOOK_1, headers=headers)
339+
self.assertNotIn('St2-Api-Key', dispatch_mock.call_args[1]['payload']['headers'])
340+
self.assertNotIn('X-Auth-Token', dispatch_mock.call_args[1]['payload']['headers'])
341+
self.assertNotIn('Cookie', dispatch_mock.call_args[1]['payload']['headers'])
342+
323343
def __do_post(self, hook, webhook, expect_errors=False, headers=None):
324344
return self.app.post_json('/v1/webhooks/' + hook,
325345
params=webhook,

0 commit comments

Comments
 (0)