Skip to content

Commit 952c65d

Browse files
Trolldemortedfsck
authored andcommitted
Prevent dir traversal, use admin destinations when PSKs are equal
Fixes #36 Fixes #32 Fixes #25
1 parent 7425cc8 commit 952c65d

File tree

6 files changed

+8
-34
lines changed

6 files changed

+8
-34
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.code-workspace
77
/data
88
*.yml
9+
/.enocache
910

1011
# Cargo
1112
/target

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ COPY ./static ./static
3434
COPY ./Rocket.toml ./Rocket.toml
3535

3636
ENV ROCKET_ENV production
37-
ENV ROCKET_TEMPLATE_DIR static
3837

3938
RUN adduser --disabled-password --gecos '' enokey
4039
RUN mkdir /home/enokey/.ssh

Rocket.toml

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
[production]
22
port = 8000
3-
template_dir = "static"
4-
5-
[development]
6-
template_dir = "static"

src/main.rs

+7-28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rocket::response::NamedFile;
2929
use rocket::http::RawStr;
3030
use rocket::response::content;
3131
use rocket_contrib::templates::Template;
32+
use rocket_contrib::serve::StaticFiles;
3233

3334
use getopts::Options;
3435
use regex::Regex;
@@ -115,10 +116,10 @@ fn index_post(form: Result<Form<FormInput>, FormError>) -> content::Html<String>
115116
content::Html(match form {
116117
Ok(form) => {
117118
let config = &*CONFIG.lock().unwrap();
118-
let destinations = if form.authkey == config.user_psk {
119-
&config.user_destinations
120-
} else if &form.authkey == &config.admin_psk {
119+
let destinations = if form.authkey == config.admin_psk {
121120
&config.admin_destinations
121+
} else if &form.authkey == &config.user_psk {
122+
&config.user_destinations
122123
} else {
123124
return content::Html(format!("Wrong AUTHKEY: {:?}", form))
124125
};
@@ -194,30 +195,6 @@ fn favicon() -> io::Result<NamedFile> {
194195
NamedFile::open("static/favicon.ico")
195196
}
196197

197-
#[get("/static/<file..>")]
198-
fn static_files(file: PathBuf) -> Option<NamedFile> {
199-
let allowed_files = vec!(
200-
"css/bootstrap.min.css",
201-
"css/bootstrap.min.css.map",
202-
"css/style.css"
203-
);
204-
205-
if let Some(file) = file.to_str() {
206-
if allowed_files.contains(&file) {
207-
return NamedFile::open(Path::new("static/").join(file)).ok();
208-
}
209-
}
210-
None
211-
}
212-
213-
#[get("/keyfiles/<file..>")]
214-
fn key_files(file: PathBuf) -> Option<NamedFile> {
215-
if let Some(file) = file.to_str() {
216-
return NamedFile::open(Path::new("keyfiles/").join(file)).ok()
217-
}
218-
None
219-
}
220-
221198
fn main() {
222199
let args: Vec<String> = env::args().collect();
223200
let program = args[0].clone();
@@ -292,7 +269,9 @@ fn main() {
292269
}
293270

294271
rocket::ignite()
295-
.mount("/", routes![static_files, index_post, index_get, deploy_get, deploy_post, favicon, key_files])
272+
.mount("/static", StaticFiles::from("static"))
273+
.mount("/keyfiles", StaticFiles::from("keyfiles"))
274+
.mount("/", routes![index_post, index_get, deploy_get, deploy_post, favicon])
296275
.attach(Template::fairing())
297276
.launch();
298277
}

src/storage.rs

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub fn generate_authorized_key_files(destinations: &[Destination]) -> Result<(),
6767
write!(authorized_keys_file, "{}", &deploy_key)?
6868
}
6969

70-
7170
// append raw keys
7271
let mut raw_keys = String::new();
7372
if let Ok(mut raw_keys_file) = File::open(&destination.raw_storage_file_name) {
File renamed without changes.

0 commit comments

Comments
 (0)