Skip to content

Commit 183dd58

Browse files
committed
MP-432 fix settings
1 parent e76679f commit 183dd58

File tree

4 files changed

+69
-47
lines changed

4 files changed

+69
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ These are the settings that can be customized for the middleware:
119119
- `LOG_MAX_DEPTH`: Maximum depth for data to be logged. Default is `4`.
120120

121121
Note:
122-
- All settings are imported from `django_google_structured_logger.settings`.
122+
- All settings are imported from `django_google_structured_logger.constants`.
123123

124124

125125
### Other Notes:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
DEFAULT_SENSITIVE_KEYS = [
2+
"^password$",
3+
".*secret.*",
4+
".*token.*",
5+
".*key.*",
6+
".*pass.*",
7+
".*auth.*",
8+
"^Bearer.*",
9+
".*ssn.*", # Social Security Number (or equivalent in some countries)
10+
".*credit.*card.*", # Credit card numbers
11+
".*cvv.*", # CVV code for credit cards
12+
".*dob.*", # Date of Birth
13+
".*pin.*", # Personal Identification Numbers
14+
".*salt.*", # Salts used in cryptography
15+
".*encrypt.*", # Encryption keys or related values
16+
".*api.*", # API keys
17+
".*jwt.*", # JSON Web Tokens
18+
".*session.*id.*", # Session Identifiers
19+
"^Authorization$", # Authorization headers
20+
".*user.*name.*", # Usernames (can sometimes be used in combination with other data for malicious purposes)
21+
".*address.*", # Physical or email addresses
22+
".*phone.*", # Phone numbers
23+
"^otp.*", # One-Time Passwords or related values
24+
]
25+
26+
DEFAULT_SENSITIVE_HEADERS = [
27+
"Authorization", # Tokens and credentials
28+
"Cookie", # User session identifiers
29+
"Set-Cookie", # Server set session identifiers
30+
"X-API-Key", # API keys
31+
"X-CSRFToken", # CSRF tokens
32+
"Proxy-Authorization", # Credentials for a proxy connection
33+
"If-None-Match", # Can be used for cache fingerprinting
34+
"Server", # Can reveal specifics about the server
35+
"WWW-Authenticate", # Authentication method details
36+
"X-Correlation-ID", # Correlation IDs for logging
37+
"X-Frame-Options", # Security-related header
38+
"Strict-Transport-Security", # Security-related header
39+
"X-XSS-Protection", # Security-related header
40+
"X-Content-Type-Options", # Security-related header
41+
"X-Download-Options", # Security-related header
42+
"X-Permitted-Cross-Domain-Policies", # Security-related header
43+
]
Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,14 @@
11
from django.conf import settings
22

3-
DEFAULT_SENSITIVE_KEYS = [
4-
"^password$",
5-
".*secret.*",
6-
".*token.*",
7-
".*key.*",
8-
".*pass.*",
9-
".*auth.*",
10-
"^Bearer.*",
11-
".*ssn.*", # Social Security Number (or equivalent in some countries)
12-
".*credit.*card.*", # Credit card numbers
13-
".*cvv.*", # CVV code for credit cards
14-
".*dob.*", # Date of Birth
15-
".*pin.*", # Personal Identification Numbers
16-
".*salt.*", # Salts used in cryptography
17-
".*encrypt.*", # Encryption keys or related values
18-
".*api.*", # API keys
19-
".*jwt.*", # JSON Web Tokens
20-
".*session.*id.*", # Session Identifiers
21-
"^Authorization$", # Authorization headers
22-
".*user.*name.*", # Usernames (can sometimes be used in combination with other data for malicious purposes)
23-
".*address.*", # Physical or email addresses
24-
".*phone.*", # Phone numbers
25-
"^otp.*", # One-Time Passwords or related values
26-
]
27-
28-
DEFAULT_SENSITIVE_HEADERS = [
29-
"Authorization", # Tokens and credentials
30-
"Cookie", # User session identifiers
31-
"Set-Cookie", # Server set session identifiers
32-
"X-API-Key", # API keys
33-
"X-CSRFToken", # CSRF tokens
34-
"Proxy-Authorization", # Credentials for a proxy connection
35-
"If-None-Match", # Can be used for cache fingerprinting
36-
"Server", # Can reveal specifics about the server
37-
"WWW-Authenticate", # Authentication method details
38-
"X-Correlation-ID", # Correlation IDs for logging
39-
"X-Frame-Options", # Security-related header
40-
"Strict-Transport-Security", # Security-related header
41-
"X-XSS-Protection", # Security-related header
42-
"X-Content-Type-Options", # Security-related header
43-
"X-Download-Options", # Security-related header
44-
"X-Permitted-Cross-Domain-Policies", # Security-related header
45-
]
3+
from django_google_structured_logger.constants import DEFAULT_SENSITIVE_HEADERS, DEFAULT_SENSITIVE_KEYS
464

475
LOG_MAX_STR_LEN = getattr(settings, "LOG_MAX_STR_LEN", 200)
486
LOG_MAX_LIST_LEN = getattr(settings, "LOG_MAX_LIST_LEN", 10)
497
LOG_EXCLUDED_ENDPOINTS = getattr(settings, "LOG_EXCLUDED_ENDPOINTS", [])
508
LOG_SENSITIVE_KEYS = getattr(settings, "LOG_SENSITIVE_KEYS", DEFAULT_SENSITIVE_KEYS)
519
LOG_MASK_STYLE = getattr(settings, "LOG_MASK_STYLE", "partial")
5210
LOG_MIDDLEWARE_ENABLED = getattr(settings, "LOG_MIDDLEWARE_ENABLED", True)
53-
LOG_EXCLUDED_HEADERS = getattr(
54-
settings, "LOG_EXCLUDED_HEADERS", DEFAULT_SENSITIVE_HEADERS
55-
)
11+
LOG_EXCLUDED_HEADERS = getattr(settings, "LOG_EXCLUDED_HEADERS", DEFAULT_SENSITIVE_HEADERS)
5612
LOG_USER_ID_FIELD = getattr(settings, "LOG_USER_ID_FIELD", "id")
5713
LOG_USER_DISPLAY_FIELD = getattr(settings, "LOG_USER_DISPLAY_FIELD", "email")
5814
LOG_MAX_DEPTH = getattr(settings, "LOG_MAX_DEPTH", 4)

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,26 @@ pretty = true
3232
profile = "black"
3333
line_length = 120
3434
skip_glob = ["**/migrations/*.py"]
35+
36+
[tool.black]
37+
line-length = 120
38+
target-version = ['py38']
39+
exclude = '''
40+
(
41+
/(
42+
\.eggs # exclude a few common directories in the
43+
| \.git # root of the project
44+
| \.hg
45+
| \.mypy_cache
46+
| \.tox
47+
| \.venv
48+
| _build
49+
| buck-out
50+
| build
51+
| dist
52+
| venv
53+
| migrations
54+
| \.exports
55+
)/
56+
)
57+
'''

0 commit comments

Comments
 (0)