Skip to content

Commit e7b5300

Browse files
committed
fix: enhance validation for domain id, project id, and region in ProjectContext initialization
1 parent ddd651c commit e7b5300

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

template/v2/dirs/etc/sagemaker-ui/sagemaker-mcp/smus-mcp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
import re
910
from typing import Any, Dict
1011

1112
from mcp.server.fastmcp import FastMCP
@@ -40,12 +41,12 @@ def __init__(self):
4041
except Exception as e:
4142
raise RuntimeError(f"Failed to initialize project: {e}")
4243

43-
if not self.domain_id:
44-
raise RuntimeError(f"Domain id should not be empty")
45-
if not self.project_id:
46-
raise RuntimeError(f"Project id should not be empty")
47-
if not self.region:
48-
raise RuntimeError(f"Region should not be empty")
44+
if not re.match("^dzd[-_][a-zA-Z0-9_-]{1,36}$", self.domain_id):
45+
raise RuntimeError(f"Invalid domain id")
46+
if not re.match("^[a-zA-Z0-9_-]{1,36}$", self.project_id):
47+
raise RuntimeError(f"Invalid project id")
48+
if not re.match("^[a-z]{2}-[a-z]{4,10}-\\d$", self.region):
49+
raise RuntimeError(f"Invalid region")
4950

5051

5152
def safe_get_attr(obj: Any, attr: str, default: Any = None) -> Any:

template/v3/dirs/etc/sagemaker-ui/sagemaker-mcp/smus-mcp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
import re
910
from typing import Any, Dict
1011

1112
from mcp.server.fastmcp import FastMCP
@@ -40,12 +41,12 @@ def __init__(self):
4041
except Exception as e:
4142
raise RuntimeError(f"Failed to initialize project: {e}")
4243

43-
if not self.domain_id:
44-
raise RuntimeError(f"Domain id should not be empty")
45-
if not self.project_id:
46-
raise RuntimeError(f"Project id should not be empty")
47-
if not self.region:
48-
raise RuntimeError(f"Region should not be empty")
44+
if not re.match("^dzd[-_][a-zA-Z0-9_-]{1,36}$", self.domain_id):
45+
raise RuntimeError(f"Invalid domain id")
46+
if not re.match("^[a-zA-Z0-9_-]{1,36}$", self.project_id):
47+
raise RuntimeError(f"Invalid project id")
48+
if not re.match("^[a-z]{2}-[a-z]{4,10}-\\d$", self.region):
49+
raise RuntimeError(f"Invalid region")
4950

5051

5152
def safe_get_attr(obj: Any, attr: str, default: Any = None) -> Any:

0 commit comments

Comments
 (0)