syncforge 1.0.2__tar.gz → 1.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncforge
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Official Python SDK for SyncForge — control exactly when data syncs between your database and clients.
5
5
  Author-email: SyncForge <sureshdulupolai@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "syncforge"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "Official Python SDK for SyncForge — control exactly when data syncs between your database and clients."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -0,0 +1,86 @@
1
+ """
2
+ SyncForge Security Middleware
3
+ Professional-grade request/response logging and basic WAF protection for Django apps.
4
+ """
5
+ import time
6
+ import logging
7
+
8
+ try:
9
+ from django.http import HttpResponseForbidden
10
+ from django.utils.deprecation import MiddlewareMixin
11
+ HAS_DJANGO = True
12
+ except ImportError:
13
+ HAS_DJANGO = False
14
+ class MiddlewareMixin:
15
+ pass
16
+
17
+ logger = logging.getLogger('syncforge.security')
18
+
19
+ class SyncForgeSecurityMiddleware(MiddlewareMixin):
20
+ """
21
+ Drop-in security and logging middleware.
22
+ Add 'syncforge.middleware.SyncForgeSecurityMiddleware' to your MIDDLEWARE setting.
23
+ """
24
+
25
+ # Common malicious patterns to block automatically
26
+ MALICIOUS_PATTERNS = [
27
+ '../', # Path Traversal
28
+ '<script', # XSS
29
+ 'javascript:', # XSS
30
+ 'UNION SELECT', # SQLi
31
+ 'OR 1=1', # SQLi
32
+ '-- ', # SQL comment injection
33
+ ]
34
+
35
+ def process_request(self, request):
36
+ if not HAS_DJANGO:
37
+ return None
38
+
39
+ request._syncforge_start_time = time.time()
40
+
41
+ # Basic WAF (Web Application Firewall) checks
42
+ if self._is_malicious(request):
43
+ ip = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR')
44
+ logger.warning(f"[SyncForge Security] Blocked malicious request from {ip} on {request.path}")
45
+ return HttpResponseForbidden("Blocked by SyncForge Security Firewall.")
46
+
47
+ return None
48
+
49
+ def process_response(self, request, response):
50
+ if not HAS_DJANGO:
51
+ return response
52
+
53
+ # Logging
54
+ if hasattr(request, '_syncforge_start_time'):
55
+ duration = (time.time() - request._syncforge_start_time) * 1000
56
+ method = request.method
57
+ path = request.path
58
+ status = response.status_code
59
+
60
+ # Format: [POST] /api/users/ - 200 OK (45.2ms)
61
+ if status >= 500:
62
+ level = logger.error
63
+ elif status >= 400:
64
+ level = logger.warning
65
+ else:
66
+ level = logger.info
67
+
68
+ level(f"[SyncForge] [{method}] {path} - {status} ({duration:.1f}ms)")
69
+
70
+ # Inject Security Headers
71
+ response['X-Powered-By'] = 'SyncForge'
72
+ response['X-Content-Type-Options'] = 'nosniff'
73
+ response['X-XSS-Protection'] = '1; mode=block'
74
+
75
+ return response
76
+
77
+ def _is_malicious(self, request):
78
+ path = request.path.upper()
79
+ query = request.META.get('QUERY_STRING', '').upper()
80
+
81
+ for pattern in self.MALICIOUS_PATTERNS:
82
+ p = pattern.upper()
83
+ if p in path or p in query:
84
+ return True
85
+
86
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncforge
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Official Python SDK for SyncForge — control exactly when data syncs between your database and clients.
5
5
  Author-email: SyncForge <sureshdulupolai@gmail.com>
6
6
  License-Expression: MIT
@@ -5,6 +5,7 @@ syncforge/__init__.py
5
5
  syncforge/client.py
6
6
  syncforge/django.py
7
7
  syncforge/exceptions.py
8
+ syncforge/middleware.py
8
9
  syncforge/result.py
9
10
  syncforge.egg-info/PKG-INFO
10
11
  syncforge.egg-info/SOURCES.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes