kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Fixing file:// file pickup - for change detection of local files (#2505)
rodzic
c0b6c8581e
commit
e756e0af5e
|
@ -4,6 +4,7 @@ import os
|
||||||
import chardet
|
import chardet
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from changedetectionio import strtobool
|
||||||
from changedetectionio.content_fetchers.exceptions import BrowserStepsInUnsupportedFetcher, EmptyReply, Non200ErrorCodeReceived
|
from changedetectionio.content_fetchers.exceptions import BrowserStepsInUnsupportedFetcher, EmptyReply, Non200ErrorCodeReceived
|
||||||
from changedetectionio.content_fetchers.base import Fetcher
|
from changedetectionio.content_fetchers.base import Fetcher
|
||||||
|
|
||||||
|
@ -45,13 +46,19 @@ class fetcher(Fetcher):
|
||||||
if self.system_https_proxy:
|
if self.system_https_proxy:
|
||||||
proxies['https'] = self.system_https_proxy
|
proxies['https'] = self.system_https_proxy
|
||||||
|
|
||||||
r = requests.request(method=request_method,
|
session = requests.Session()
|
||||||
data=request_body,
|
|
||||||
url=url,
|
if strtobool(os.getenv('ALLOW_FILE_URI', 'false')) and url.startswith('file://'):
|
||||||
headers=request_headers,
|
from requests_file import FileAdapter
|
||||||
timeout=timeout,
|
session.mount('file://', FileAdapter())
|
||||||
proxies=proxies,
|
|
||||||
verify=False)
|
r = session.request(method=request_method,
|
||||||
|
data=request_body,
|
||||||
|
url=url,
|
||||||
|
headers=request_headers,
|
||||||
|
timeout=timeout,
|
||||||
|
proxies=proxies,
|
||||||
|
verify=False)
|
||||||
|
|
||||||
# If the response did not tell us what encoding format to expect, Then use chardet to override what `requests` thinks.
|
# If the response did not tell us what encoding format to expect, Then use chardet to override what `requests` thinks.
|
||||||
# For example - some sites don't tell us it's utf-8, but return utf-8 content
|
# For example - some sites don't tell us it's utf-8, but return utf-8 content
|
||||||
|
|
|
@ -35,4 +35,8 @@ pytest tests/test_access_control.py
|
||||||
pytest tests/test_notification.py
|
pytest tests/test_notification.py
|
||||||
pytest tests/test_backend.py
|
pytest tests/test_backend.py
|
||||||
pytest tests/test_rss.py
|
pytest tests/test_rss.py
|
||||||
pytest tests/test_unique_lines.py
|
pytest tests/test_unique_lines.py
|
||||||
|
|
||||||
|
# Check file:// will pickup a file when enabled
|
||||||
|
echo "Hello world" > /tmp/test-file.txt
|
||||||
|
ALLOW_FILE_URI=yes pytest tests/test_security.py
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks
|
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from .. import strtobool
|
||||||
|
|
||||||
|
|
||||||
def test_setup(client, live_server, measure_memory_usage):
|
def test_setup(client, live_server, measure_memory_usage):
|
||||||
live_server_setup(live_server)
|
live_server_setup(live_server)
|
||||||
|
|
||||||
|
@ -55,17 +60,33 @@ def test_bad_access(client, live_server, measure_memory_usage):
|
||||||
|
|
||||||
assert b'Watch protocol is not permitted by SAFE_PROTOCOL_REGEX' in res.data
|
assert b'Watch protocol is not permitted by SAFE_PROTOCOL_REGEX' in res.data
|
||||||
|
|
||||||
# file:// is permitted by default, but it will be caught by ALLOW_FILE_URI
|
|
||||||
|
|
||||||
|
def test_file_access(client, live_server, measure_memory_usage):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
|
||||||
|
test_file_path = "/tmp/test-file.txt"
|
||||||
|
|
||||||
|
# file:// is permitted by default, but it will be caught by ALLOW_FILE_URI
|
||||||
client.post(
|
client.post(
|
||||||
url_for("form_quick_watch_add"),
|
url_for("form_quick_watch_add"),
|
||||||
data={"url": 'file:///tasty/disk/drive', "tags": ''},
|
data={"url": f"file://{test_file_path}", "tags": ''},
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
wait_for_all_checks(client)
|
wait_for_all_checks(client)
|
||||||
res = client.get(url_for("index"))
|
res = client.get(url_for("index"))
|
||||||
|
|
||||||
assert b'file:// type access is denied for security reasons.' in res.data
|
# If it is enabled at test time
|
||||||
|
if strtobool(os.getenv('ALLOW_FILE_URI', 'false')):
|
||||||
|
res = client.get(
|
||||||
|
url_for("preview_page", uuid="first"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Should see something (this file added by run_basic_tests.sh)
|
||||||
|
assert b"Hello world" in res.data
|
||||||
|
else:
|
||||||
|
# Default should be here
|
||||||
|
assert b'file:// type access is denied for security reasons.' in res.data
|
||||||
|
|
||||||
def test_xss(client, live_server, measure_memory_usage):
|
def test_xss(client, live_server, measure_memory_usage):
|
||||||
#live_server_setup(live_server)
|
#live_server_setup(live_server)
|
||||||
|
|
|
@ -22,6 +22,7 @@ validators~=0.21
|
||||||
# >= 2.26 also adds Brotli support if brotli is installed
|
# >= 2.26 also adds Brotli support if brotli is installed
|
||||||
brotli~=1.0
|
brotli~=1.0
|
||||||
requests[socks]
|
requests[socks]
|
||||||
|
requests-file
|
||||||
|
|
||||||
urllib3==1.26.19
|
urllib3==1.26.19
|
||||||
chardet>2.3.0
|
chardet>2.3.0
|
||||||
|
|
Ładowanie…
Reference in New Issue