Skip to content

Commit f7e9846

Browse files
committed
CVE-2024-56509 - Stricter file protocol checking pre-check ( Improper Input Validation Leading to LFR/Path Traversal when fetching file:.. )
1 parent 5dea5e1 commit f7e9846

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

changedetectionio/processors/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def call_browser(self, preferred_proxy_id=None):
3333

3434
url = self.watch.link
3535

36-
# Protect against file://, file:/ access, check the real "link" without any meta "source:" etc prepended.
37-
if re.search(r'^file:/', url.strip(), re.IGNORECASE):
36+
# Protect against file:, file:/, file:// access, check the real "link" without any meta "source:" etc prepended.
37+
if re.search(r'^file:', url.strip(), re.IGNORECASE):
3838
if not strtobool(os.getenv('ALLOW_FILE_URI', 'false')):
3939
raise Exception(
4040
"file:// type access is denied for security reasons."

changedetectionio/tests/test_security.py

+14-33
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import os
22

33
from flask import url_for
4-
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks
5-
import time
6-
4+
from .util import live_server_setup, wait_for_all_checks
75
from .. import strtobool
86

97

@@ -61,54 +59,37 @@ def test_bad_access(client, live_server, measure_memory_usage):
6159
assert b'Watch protocol is not permitted by SAFE_PROTOCOL_REGEX' in res.data
6260

6361

64-
def test_file_slashslash_access(client, live_server, measure_memory_usage):
65-
#live_server_setup(live_server)
66-
67-
test_file_path = os.path.abspath(__file__)
62+
def _runner_test_various_file_slash(client, file_uri):
6863

69-
# file:// is permitted by default, but it will be caught by ALLOW_FILE_URI
7064
client.post(
7165
url_for("form_quick_watch_add"),
72-
data={"url": f"file://{test_file_path}", "tags": ''},
66+
data={"url": file_uri, "tags": ''},
7367
follow_redirects=True
7468
)
7569
wait_for_all_checks(client)
7670
res = client.get(url_for("index"))
7771

7872
# If it is enabled at test time
7973
if strtobool(os.getenv('ALLOW_FILE_URI', 'false')):
80-
res = client.get(
81-
url_for("preview_page", uuid="first"),
82-
follow_redirects=True
83-
)
84-
85-
assert b"test_file_slashslash_access" in res.data
74+
# So it should permit it, but it should fall back to the 'requests' library giving an error
75+
# (but means it gets passed to playwright etc)
76+
assert b"URLs with hostname components are not permitted" in res.data
77+
assert b"_runner_test_various_file_slash" in res.data # Can read this file OK
8678
else:
8779
# Default should be here
8880
assert b'file:// type access is denied for security reasons.' in res.data
8981

82+
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
83+
assert b'Deleted' in res.data
84+
9085
def test_file_slash_access(client, live_server, measure_memory_usage):
9186
#live_server_setup(live_server)
87+
# file: is permitted by default, but it will be caught by ALLOW_FILE_URI
9288

9389
test_file_path = os.path.abspath(__file__)
94-
95-
# file:// is permitted by default, but it will be caught by ALLOW_FILE_URI
96-
client.post(
97-
url_for("form_quick_watch_add"),
98-
data={"url": f"file:/{test_file_path}", "tags": ''},
99-
follow_redirects=True
100-
)
101-
wait_for_all_checks(client)
102-
res = client.get(url_for("index"))
103-
104-
# If it is enabled at test time
105-
if strtobool(os.getenv('ALLOW_FILE_URI', 'false')):
106-
# So it should permit it, but it should fall back to the 'requests' library giving an error
107-
# (but means it gets passed to playwright etc)
108-
assert b"URLs with hostname components are not permitted" in res.data
109-
else:
110-
# Default should be here
111-
assert b'file:// type access is denied for security reasons.' in res.data
90+
_runner_test_various_file_slash(client, file_uri=f"file://{test_file_path}")
91+
_runner_test_various_file_slash(client, file_uri=f"file:/{test_file_path}")
92+
_runner_test_various_file_slash(client, file_uri=f"file:{test_file_path}") # CVE-2024-56509
11293

11394
def test_xss(client, live_server, measure_memory_usage):
11495
#live_server_setup(live_server)

0 commit comments

Comments
 (0)