Skip to content

Commit 31a4c29

Browse files
committed
file access restrictions: improve error messages
1 parent 7399b10 commit 31a4c29

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/filesystem.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,18 @@ impl FileSystem {
144144
for (i, component) in path.components().enumerate() {
145145
if let Component::Normal(c) = component {
146146
if i == 0 && c.eq_ignore_ascii_case("sqlpage") {
147-
anyhow::bail!(ErrorWithStatus {
147+
return Err(ErrorWithStatus {
148148
status: actix_web::http::StatusCode::FORBIDDEN,
149+
})
150+
.with_context(|| {
151+
"The /sqlpage/ path prefix is reserved for internal use. It is not public."
149152
});
150153
}
151154
if c.as_encoded_bytes().starts_with(b".") {
152-
anyhow::bail!(ErrorWithStatus {
155+
return Err(ErrorWithStatus {
153156
status: actix_web::http::StatusCode::FORBIDDEN,
154-
});
157+
})
158+
.with_context(|| "Directory traversal is not allowed");
155159
}
156160
} else {
157161
anyhow::bail!(

src/webserver/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub async fn main_handler(
338338
Ok(action) => action,
339339
Err(e) => {
340340
let e = e.context(format!(
341-
"The server cannot provide what you were asking for. \n\
341+
"The server was unable to fulfill your request. \n\
342342
The following page is not accessible: {path_and_query:?}"
343343
));
344344
return Err(anyhow_err_to_actix(e, app_state));

0 commit comments

Comments
 (0)