Skip to content

Commit 6b63fde

Browse files
freddyaboultongradio-pr-bot
andauthoredJan 8, 2025
Blocked Paths Fix (#10304)
* add code * add changeset * Fix test * empty --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 345851d commit 6b63fde

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
 

‎.changeset/afraid-rats-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gradio": minor
3+
---
4+
5+
feat:Blocked Paths Fix

‎gradio/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,8 @@ def is_allowed_file(
15131513
bool, Literal["in_blocklist", "allowed", "created", "not_created_or_allowed"]
15141514
]:
15151515
in_blocklist = any(
1516-
is_in_or_equal(path, blocked_path) for blocked_path in blocked_paths
1516+
is_in_or_equal(str(path).lower(), str(blocked_path).lower())
1517+
for blocked_path in blocked_paths
15171518
)
15181519
if in_blocklist:
15191520
return False, "in_blocklist"

‎test/test_routes.py

+18
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@ def test_allowed_and_blocked_paths(self):
325325
io.close()
326326
os.remove(tmp_file.name)
327327

328+
def test_blocked_path_case_insensitive(self):
329+
with tempfile.TemporaryDirectory() as temp_dir:
330+
tmp_file = Path(temp_dir) / "blocked" / "test.txt"
331+
tmp_file.parent.mkdir(parents=True, exist_ok=True)
332+
tmp_file.touch()
333+
io = gr.Interface(lambda s: s.name, gr.File(), gr.File())
334+
app, _, _ = io.launch(
335+
prevent_thread_lock=True,
336+
allowed_paths=[temp_dir],
337+
blocked_paths=[str(tmp_file.parent)],
338+
)
339+
client = TestClient(app)
340+
file_response = client.get(
341+
f"{API_PREFIX}/file={str(Path(temp_dir) / 'BLOCKED' / 'test.txt')}"
342+
)
343+
assert file_response.status_code == 403
344+
io.close()
345+
328346
def test_get_file_created_by_app(self, test_client):
329347
app, _, _ = gr.Interface(lambda s: s.name, gr.File(), gr.File()).launch(
330348
prevent_thread_lock=True

0 commit comments

Comments
 (0)