Skip to content

Commit

Permalink
Improve auth logging + configurable body size
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwilemski committed Jan 1, 2024
1 parent 367a57e commit 51dbc4b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::{debug, error, info};
use serde_json::json;

use axum::{
extract::Path,
extract::{Path, DefaultBodyLimit},
http::{HeaderMap, StatusCode},
response::IntoResponse,
routing::{get, on, on_service, post, MethodFilter},
Expand Down Expand Up @@ -175,7 +175,7 @@ async fn main() -> Result<(), anyhow::Error> {
}

})
)
).route_layer(DefaultBodyLimit::max(site_config.micropub.media_endpoint_max_upload_length))
.route(
"/tag/:tag",
on(
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct MicropubConfig {
pub host_website: String,
pub media_endpoint: String,
#[serde(default = "default_max_upload_length")]
pub media_endpoint_max_upload_length: u64, // XXX currently unused
pub media_endpoint_max_upload_length: usize,
pub micropub_endpoint: String,
}

Expand All @@ -42,6 +42,6 @@ fn default_auth_endpoint() -> String {
crate::DEFAULT_AUTH_ENDPOINT.into()
}

fn default_max_upload_length() -> u64 {
fn default_max_upload_length() -> usize {
crate::DEFAULT_MAX_CONTENT_LENGTH
}
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub const DEFAULT_MAX_CONTENT_LENGTH: u64 = 1024 * 1024 * 50; // 50 megabytes
pub const DEFAULT_MAX_CONTENT_LENGTH: usize = 1024 * 1024 * 50; // 50 megabytes
pub const DEFAULT_AUTH_TOKEN_ENDPOINT: &str = "https://tokens.indieauth.com/token";
pub const DEFAULT_AUTH_ENDPOINT: &str = "https://indieauth.com/auth";
5 changes: 5 additions & 0 deletions src/handlers/micropub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ pub async fn handle_post(
).await?;

if validate_response.me != site_config.micropub.host_website {
error!(
"mismatched authorization: me: {} host_website: {}",
validate_response.me,
site_config.micropub.host_website
);
return Err(StatusCode::FORBIDDEN);
}

Expand Down

0 comments on commit 51dbc4b

Please sign in to comment.