Skip to content

Commit 8c441c4

Browse files
Copilotslister1001
andcommitted
Add version validation to prevent unauthorized SDK usage
Added validation checks in UserAgentPolicy and SDK-specific user agent modules to ensure VERSION is never empty, None, or whitespace-only, which would indicate improperly configured or unauthorized SDK usage. Co-authored-by: slister1001 <[email protected]>
1 parent 3e1301e commit 8c441c4

File tree

8 files changed

+33
-0
lines changed

8 files changed

+33
-0
lines changed

sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66

77
from ._version import VERSION
88

9+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
10+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
11+
raise ValueError("Invalid SDK version: version must be a non-empty string")
12+
913
USER_AGENT = "python-appconfiguration-provider/{}".format(VERSION)

sdk/containerregistry/azure-containerregistry/azure/containerregistry/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66

77
from ._version import VERSION
88

9+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
10+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
11+
raise ValueError("Invalid SDK version: version must be a non-empty string")
12+
913
USER_AGENT = f"azure-containerregistry/{VERSION}"

sdk/core/azure-core/azure/core/pipeline/policies/_universal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ def __init__(self, base_user_agent: Optional[str] = None, **kwargs: Any) -> None
207207
self.overwrite: bool = kwargs.pop("user_agent_overwrite", False)
208208
self.use_env: bool = kwargs.pop("user_agent_use_env", True)
209209
application_id: Optional[str] = kwargs.pop("user_agent", None)
210+
211+
# Validate that azcore_version is not empty or None to prevent unauthorized SDK usage
212+
if not azcore_version or not isinstance(azcore_version, str) or not azcore_version.strip():
213+
raise ValueError("Invalid SDK version: version must be a non-empty string")
214+
210215
sdk_moniker: str = kwargs.pop("sdk_moniker", "core/{}".format(azcore_version))
211216

212217
if base_user_agent:

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
from azure.ai.evaluation._version import VERSION
88

9+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
10+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
11+
raise ValueError("Invalid SDK version: version must be a non-empty string")
12+
913

1014
class UserAgentSingleton:
1115
__BASE_USER_AGENT: str = "{}/{}".format("azure-ai-evaluation", VERSION)

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55

66
from ._version import VERSION
77

8+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
9+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
10+
raise ValueError("Invalid SDK version: version must be a non-empty string")
11+
812
USER_AGENT = f"ai-formrecognizer/{VERSION}"

sdk/identity/azure-identity/azure/identity/_internal/user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66

77
from .._version import VERSION
88

9+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
10+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
11+
raise ValueError("Invalid SDK version: version must be a non-empty string")
12+
913
USER_AGENT = "azsdk-python-identity/{} Python/{} ({})".format(VERSION, platform.python_version(), platform.platform())

sdk/ml/azure-ai-ml/azure/ai/ml/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
# ---------------------------------------------------------
44
from azure.ai.ml._version import VERSION
55

6+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
7+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
8+
raise ValueError("Invalid SDK version: version must be a non-empty string")
9+
610
USER_AGENT = "{}/{}".format("azure-ai-ml", VERSION)

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_user_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55

66
from ._version import VERSION
77

8+
# Validate that VERSION is not empty or None to prevent unauthorized SDK usage
9+
if not VERSION or not isinstance(VERSION, str) or not VERSION.strip():
10+
raise ValueError("Invalid SDK version: version must be a non-empty string")
11+
812
USER_AGENT = f"ai-textanalytics/{VERSION}"

0 commit comments

Comments
 (0)