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.
Files changed (32) hide show
  1. {taipanstack-0.3.8 → taipanstack-0.3.9}/PKG-INFO +1 -1
  2. {taipanstack-0.3.8 → taipanstack-0.3.9}/pyproject.toml +1 -1
  3. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/__init__.py +1 -1
  4. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/guards.py +13 -18
  5. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/jwt.py +1 -1
  6. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/models.py +1 -1
  7. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/sanitizers.py +6 -1
  8. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/filesystem.py +6 -1
  9. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/logging.py +13 -8
  10. {taipanstack-0.3.8 → taipanstack-0.3.9}/LICENSE +0 -0
  11. {taipanstack-0.3.8 → taipanstack-0.3.9}/README.md +0 -0
  12. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/__init__.py +0 -0
  13. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/generators.py +0 -0
  14. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/models.py +0 -0
  15. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/config/version_config.py +0 -0
  16. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/__init__.py +0 -0
  17. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/compat.py +0 -0
  18. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/optimizations.py +0 -0
  19. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/core/result.py +0 -0
  20. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/__init__.py +0 -0
  21. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/decorators.py +0 -0
  22. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/password.py +0 -0
  23. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/types.py +0 -0
  24. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/security/validators.py +0 -0
  25. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/__init__.py +0 -0
  26. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/circuit_breaker.py +0 -0
  27. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/concurrency.py +0 -0
  28. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/metrics.py +0 -0
  29. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/rate_limit.py +0 -0
  30. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/retry.py +0 -0
  31. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/serialization.py +0 -0
  32. {taipanstack-0.3.8 → taipanstack-0.3.9}/src/taipanstack/utils/subprocess.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taipanstack
3
- Version: 0.3.8
3
+ Version: 0.3.9
4
4
  Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "taipanstack"
3
- version = "0.3.8"
3
+ version = "0.3.9"
4
4
  description = "TaipanStack - Modular, secure, and scalable Python stack for robust development"
5
5
  authors = [
6
6
  {name = "gabrielima7", email = "gabrielima.alu.lmb@gmail.com"}
@@ -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"
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
- _SENSITIVE_ENV_VAR_PATTERNS = (
89
- re.compile(r".*SECRET.*"),
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
- for pattern in _SENSITIVE_ENV_VAR_PATTERNS:
373
- if pattern.match(name_upper):
374
- # Only block if not explicitly allowed
375
- if allowed_names is not None:
376
- allowed = {n.upper() for n in allowed_names}
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 "none" in [str(alg).strip().lower() for alg in algorithms]:
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
@@ -30,7 +30,7 @@ def _mask_data(data: Any) -> Any:
30
30
  else:
31
31
  masked[k] = _mask_data(v)
32
32
  return masked
33
- elif isinstance(data, list):
33
+ if isinstance(data, list):
34
34
  return [_mask_data(item) for item in data]
35
35
  return data
36
36
 
@@ -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
- result = re.sub(r"[^a-zA-Z0-9_]", "", identifier)
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(lambda: f.read(8192), b""):
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: dict[str, Any],
54
- ) -> dict[str, Any]:
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
- logger: The wrapped logger object (unused, required by structlog).
63
- method: The name of the log method called (unused, required by structlog).
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
- logger: Any, # noqa: ARG001
108
- method: str, # noqa: ARG001
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
- logger: The wrapped logger object.
115
- method: The name of the log method called.
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