Reject unsafe file extensions

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-11-23 14:46:22 -06:00
parent 80b2bd2d14
commit f86c7d69db
No known key found for this signature in database

View file

@ -992,6 +992,18 @@ impl<C: UpstreamClient + 'static, S: Sandboxing + Send + Sync + 'static> App<C,
where where
<<C as UpstreamClient>::Response as HTTPResponse>::BodyStream: Unpin, <<C as UpstreamClient>::Response as HTTPResponse>::BodyStream: Unpin,
{ {
if let Some(ext) = filename.split('.').last() {
if [
"exe", "com", "dll", "sys", "bat", "cmd", "sh", "bash", "zsh", "fish", "ps1",
"psm1", "elf", "so", "dylib", "dmg", "scr", "url", "app", "jar", "apk", "msi",
"deb", "rpm", "rpm", "pkg",
]
.iter()
.any(|x| x.eq_ignore_ascii_case(ext))
{
return Err(ErrorResponse::unsafe_media());
}
}
Self::proxy_impl(method, Some(&filename), State(state), Query(query), info).await Self::proxy_impl(method, Some(&filename), State(state), Query(query), info).await
} }
} }