taipanstack 0.3.8__tar.gz → 0.3.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {taipanstack-0.3.8 → taipanstack-0.3.9}/PKG-INFO +1 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/pyproject.toml +1 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/__init__.py +1 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/guards.py +13 -18
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/jwt.py +1 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/models.py +1 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/sanitizers.py +6 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/filesystem.py +6 -1
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/logging.py +13 -8
- {taipanstack-0.3.8 → taipanstack-0.3.9}/LICENSE +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/README.md +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/__init__.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/generators.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/models.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/version_config.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/__init__.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/compat.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/optimizations.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/result.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/__init__.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/decorators.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/password.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/types.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/validators.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/__init__.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/circuit_breaker.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/concurrency.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/metrics.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/rate_limit.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/retry.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/serialization.py +0 -0
- {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/subprocess.py +0 -0
|
@@ -5,7 +5,7 @@ A modular, secure, and scalable Python stack for robust development.
|
|
|
5
5
|
Supports Python 3.11+ with version-aware optimizations for 3.13/3.14.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.3.
|
|
8
|
+
__version__ = "0.3.9"
|
|
9
9
|
|
|
10
10
|
from taipanstack.config.version_config import (
|
|
11
11
|
VersionRecommendations,
|
|
@@ -85,12 +85,8 @@ _DEFAULT_DENIED_ENV_VARS = frozenset(
|
|
|
85
85
|
]
|
|
86
86
|
)
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
re.compile(r".*PASSWORD.*"),
|
|
91
|
-
re.compile(r".*TOKEN.*"),
|
|
92
|
-
re.compile(r".*PRIVATE.*KEY.*"),
|
|
93
|
-
re.compile(r".*API.*KEY.*"),
|
|
88
|
+
_SENSITIVE_ENV_VAR_PATTERN = re.compile(
|
|
89
|
+
r".*SECRET.*|.*PASSWORD.*|.*TOKEN.*|.*PRIVATE.*KEY.*|.*API.*KEY.*"
|
|
94
90
|
)
|
|
95
91
|
|
|
96
92
|
|
|
@@ -369,23 +365,22 @@ def guard_env_variable(
|
|
|
369
365
|
value=name,
|
|
370
366
|
)
|
|
371
367
|
|
|
372
|
-
|
|
373
|
-
if
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if name_upper not in allowed:
|
|
378
|
-
raise SecurityError(
|
|
379
|
-
f"Access to potentially sensitive variable '{name}' is denied",
|
|
380
|
-
guard_name="env_variable",
|
|
381
|
-
value=name,
|
|
382
|
-
)
|
|
383
|
-
else:
|
|
368
|
+
if _SENSITIVE_ENV_VAR_PATTERN.match(name_upper):
|
|
369
|
+
# Only block if not explicitly allowed
|
|
370
|
+
if allowed_names is not None:
|
|
371
|
+
allowed = {n.upper() for n in allowed_names}
|
|
372
|
+
if name_upper not in allowed:
|
|
384
373
|
raise SecurityError(
|
|
385
374
|
f"Access to potentially sensitive variable '{name}' is denied",
|
|
386
375
|
guard_name="env_variable",
|
|
387
376
|
value=name,
|
|
388
377
|
)
|
|
378
|
+
else:
|
|
379
|
+
raise SecurityError(
|
|
380
|
+
f"Access to potentially sensitive variable '{name}' is denied",
|
|
381
|
+
guard_name="env_variable",
|
|
382
|
+
value=name,
|
|
383
|
+
)
|
|
389
384
|
|
|
390
385
|
# Get the variable
|
|
391
386
|
value = os.environ.get(name)
|
|
@@ -72,7 +72,7 @@ def decode_jwt(
|
|
|
72
72
|
PyJWTError: If the token is invalid, expired, or has incorrect claims.
|
|
73
73
|
|
|
74
74
|
"""
|
|
75
|
-
if
|
|
75
|
+
if any(str(alg).strip().lower() == "none" for alg in algorithms):
|
|
76
76
|
raise ValueError('Algorithm "none" is explicitly disallowed for decoding.')
|
|
77
77
|
|
|
78
78
|
# We enforce 'exp' and 'aud' through PyJWT's options parameter
|
|
@@ -14,6 +14,7 @@ MAX_SQL_IDENTIFIER_LENGTH = 128 # pragma: no mutate
|
|
|
14
14
|
|
|
15
15
|
# Pre-compiled regex and sets for Performance Benchmarks
|
|
16
16
|
_INVALID_FILENAME_CHARS_RE = re.compile(r'[<>:"/\\|?*\x00-\x1f]') # pragma: no mutate
|
|
17
|
+
_SQL_IDENTIFIER_DENY_RE = re.compile(r"[^a-zA-Z0-9_]") # pragma: no mutate
|
|
17
18
|
_WINDOWS_RESERVED_NAMES = frozenset( # pragma: no mutate
|
|
18
19
|
{
|
|
19
20
|
"CON",
|
|
@@ -317,7 +318,11 @@ def sanitize_sql_identifier(identifier: str) -> str:
|
|
|
317
318
|
raise ValueError(msg)
|
|
318
319
|
|
|
319
320
|
# Only allow alphanumeric and underscore
|
|
320
|
-
|
|
321
|
+
# Fast path: if already clean, skip sub
|
|
322
|
+
if _SQL_IDENTIFIER_DENY_RE.search(identifier):
|
|
323
|
+
result = _SQL_IDENTIFIER_DENY_RE.sub("", identifier)
|
|
324
|
+
else:
|
|
325
|
+
result = identifier
|
|
321
326
|
|
|
322
327
|
# Must start with letter or underscore
|
|
323
328
|
if result and not (result[0].isalpha() or result[0] == "_"):
|
|
@@ -6,6 +6,7 @@ atomic writes, and proper error handling using Result types.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
import contextlib
|
|
9
|
+
import functools
|
|
9
10
|
import hashlib
|
|
10
11
|
import os
|
|
11
12
|
import shutil
|
|
@@ -362,11 +363,13 @@ def get_file_hash(
|
|
|
362
363
|
# Validate path
|
|
363
364
|
if base_dir is not None:
|
|
364
365
|
path = guard_path_traversal(path, Path(base_dir))
|
|
366
|
+
elif ".." in str(path):
|
|
367
|
+
path = guard_path_traversal(path, Path.cwd())
|
|
365
368
|
|
|
366
369
|
hasher = hashlib.new(algorithm)
|
|
367
370
|
|
|
368
371
|
with path.open("rb") as f:
|
|
369
|
-
for chunk in iter(
|
|
372
|
+
for chunk in iter(functools.partial(f.read, 8192), b""):
|
|
370
373
|
hasher.update(chunk)
|
|
371
374
|
|
|
372
375
|
return hasher.hexdigest()
|
|
@@ -398,6 +401,8 @@ def find_files(
|
|
|
398
401
|
# Validate path
|
|
399
402
|
if base_dir is not None:
|
|
400
403
|
directory = guard_path_traversal(directory, Path(base_dir))
|
|
404
|
+
elif ".." in str(directory):
|
|
405
|
+
directory = guard_path_traversal(directory, Path.cwd())
|
|
401
406
|
|
|
402
407
|
if not directory.exists():
|
|
403
408
|
return []
|
|
@@ -50,8 +50,8 @@ REDACTED_VALUE = "***REDACTED***"
|
|
|
50
50
|
def mask_sensitive_data_processor(
|
|
51
51
|
logger: Any, # noqa: ARG001
|
|
52
52
|
method: str, # noqa: ARG001
|
|
53
|
-
event_dict:
|
|
54
|
-
) ->
|
|
53
|
+
event_dict: MutableMapping[str, Any],
|
|
54
|
+
) -> MutableMapping[str, Any]:
|
|
55
55
|
"""Mask sensitive data in structlog event dictionaries.
|
|
56
56
|
|
|
57
57
|
Intercept the *event_dict* produced by structlog and replace the
|
|
@@ -59,8 +59,8 @@ def mask_sensitive_data_processor(
|
|
|
59
59
|
``"***REDACTED***"``. Matching is case-insensitive.
|
|
60
60
|
|
|
61
61
|
Args:
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
_logger: The wrapped logger object (unused, required by structlog).
|
|
63
|
+
_method: The name of the log method called (unused, required by structlog).
|
|
64
64
|
event_dict: The structured event dictionary.
|
|
65
65
|
|
|
66
66
|
Returns:
|
|
@@ -104,15 +104,15 @@ def set_correlation_id(correlation_id: str | None) -> None:
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
def correlation_id_processor(
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
_logger: Any,
|
|
108
|
+
_method: str,
|
|
109
109
|
event_dict: MutableMapping[str, Any],
|
|
110
110
|
) -> MutableMapping[str, Any]:
|
|
111
111
|
"""Structlog processor to inject correlation ID into events.
|
|
112
112
|
|
|
113
113
|
Args:
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
_logger: The wrapped logger object.
|
|
115
|
+
_method: The name of the log method called.
|
|
116
116
|
event_dict: The structured event dictionary.
|
|
117
117
|
|
|
118
118
|
Returns:
|
|
@@ -210,6 +210,10 @@ class StackLogger:
|
|
|
210
210
|
return message
|
|
211
211
|
|
|
212
212
|
context = {**self._context, **kwargs}
|
|
213
|
+
if _SENSITIVE_KEY_REGEX is not None:
|
|
214
|
+
for key in context:
|
|
215
|
+
if _SENSITIVE_KEY_REGEX.search(key):
|
|
216
|
+
context[key] = REDACTED_VALUE
|
|
213
217
|
context_str = " ".join(f"{k}={v}" for k, v in context.items())
|
|
214
218
|
return f"{message} | {context_str}"
|
|
215
219
|
|
|
@@ -317,6 +321,7 @@ def setup_logging(
|
|
|
317
321
|
structlog.stdlib.add_log_level,
|
|
318
322
|
structlog.processors.TimeStamper(fmt="iso"),
|
|
319
323
|
correlation_id_processor,
|
|
324
|
+
mask_sensitive_data_processor,
|
|
320
325
|
structlog.processors.StackInfoRenderer(),
|
|
321
326
|
structlog.processors.format_exc_info,
|
|
322
327
|
structlog.processors.UnicodeDecoder(),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|