|
1 | 1 | import os
|
2 | 2 |
|
3 | 3 | 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 |
7 | 5 | from .. import strtobool
|
8 | 6 |
|
9 | 7 |
|
@@ -61,54 +59,37 @@ def test_bad_access(client, live_server, measure_memory_usage):
|
61 | 59 | assert b'Watch protocol is not permitted by SAFE_PROTOCOL_REGEX' in res.data
|
62 | 60 |
|
63 | 61 |
|
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): |
68 | 63 |
|
69 |
| - # file:// is permitted by default, but it will be caught by ALLOW_FILE_URI |
70 | 64 | client.post(
|
71 | 65 | url_for("form_quick_watch_add"),
|
72 |
| - data={"url": f"file://{test_file_path}", "tags": ''}, |
| 66 | + data={"url": file_uri, "tags": ''}, |
73 | 67 | follow_redirects=True
|
74 | 68 | )
|
75 | 69 | wait_for_all_checks(client)
|
76 | 70 | res = client.get(url_for("index"))
|
77 | 71 |
|
78 | 72 | # If it is enabled at test time
|
79 | 73 | 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 |
86 | 78 | else:
|
87 | 79 | # Default should be here
|
88 | 80 | assert b'file:// type access is denied for security reasons.' in res.data
|
89 | 81 |
|
| 82 | + res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True) |
| 83 | + assert b'Deleted' in res.data |
| 84 | + |
90 | 85 | def test_file_slash_access(client, live_server, measure_memory_usage):
|
91 | 86 | #live_server_setup(live_server)
|
| 87 | + # file: is permitted by default, but it will be caught by ALLOW_FILE_URI |
92 | 88 |
|
93 | 89 | 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 |
112 | 93 |
|
113 | 94 | def test_xss(client, live_server, measure_memory_usage):
|
114 | 95 | #live_server_setup(live_server)
|
|
0 commit comments