Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : hide http push security token in the subscribers api [SDESK-7093] #2483

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion apps/publish/publish_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,52 @@ class PublishServiceTests(TestCase):
"sequence_num_settings": {"max": 10, "min": 1},
"critical_errors": {"9004": True},
"destinations": [{"name": "NITF", "delivery_type": "ftp", "format": "nitf", "config": {}}],
}
},
{
"_id": "2",
"name": "Test2",
"subscriber_type": SUBSCRIBER_TYPES.WIRE,
"media_type": "media",
"is_active": True,
"sequence_num_settings": {"max": 10, "min": 1},
"critical_errors": {"9004": True},
"destinations": [
{
"name": "HTTP PUSH",
"delivery_type": "http_push",
"format": "nitf",
"config": {
"resource_url": "http://localhost:5050/push",
"assets_url": "http://localhost:5050/push_binary",
"packaged": "true",
"secret_token": "newsroom",
},
}
],
},
{
"_id": "3",
"name": "Test3",
"subscriber_type": SUBSCRIBER_TYPES.WIRE,
"media_type": "media",
"is_active": True,
"sequence_num_settings": {"max": 10, "min": 1},
"critical_errors": {"9004": True},
"destinations": [
{
"name": "AMAZON SQS",
"delivery_type": "amazon_sqs_fifo",
"format": "nitf",
"config": {
"access_key_id": "demokeyaccess",
"attach_media": False,
"message_group_id": "messageGroupId",
"queue_name": "demo test",
"secret_access_key": "accesskey",
},
}
],
},
]

def setUp(self):
Expand Down Expand Up @@ -114,3 +159,15 @@ def test_highlight_query(self):
self.assertEqual(
["body_html", "body_footer", "headline", "slugline", "abstract"], list(source["highlight"]["fields"].keys())
)

def test_subscribers_secret_keys(self):
subscriber_service = superdesk.get_resource_service("subscribers")
data = list(subscriber_service.get(req=None, lookup={}))
item = data[1]
self.assertEqual("Test2", item["name"])
self.assertNotIn("secret_token", item["destinations"][0]["config"])

item = data[2]
self.assertEqual("Test3", item["name"])
self.assertNotIn("access_key_id", item["destinations"][0]["config"])
self.assertNotIn("secret_access_key", item["destinations"][0]["config"])
23 changes: 21 additions & 2 deletions superdesk/publish/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ class SubscribersService(CacheableService):
cache_lookup = {"is_active": True}

def get(self, req, lookup):
fields = ("secret_token", "password", "apiKey", "access_key_id", "secret_access_key")
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
if req is None:
req = ParsedRequest()
if req.args and req.args.get("filter_condition"):
filter_condition = json.loads(req.args.get("filter_condition"))
return ListCursor(self._get_subscribers_by_filter_condition(filter_condition))
return super().get_from_mongo(req=req, lookup=lookup)
return self.hideConfigField(self._get_subscribers_by_filter_condition(filter_condition), fields)

return self.hideConfigField(list(super().get_from_mongo(req=req, lookup=lookup)), fields)

def on_create(self, docs):
for doc in docs:
Expand Down Expand Up @@ -291,3 +293,20 @@ def generate_sequence_number(self, subscriber):

def get_active(self):
return self.get_cached()

def hideConfigField(self, docs, fields):
return ListCursor(
[
{
**doc,
"destinations": [
{
**destination,
"config": {key: value for key, value in destination["config"].items() if key not in fields},
}
for destination in doc.get("destinations", [])
],
}
for doc in docs
]
)
Loading