pywebguard 1.0.44__tar.gz → 1.0.45__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 (69) hide show
  1. {pywebguard-1.0.44 → pywebguard-1.0.45}/PKG-INFO +1 -1
  2. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/core/config.py +30 -0
  3. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/PKG-INFO +1 -1
  4. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_core.py +28 -0
  5. {pywebguard-1.0.44 → pywebguard-1.0.45}/LICENSE +0 -0
  6. {pywebguard-1.0.44 → pywebguard-1.0.45}/README.md +0 -0
  7. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/__init__.py +0 -0
  8. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/cli.py +0 -0
  9. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/core/__init__.py +0 -0
  10. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/core/base.py +0 -0
  11. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/core/constants.py +0 -0
  12. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/filters/__init__.py +0 -0
  13. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/filters/base.py +0 -0
  14. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/filters/ip_filter.py +0 -0
  15. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/filters/user_agent.py +0 -0
  16. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/frameworks/__init__.py +0 -0
  17. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/frameworks/_fastapi.py +0 -0
  18. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/frameworks/_flask.py +0 -0
  19. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/limiters/__init__.py +0 -0
  20. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/limiters/base.py +0 -0
  21. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/limiters/rate_limit.py +0 -0
  22. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/__init__.py +0 -0
  23. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/backends/__init__.py +0 -0
  24. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/backends/_elasticsearch.py +0 -0
  25. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/backends/_meilisearch.py +0 -0
  26. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/backends/_mongodb.py +0 -0
  27. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/base.py +0 -0
  28. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/logging/logger.py +0 -0
  29. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/security/__init__.py +0 -0
  30. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/security/base.py +0 -0
  31. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/security/cors.py +0 -0
  32. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/security/penetration.py +0 -0
  33. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/__init__.py +0 -0
  34. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/_mongodb.py +0 -0
  35. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/_postgresql.py +0 -0
  36. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/_redis.py +0 -0
  37. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/_sqlite.py +0 -0
  38. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/_tinydb.py +0 -0
  39. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/base.py +0 -0
  40. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/storage/memory.py +0 -0
  41. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/utils/__init__.py +0 -0
  42. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/utils/ip.py +0 -0
  43. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/utils/request.py +0 -0
  44. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard/utils/setup.py +0 -0
  45. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/SOURCES.txt +0 -0
  46. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/dependency_links.txt +0 -0
  47. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/entry_points.txt +0 -0
  48. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/requires.txt +0 -0
  49. {pywebguard-1.0.44 → pywebguard-1.0.45}/pywebguard.egg-info/top_level.txt +0 -0
  50. {pywebguard-1.0.44 → pywebguard-1.0.45}/setup.cfg +0 -0
  51. {pywebguard-1.0.44 → pywebguard-1.0.45}/setup.py +0 -0
  52. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_cli.py +0 -0
  53. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_filters.py +0 -0
  54. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_frameworks.py +0 -0
  55. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_frameworks_fastapi.py +0 -0
  56. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_frameworks_flask.py +0 -0
  57. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_limiters.py +0 -0
  58. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_security.py +0 -0
  59. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_setup_api.py +0 -0
  60. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage.py +0 -0
  61. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_memory.py +0 -0
  62. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_mongodb.py +0 -0
  63. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_postgresql.py +0 -0
  64. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_redis.py +0 -0
  65. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_sqlite.py +0 -0
  66. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_storage_tinydb.py +0 -0
  67. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_user_agent.py +0 -0
  68. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_utils_ip.py +0 -0
  69. {pywebguard-1.0.44 → pywebguard-1.0.45}/tests/test_utils_request.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywebguard
3
- Version: 1.0.44
3
+ Version: 1.0.45
4
4
  Summary: A comprehensive security library for Python web applications
5
5
  Home-page: https://github.com/py-daily/pywebguard
6
6
  Author: py-daily
@@ -131,6 +131,36 @@ class CORSConfig(BaseModel):
131
131
  allow_credentials: bool = False
