Skip to content

Commit 2a79e23

Browse files
authored
fix(risks): perform URL path escaping on risk-types before using as input (#687)
* fix(risks): perform URL path escaping on risk-types before using as input * build: bump to 2.2.17
1 parent bbb0c86 commit 2a79e23

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

censys/asm/risks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Interact with the Censys Risks API."""
22

3+
import urllib.parse
34
from typing import Any, Dict, List, Optional
45

56
from .api import CensysAsmAPI
@@ -168,8 +169,9 @@ def get_risk_type(
168169
Returns:
169170
dict: Risk type result.
170171
"""
172+
escaped_risk_type = urllib.parse.quote(risk_type, safe="")
171173
args = {"includeEvents": include_events}
172-
return self._get(f"{self.risk_types_path}/{risk_type}", args=args)
174+
return self._get(f"{self.risk_types_path}/{escaped_risk_type}", args=args)
173175

174176
def patch_risk_type(self, risk_type: str, data: dict) -> dict:
175177
"""Patch a risk type.
@@ -181,4 +183,5 @@ def patch_risk_type(self, risk_type: str, data: dict) -> dict:
181183
Returns:
182184
dict: Risk type result.
183185
"""
184-
return self._patch(f"{self.risk_types_path}/{risk_type}", data=data)
186+
escaped_risk_type = urllib.parse.quote(risk_type, safe="")
187+
return self._patch(f"{self.risk_types_path}/{escaped_risk_type}", data=data)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "censys"
3-
version = "2.2.16"
3+
version = "2.2.17"
44
description = "An easy-to-use and lightweight API wrapper for Censys APIs (censys.io)."
55
authors = ["Censys, Inc. <[email protected]>"]
66
license = "Apache-2.0"

tests/asm/test_risks.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import urllib.parse
2+
13
import responses
24
from parameterized import parameterized
35
from responses import matchers
@@ -38,7 +40,8 @@
3840
"skips": 0,
3941
"userStatusChanges": 0,
4042
}
41-
TEST_RISK_TYPE = "service.authentication.http_weak_auth.http_weak_auth_encrypted"
43+
TEST_RISK_TYPE = "service.authentication.http_weak_auth/after-slash"
44+
ESCAPED_TEST_RISK_TYPE = urllib.parse.quote(TEST_RISK_TYPE, safe="")
4245
TEST_RISK_TYPE_JSON = {
4346
"config": "string",
4447
"contextType": "string",
@@ -236,14 +239,14 @@ def test_get_risk_types(self, kwargs, params):
236239

237240
@parameterized.expand(
238241
[
239-
({"risk_type": TEST_RISK_TYPE}, TEST_RISK_TYPE),
242+
({"risk_type": TEST_RISK_TYPE}, ESCAPED_TEST_RISK_TYPE),
240243
(
241244
{"risk_type": TEST_RISK_TYPE, "include_events": True},
242-
TEST_RISK_TYPE + "?includeEvents=True",
245+
ESCAPED_TEST_RISK_TYPE + "?includeEvents=True",
243246
),
244247
(
245248
{"risk_type": TEST_RISK_TYPE, "include_events": False},
246-
TEST_RISK_TYPE + "?includeEvents=False",
249+
ESCAPED_TEST_RISK_TYPE + "?includeEvents=False",
247250
),
248251
]
249252
)
@@ -270,7 +273,7 @@ def test_patch_risk_type(self):
270273
)
271274
self.responses.add(
272275
responses.PATCH,
273-
V2_URL + f"/risk-types/{TEST_RISK_TYPE}",
276+
V2_URL + f"/risk-types/{ESCAPED_TEST_RISK_TYPE}",
274277
status=200,
275278
json=TEST_PATCH_RISK_TYPE_JSON,
276279
match=[matchers.json_params_matcher(mock_patch)],

0 commit comments

Comments
 (0)