Skip to content

Commit 6e39500

Browse files
Aryamanz29claude
andcommitted
refactor: consolidate sensitive path env vars into PYATLAN_UPLOAD_FILE_BLOCKED_PATHS
Replace three separate env vars (PYATLAN_SENSITIVE_SYSTEM_PREFIXES, PYATLAN_SENSITIVE_DIR_NAMES, PYATLAN_SENSITIVE_FILE_PREFIXES) with a single PYATLAN_UPLOAD_FILE_BLOCKED_PATHS that accepts comma-separated path patterns matched as substrings against the full resolved file path. Also update the error message from "Access to sensitive" to "Access to blocked". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 393aad1 commit 6e39500

3 files changed

Lines changed: 29 additions & 31 deletions

File tree

pyatlan/client/common/file.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any
66

77
# System directories that must never be read from.
8-
# Extend via PYATLAN_SENSITIVE_SYSTEM_PREFIXES (comma-separated paths, e.g. "/vault/,/secrets/")
98
_SENSITIVE_SYSTEM_PREFIXES = (
109
"/etc/",
1110
"/proc/",
@@ -17,11 +16,9 @@
1716
)
1817

1918
# Hidden credential/config directories that must never be read from.
20-
# Extend via PYATLAN_SENSITIVE_DIR_NAMES (comma-separated names, e.g. ".vault,.myconfig")
2119
_SENSITIVE_DIR_NAMES = frozenset({".aws", ".ssh", ".gnupg"})
2220

2321
# File name prefixes for environment/secret files.
24-
# Extend via PYATLAN_SENSITIVE_FILE_PREFIXES (comma-separated prefixes, e.g. ".secrets,.credentials")
2522
_SENSITIVE_FILE_PREFIXES = (".env",)
2623

2724

@@ -96,30 +93,31 @@ def validate_file_path(file_path: str) -> Any:
9693
resolved = path.resolve()
9794
resolved_str = str(resolved)
9895

99-
system_prefixes = _SENSITIVE_SYSTEM_PREFIXES + tuple(
100-
_parse_env_list("PYATLAN_SENSITIVE_SYSTEM_PREFIXES")
101-
)
102-
dir_names = _SENSITIVE_DIR_NAMES | frozenset(
103-
_parse_env_list("PYATLAN_SENSITIVE_DIR_NAMES")
104-
)
105-
file_prefixes = _SENSITIVE_FILE_PREFIXES + tuple(
106-
_parse_env_list("PYATLAN_SENSITIVE_FILE_PREFIXES")
107-
)
108-
10996
# Block sensitive system directories (e.g. /etc/, /proc/, /dev/)
110-
if resolved_str.startswith(system_prefixes):
97+
if resolved_str.startswith(_SENSITIVE_SYSTEM_PREFIXES):
11198
raise ErrorCode.INVALID_UPLOAD_FILE_PATH_SENSITIVE.exception_with_parameters(
11299
file_path
113100
)
114101

115102
# Block credential/config hidden directories (e.g. .aws, .ssh, .gnupg)
116-
if any(part in dir_names for part in resolved.parts):
103+
if any(part in _SENSITIVE_DIR_NAMES for part in resolved.parts):
117104
raise ErrorCode.INVALID_UPLOAD_FILE_PATH_SENSITIVE.exception_with_parameters(
118105
file_path
119106
)
120107

121108
# Block environment/secret files (e.g. .env, .env.local, .env.production)
122-
if resolved.name.startswith(file_prefixes):
109+
if resolved.name.startswith(_SENSITIVE_FILE_PREFIXES):
110+
raise ErrorCode.INVALID_UPLOAD_FILE_PATH_SENSITIVE.exception_with_parameters(
111+
file_path
112+
)
113+
114+
# Block user-defined paths via PYATLAN_UPLOAD_FILE_BLOCKED_PATHS (comma-separated).
115+
# Each entry is matched as a substring against the full resolved path, so it
116+
# can express system prefixes ("/vault/"), dir names (".vault"), or
117+
# file prefixes (".credentials").
118+
# e.g. PYATLAN_UPLOAD_FILE_BLOCKED_PATHS="/custom/secrets/,.vault,.credentials"
119+
user_blocked = _parse_env_list("PYATLAN_UPLOAD_FILE_BLOCKED_PATHS")
120+
if any(pattern in resolved_str for pattern in user_blocked):
123121
raise ErrorCode.INVALID_UPLOAD_FILE_PATH_SENSITIVE.exception_with_parameters(
124122
file_path
125123
)

pyatlan/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ class ErrorCode(Enum):
685685
INVALID_UPLOAD_FILE_PATH_SENSITIVE = (
686686
400,
687687
"ATLAN-PYTHON-400-078",
688-
"Access to sensitive file path is not allowed: {0}.",
689-
"Ensure the file path does not point to sensitive system files or credential directories.",
688+
"Access to blocked file path is not allowed: {0}.",
689+
"Ensure the file path does not point to a blocked location (system files, credential directories, or paths defined in PYATLAN_UPLOAD_FILE_BLOCKED_PATHS).",
690690
InvalidRequestError,
691691
)
692692
AUTHENTICATION_PASSTHROUGH = (

tests/unit/test_file_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,29 @@ def test_file_client_methods_validation_error(client, method, params):
172172
# Sensitive system files
173173
[
174174
"/etc/passwd",
175-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
175+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
176176
],
177177
[
178178
"/etc/shadow",
179-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
179+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
180180
],
181181
# Credential directories
182182
[
183183
"/home/user/.aws/credentials",
184-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
184+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
185185
],
186186
[
187187
"/home/user/.ssh/id_rsa",
188-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
188+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
189189
],
190190
# Environment files
191191
[
192192
"/app/.env",
193-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
193+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
194194
],
195195
[
196196
"/app/.env.production",
197-
"ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
197+
"ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
198198
],
199199
],
200200
)
@@ -211,21 +211,21 @@ def test_file_client_upload_file_raises_invalid_request_error(
211211

212212

213213
@pytest.mark.parametrize(
214-
"env_var, env_value, file_path",
214+
"env_value, file_path",
215215
[
216-
("PYATLAN_SENSITIVE_SYSTEM_PREFIXES", "/custom/secrets/", "/custom/secrets/key"),
217-
("PYATLAN_SENSITIVE_DIR_NAMES", ".vault", "/home/user/.vault/token"),
218-
("PYATLAN_SENSITIVE_FILE_PREFIXES", ".credentials", "/app/.credentials.prod"),
216+
("/custom/secrets/", "/custom/secrets/key"),
217+
(".vault", "/home/user/.vault/token"),
218+
(".credentials", "/app/.credentials.prod"),
219219
],
220220
)
221221
def test_file_client_upload_file_user_defined_sensitive_paths(
222-
monkeypatch, mock_api_caller, env_var, env_value, file_path
222+
monkeypatch, mock_api_caller, env_value, file_path
223223
):
224-
monkeypatch.setenv(env_var, env_value)
224+
monkeypatch.setenv("PYATLAN_UPLOAD_FILE_BLOCKED_PATHS", env_value)
225225
client = FileClient(client=mock_api_caller)
226226
with pytest.raises(
227227
InvalidRequestError,
228-
match="ATLAN-PYTHON-400-078 Access to sensitive file path is not allowed",
228+
match="ATLAN-PYTHON-400-078 Access to blocked file path is not allowed",
229229
):
230230
client.upload_file(presigned_url="test-url", file_path=file_path)
231231

0 commit comments

Comments
 (0)