132
132
  max_age: int = Field(default=600, ge=0)
133
133
 
134
+ @field_validator("allow_credentials")
135
+ def validate_credentials_origin_combination(
136
+ cls, v: bool, info: ValidationInfo
137
+ ) -> bool:
138
+ """Reject allow_credentials=True paired with the default wildcard allow_origins.
139
+
140
+ Browsers unconditionally reject a response carrying both
141
+ `Access-Control-Allow-Origin: *` and `Access-Control-Allow-Credentials: true`,
142
+ so a config that would produce that combination fails fast here instead of
143
+ silently failing client-side.
144
+
145
+ Args:
146
+ v: The allow_credentials value being validated
147
+ info: Validation context, used to read the already-validated allow_origins
148
+
149
+ Returns:
150
+ The validated allow_credentials value
151
+
152
+ Raises:
153
+ ValueError: If allow_credentials is True while allow_origins is still the
154
+ default wildcard ["*"]
155
+ """
156
+ if v and info.data.get("allow_origins") == ["*"]:
157
+ raise ValueError(
158
+ "allow_credentials=True cannot be combined with the default wildcard "
159
+ "allow_origins=['*']: browsers reject that combination outright. Set "
160
+ "allow_origins to your actual origin(s) when allow_credentials=True."
161
+ )
162
+ return v
163
+
134
164
 
135
165
  class LoggingConfig(BaseModel):
136
166
  """Configuration for logging.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywebguard
3
- Version: 1.0.44
3
+ Version: 1.0.45
4
4
  Summary: A comprehensive security library for Python web applications
5
5
  Home-page: https://github.com/py-daily/pywebguard
6
6
  Author: py-daily
@@ -5,12 +5,15 @@ from datetime import datetime
5
5
  from typing import Dict, Any, cast
6
6
  from unittest.mock import MagicMock, patch
7
7
 
8
+ from pydantic import ValidationError
9
+
8
10
  from pywebguard.core.base import Guard, AsyncGuard
9
11
  from pywebguard.core.config import (
10
12
  GuardConfig,
11
13
  IPFilterConfig,
12
14
  RateLimitConfig,
13
15
  StorageConfig,
16
+ CORSConfig,
14
17
  )
15
18
  from pywebguard.storage._redis import REDIS_AVAILABLE, RedisStorage, AsyncRedisStorage
16
19
  from pywebguard.storage._sqlite import (
@@ -545,3 +548,28 @@ async def test_async_guard_auto_creates_postgresql_storage():
545
548
  assert isinstance(guard.storage, AsyncPostgreSQLStorage)
546
549
  assert guard.storage.table_name == "custom_table"
547
550
  assert guard.storage.ttl == 120
551
+
552
+
553
+ def test_cors_config_rejects_credentials_with_default_wildcard_origin():
554
+ """CORSConfig should raise when allow_credentials=True keeps allow_origins at the
555
+ default ["*"] — browsers reject that header combination outright."""
556
+ with pytest.raises(ValidationError, match="allow_credentials"):
557
+ CORSConfig(allow_credentials=True)
558
+
559
+
560
+ def test_cors_config_allows_credentials_with_explicit_origins():
561
+ """CORSConfig should accept allow_credentials=True once allow_origins is overridden
562
+ to an explicit, non-wildcard list."""
563
+ config = CORSConfig(allow_credentials=True, allow_origins=["https://example.com"])
564
+
565
+ assert config.allow_credentials is True
566
+ assert config.allow_origins == ["https://example.com"]
567
+
568
+
569
+ def test_cors_config_default_without_credentials_is_unaffected():
570
+ """The default CORSConfig (allow_credentials=False, allow_origins=["*"]) should
571
+ continue to construct without error."""
572
+ config = CORSConfig()
573
+
574
+ assert config.allow_credentials is False
575
+ assert config.allow_origins == ["*"]
File without changes
File without changes
File without changes
File without changes