Skip to content

Commit 7d5e8cc

Browse files
authored
Remove unsafe imports in Slack API Connection (#26459)
1 parent f51587e commit 7d5e8cc

File tree

5 files changed

+1
-74
lines changed

5 files changed

+1
-74
lines changed

airflow/providers/slack/hooks/slack.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get_conn(self) -> WebClient:
135135
def _get_conn_params(self) -> dict[str, Any]:
136136
"""Fetch connection params as a dict and merge it with hook parameters."""
137137
conn = self.get_connection(self.slack_conn_id) if self.slack_conn_id else None
138-
conn_params: dict[str, Any] = {}
138+
conn_params: dict[str, Any] = {"retry_handlers": self.retry_handlers}
139139

140140
if self._token:
141141
conn_params["token"] = self._token
@@ -158,9 +158,6 @@ def _get_conn_params(self) -> dict[str, Any]:
158158
"timeout": self.timeout or extra_config.getint("timeout", default=None),
159159
"base_url": self.base_url or extra_config.get("base_url", default=None),
160160
"proxy": self.proxy or extra_config.get("proxy", default=None),
161-
"retry_handlers": (
162-
self.retry_handlers or extra_config.getimports("retry_handlers", default=None)
163-
),
164161
}
165162
)
166163

@@ -314,12 +311,6 @@ def get_connection_form_widgets(cls) -> dict[str, Any]:
314311
widget=BS3TextFieldWidget(),
315312
description="Optional. Proxy to make the Slack API call.",
316313
),
317-
prefixed_extra_field("retry_handlers", cls.conn_type): StringField(
318-
lazy_gettext('Retry Handlers'),
319-
widget=BS3TextFieldWidget(),
320-
description="Optional. Comma separated list of import paths to zero-argument callable "
321-
"which returns retry handler for Slack WebClient.",
322-
),
323314
}
324315

325316
@classmethod
@@ -335,9 +326,5 @@ def get_ui_field_behaviour(cls) -> dict[str, Any]:
335326
prefixed_extra_field("timeout", cls.conn_type): "30",
336327
prefixed_extra_field("base_url", cls.conn_type): "https://www.slack.com/api/",
337328
prefixed_extra_field("proxy", cls.conn_type): "http://localhost:9000",
338-
prefixed_extra_field("retry_handlers", cls.conn_type): (
339-
"slack_sdk.http_retry.builtin_handlers.ConnectionErrorRetryHandler,"
340-
"slack_sdk.http_retry.builtin_handlers.RateLimitErrorRetryHandler"
341-
),
342329
},
343330
}

airflow/providers/slack/utils/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
from typing import Any
2020

21-
from airflow.utils.module_loading import import_string
22-
2321
try:
2422
from airflow.utils.types import NOTSET
2523
except ImportError: # TODO: Remove when the provider has an Airflow 2.3+ requirement.
@@ -78,22 +76,3 @@ def getint(self, field, default: Any = NOTSET) -> Any:
7876
if value != default:
7977
value = int(value)
8078
return value
81-
82-
def getimports(self, field, default: Any = NOTSET) -> Any:
83-
"""Get specified field from Connection Extra and imports the full qualified name separated by comma.
84-
85-
.. note::
86-
This method intends to use with zero-argument callable objects.
87-
88-
:param field: Connection extra field name.
89-
:param default: If specified then use as default value if field not present in Connection Extra.
90-
"""
91-
value = self.get(field=field, default=default)
92-
if value != default:
93-
if not isinstance(value, str):
94-
raise TypeError(
95-
f"Connection ({self.conn_id!r}) Extra {field!r} expected string "
96-
f"when return value not equal `default={default}`, got {type(value).__name__}."
97-
)
98-
value = [import_string(part.strip())() for part in value.split(",")]
99-
return value

docs/apache-airflow-providers-slack/connections/slack.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ Extra (optional)
5151
* ``timeout``: The maximum number of seconds the client will wait to connect and receive a response from Slack API.
5252
* ``base_url``: A string representing the Slack API base URL.
5353
* ``proxy``: Proxy to make the Slack Incoming Webhook call.
54-
* ``retry_handlers``: Comma separated list of import paths to zero-argument callable which returns retry handler
55-
for Slack WebClient.
5654

