Skip to content

Commit 1258cf6

Browse files
committed
v0.1.1
Enhanced security
1 parent 860af66 commit 1258cf6

File tree

11 files changed

+39
-7
lines changed

11 files changed

+39
-7
lines changed
-22 KB
Binary file not shown.

dist/pywire_eel-0.1.0.tar.gz

-21.5 KB
Binary file not shown.
22.3 KB
Binary file not shown.

dist/pywire_eel-0.1.1.tar.gz

21.8 KB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pywire-eel"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "PyWire is a lightweight Python library that allows you to create simple desktop GUI applications using HTML, CSS, and JavaScript, while giving full access to Python’s functionality and libraries."
99
authors = [
1010
{ name = "Fadi002"}

pywire/bridge.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
from typing import Dict, Any, Callable, Optional, List
77
from .server import HTTPServerThread, WSServerThread
8+
from .security import SecurityConfig
89
from .utils import PortManager, Logger, MessageQueue
910
from .browser import BrowserDetector, BrowserLauncher
1011

@@ -93,7 +94,8 @@ def _start_servers(self):
9394

9495
self.ws_server = WSServerThread(
9596
port=self.ws_port,
96-
bridge=self
97+
bridge=self,
98+
security_config=SecurityConfig(http_port=self.http_port)
9799
)
98100
self.ws_server.daemon = True
99101
self.ws_server.start()

pywire/browser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ def _launch_edge_controlled(self, url: str, mode: str, size: tuple, position: tu
640640
'--disable-features=TranslateUI',
641641
'--enable-automation',
642642
'--disable-sync',
643-
'--disable-extensions'
643+
'--disable-extensions',
644+
"--allow-insecure-localhost",
645+
"--disable-site-isolation-trials",
646+
"--allow-running-insecure-content"
644647
])
645648

646649
if mode == 'app':

pywire/security.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,25 @@ def validate_args(self, args: List[Any]) -> List[Any]:
4040
class SecurityConfig:
4141
"""Simplified security configuration."""
4242

43-
def __init__(self):
43+
def __init__(self, http_port: int = None):
4444
self.enable_input_validation = True
4545
self.max_message_size = 1024 * 1024 # 1MB
46-
self.allowed_origins = ['http://localhost', 'http://127.0.0.1']
46+
self.http_port = http_port
47+
self.allowed_origins = {
48+
"http://127.0.0.1:<server_port>",
49+
"http://localhost:<server_port>",
50+
}
51+
52+
def is_origin_allowed(self, origin: str) -> bool:
53+
"""Check if the Origin header value is allowed."""
54+
if not isinstance(origin, str) or not origin:
55+
return False
56+
if self.http_port is not None:
57+
expected1 = f"http://localhost:{self.http_port}"
58+
expected2 = f"http://127.0.0.1:{self.http_port}"
59+
return origin == expected1 or origin == expected2
60+
pattern = r'^http://(localhost|127\.0\.0\.1)(:\\d+)?$'
61+
return re.match(pattern, origin) is not None
4762

4863
def update(self, **kwargs):
4964
"""Update security configuration."""

pywire/server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(self, port=8001, bridge=None, security_config=None):
159159
self.logger = Logger("WebSocket")
160160
self.security_manager = SecurityManager()
161161
self.input_validator = InputValidator()
162+
self.security_config = security_config or SecurityConfig()
162163
# Use the bridge's message queue instead of creating a new one
163164
self.message_queue = bridge.message_queue if bridge else MessageQueue()
164165
self.server_socket = None
@@ -323,6 +324,17 @@ def handshake(self, client_socket) -> bool:
323324
if header not in headers or headers[header].lower() != expected_value.lower():
324325
return False
325326

327+
origin = headers.get('origin')
328+
if origin:
329+
if not self.security_config.is_origin_allowed(origin):
330+
response = (
331+
'HTTP/1.1 403 Forbidden\r\n'
332+
'Content-Length: 0\r\n'
333+
'\r\n'
334+
)
335+
client_socket.send(response.encode())
336+
return False
337+
326338
# Get WebSocket key
327339
ws_key = headers.get('sec-websocket-key')
328340
if not ws_key:

pywire_eel.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.4
22
Name: pywire-eel
3-
Version: 0.1.0
3+
Version: 0.1.1
44
Summary: PyWire is a lightweight Python library that allows you to create simple desktop GUI applications using HTML, CSS, and JavaScript, while giving full access to Python’s functionality and libraries.
55
Home-page: https://github.com/Fadi002/pywire-eel
66
Author: Fadi002

0 commit comments

Comments
 (0)