Skip to content

Commit 256aee4

Browse files
committed
path traversal, block such uploads, even they are safe for azure storage
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent c0987ed commit 256aee4

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
FROM rust:1.83 AS builder
1+
FROM rust:1.93 AS builder
22
WORKDIR /usr/src/app
33
COPY . .
44
RUN cargo install --path .
55

6-
FROM debian:bookworm-slim
6+
FROM debian:trixie-slim
77
RUN apt-get update && rm -rf /var/lib/apt/lists/*
88
COPY --from=builder /usr/local/cargo/bin/kernelci-storage /usr/local/bin/kernelci-storage
99
# install ssl certificates
1010
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1111
RUN mkdir /workdir
1212
WORKDIR /workdir
1313
CMD ["kernelci-storage"]
14-
15-

src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ prefixes = ["/bob"]
491491
prefixes = [""]
492492
*/
493493

494+
fn validate_path(path: &str) -> Result<(), String> {
495+
if path.contains("..") {
496+
return Err("Path traversal detected".to_string());
497+
}
498+
Ok(())
499+
}
500+
494501
fn verify_upload_permissions(owner: &str, path: &str) -> Result<(), String> {
495502
let cfg_content = get_config_content();
496503
let cfg: Table = toml::from_str(&cfg_content).unwrap();
@@ -658,6 +665,15 @@ async fn ax_post_file(
658665

659666
let full_path = format!("{}/{}", path, file0_filename);
660667

668+
// validate path for traversal
669+
match validate_path(&full_path) {
670+
Ok(_) => (),
671+
Err(e) => {
672+
upload_result = Some((StatusCode::BAD_REQUEST, e.into_bytes()));
673+
break;
674+
}
675+
}
676+
661677
// verify upload permissions
662678
match verify_upload_permissions(&owner, &path) {
663679
Ok(_) => (),
@@ -781,6 +797,13 @@ async fn ax_post_file(
781797

782798
let full_path = format!("{}/{}", path, file0_filename);
783799

800+
match validate_path(&full_path) {
801+
Ok(_) => (),
802+
Err(e) => {
803+
return (StatusCode::BAD_REQUEST, e.into_bytes());
804+
}
805+
}
806+
784807
match verify_upload_permissions(&owner, &path) {
785808
Ok(_) => (),
786809
Err(e) => {

0 commit comments

Comments
 (0)