5755
If you are configuring the connection via a URI, ensure that all components of the URI are URL-encoded.
5856

tests/providers/slack/hooks/test_slack.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444
]
4545

4646

47-
def conn_error_retry_handler():
48-
return TEST_CONN_ERROR_RETRY_HANDLER
49-
50-
51-
def rate_limit_retry_handler():
52-
return TEST_RATE_LIMIT_RETRY_HANDLER
53-
54-
5547
@pytest.fixture(scope="module", autouse=True)
5648
def slack_api_connections():
5749
"""Create tests connections."""
@@ -170,16 +162,11 @@ def test_empty_password(self):
170162
"timeout": "9000",
171163
"base_url": "http://conn-base-url:4321",
172164
"proxy": "https://conn-proxy:4321",
173-
"retry_handlers": (
174-
"tests.providers.slack.hooks.test_slack.rate_limit_retry_handler,"
175-
"tests.providers.slack.hooks.test_slack.conn_error_retry_handler"
176-
),
177165
},
178166
{
179167
"timeout": 9000,
180168
"base_url": "http://conn-base-url:4321",
181169
"proxy": "https://conn-proxy:4321",
182-
"retry_handlers": [TEST_RATE_LIMIT_RETRY_HANDLER, TEST_CONN_ERROR_RETRY_HANDLER],
183170
},
184171
),
185172
( # Test Case: Connection from the UI
@@ -188,16 +175,11 @@ def test_empty_password(self):
188175
"extra__slack__timeout": 9000,
189176
"extra__slack__base_url": "http://conn-base-url:4321",
190177
"extra__slack__proxy": "https://conn-proxy:4321",
191-
"extra__slack__retry_handlers": (
192-
"tests.providers.slack.hooks.test_slack.rate_limit_retry_handler,"
193-
"tests.providers.slack.hooks.test_slack.conn_error_retry_handler"
194-
),
195178
},
196179
{
197180
"timeout": 9000,
198181
"base_url": "http://conn-base-url:4321",
199182
"proxy": "https://conn-proxy:4321",
200-
"retry_handlers": [TEST_RATE_LIMIT_RETRY_HANDLER, TEST_CONN_ERROR_RETRY_HANDLER],
201183
},
202184
),
203185
( # Test Case: Merge configs - hook args overwrite conn config
@@ -209,10 +191,6 @@ def test_empty_password(self):
209191
{
210192
"timeout": 9000,
211193
"proxy": "https://conn-proxy:4321",
212-
"retry_handlers": (
213-
"tests.providers.slack.hooks.test_slack.rate_limit_retry_handler,"
214-
"tests.providers.slack.hooks.test_slack.conn_error_retry_handler"
215-
),
216194
},
217195
{
218196
"timeout": 1,
@@ -227,12 +205,10 @@ def test_empty_password(self):
227205
{
228206
"timeout": 9000,
229207
"proxy": "https://conn-proxy:4334",
230-
"retry_handlers": ("tests.providers.slack.hooks.test_slack.conn_error_retry_handler"),
231208
},
232209
{
233210
"timeout": 1,
234211
"proxy": "https://conn-proxy:4334",
235-
"retry_handlers": [TEST_CONN_ERROR_RETRY_HANDLER],
236212
},
237213
),
238214
( # Test Case: empty configs

tests/providers/slack/utils/test_utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,3 @@ def test_get_parse_int(self):
6969
)
7070
assert extra_config.getint("int_arg_1") == 42
7171
assert extra_config.getint("int_arg_2") == 9000
72-
73-
def test_get_parse_imports(self):
74-
extra_config = ConnectionExtraConfig(
75-
conn_type="slack",
76-
extra={
77-
"imports_arg_1": "builtins.str",
78-
"imports_arg_2": "builtins.str,builtins.dict",
79-
"imports_arg_3": " builtins.str , builtins.dict ",
80-
},
81-
)
82-
assert extra_config.getimports("imports_arg_1") == ['']
83-
assert extra_config.getimports("imports_arg_2") == ['', {}]
84-
assert extra_config.getimports("imports_arg_3") == ['', {}]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy