Skip to content

Commit 74447ea

Browse files
committed
hide dotfiles
1 parent b88baac commit 74447ea

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/filesystem.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ impl FileSystem {
122122
status: actix_web::http::StatusCode::FORBIDDEN,
123123
});
124124
}
125+
if c.to_str().map_or(false, |s| s.starts_with('.')) {
126+
anyhow::bail!(ErrorWithStatus {
127+
status: actix_web::http::StatusCode::FORBIDDEN,
128+
});
129+
}
125130
} else {
126131
anyhow::bail!(
127132
"Unsupported path: {path:?}. Path component '{component:?}' is not allowed."

tests/.hidden.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select 'text' as component, 'This is a hidden file that should not be accessible' as contents;

tests/index.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,22 @@ async fn test_request_body_base64() -> actix_web::Result<()> {
880880
Ok(())
881881
}
882882

883+
#[actix_web::test]
884+
async fn test_hidden_files() {
885+
let resp_result = req_path("/tests/.hidden.sql").await;
886+
assert!(
887+
resp_result.is_err(),
888+
"Accessing a hidden file should be forbidden, but received success: {resp_result:?}"
889+
);
890+
let resp = resp_result.unwrap_err().error_response();
891+
assert_eq!(resp.status(), http::StatusCode::FORBIDDEN);
892+
assert!(
893+
String::from_utf8_lossy(&resp.into_body().try_into_bytes().unwrap())
894+
.to_lowercase()
895+
.contains("forbidden"),
896+
);
897+
}
898+
883899
async fn get_request_to_with_data(
884900
path: &str,
885901
data: actix_web::web::Data<AppState>,

0 commit comments

Comments
 (0)