From 7c52da4bf68a0d4fe81bd547dcde384bb0085b4c Mon Sep 17 00:00:00 2001 From: mkzung <103102868+mkzung@users.noreply.github.com> Date: Mon, 9 Nov 2026 08:25:30 +0000 Subject: [PATCH 1/2] fix: encode ASM tag names in delete requests --- censys/asm/assets/assets.py | 4 +++- tests/asm/test_assets.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/censys/asm/assets/assets.py b/censys/asm/assets/assets.py index 25c8d588..28a25bfc 100644 --- a/censys/asm/assets/assets.py +++ b/censys/asm/assets/assets.py @@ -3,6 +3,7 @@ import re from collections.abc import Iterator from typing import Any, Optional +from urllib.parse import quote from censys.common.exceptions import CensysInvalidColorException @@ -175,7 +176,8 @@ def delete_tag(self, asset_id: str, name: str) -> dict: Returns: dict: Deleted tag results. """ - path = f"{self.base_path}/{self._format_asset_id(asset_id)}/tags/{name}" + escaped_name = quote(name, safe="") + path = f"{self.base_path}/{self._format_asset_id(asset_id)}/tags/{escaped_name}" return self._delete(path) diff --git a/tests/asm/test_assets.py b/tests/asm/test_assets.py index 69dc11e3..193907cb 100644 --- a/tests/asm/test_assets.py +++ b/tests/asm/test_assets.py @@ -1,6 +1,7 @@ from urllib.parse import quote import pytest +import responses from pytest_mock import MockerFixture from censys.asm.client import AsmClient @@ -272,6 +273,26 @@ def test_delete_tag(self): timeout=TEST_TIMEOUT, ) + @pytest.mark.parametrize( + ("name", "encoded"), + [ + (TEST_TAG_NAME, TEST_TAG_NAME), + ("\u00e9quipe", "%C3%A9quipe"), + ("team#1", "team%231"), + ("team?env=prod", "team%3Fenv%3Dprod"), + ("team/infra", "team%2Finfra"), + ("team%2F1", "team%252F1"), + ], + ) + def test_delete_tag_preserves_name(self, name, encoded): + with responses.RequestsMock() as rsps: + rsps.delete( + f"{self.asset_id_url()}/tags/{encoded}", + json={"name": name}, + match=[responses.matchers.query_param_matcher({})], + ) + assert self.get_asset_accessor().delete_tag(self.test_asset_id, name) == {"name": name} + def test_get_subdomains(self): # Mock mock_request = self.mocker.patch("censys.common.base.requests.Session.get") From 4cc37a36354d97daaa512d950bc2fa5b83d70699 Mon Sep 17 00:00:00 2001 From: mkzung <103102868+mkzung@users.noreply.github.com> Date: Mon, 9 Nov 2026 08:31:21 +0000 Subject: [PATCH 2/2] fix: reject dot-segment tag names before deletion --- censys/asm/assets/assets.py | 5 +++++ tests/asm/test_assets.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/censys/asm/assets/assets.py b/censys/asm/assets/assets.py index 28a25bfc..8fda10fb 100644 --- a/censys/asm/assets/assets.py +++ b/censys/asm/assets/assets.py @@ -173,9 +173,14 @@ def delete_tag(self, asset_id: str, name: str) -> dict: asset_id (str): Asset ID to delete tag from. name (str): Tag name to delete. + Raises: + ValueError: If name is a URL dot segment ("." or ".."). + Returns: dict: Deleted tag results. """ + if name in (".", ".."): + raise ValueError('Tag name cannot be a URL dot segment ("." or "..").') escaped_name = quote(name, safe="") path = f"{self.base_path}/{self._format_asset_id(asset_id)}/tags/{escaped_name}" diff --git a/tests/asm/test_assets.py b/tests/asm/test_assets.py index 193907cb..bee1c49f 100644 --- a/tests/asm/test_assets.py +++ b/tests/asm/test_assets.py @@ -293,6 +293,15 @@ def test_delete_tag_preserves_name(self, name, encoded): ) assert self.get_asset_accessor().delete_tag(self.test_asset_id, name) == {"name": name} + @pytest.mark.parametrize("name", [".", ".."]) + def test_delete_tag_rejects_dot_segments(self, name): + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: + rsps.delete(f"{self.asset_id_url()}/tags/", json={}) + rsps.delete(f"{self.asset_id_url()}/", json={}) + with pytest.raises(ValueError, match="Tag name cannot be a URL dot segment"): + self.get_asset_accessor().delete_tag(self.test_asset_id, name) + assert not rsps.calls + def test_get_subdomains(self): # Mock mock_request = self.mocker.patch("censys.common.base.requests.Session.get")