Added proper 404 for not found media #1326
Labels
No labels
Blocked
Bug
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
To-Merge
Wont fix
old/ci/cd
old/rust
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
continuwuation/continuwuity!1326
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "benbot/continuwuity:benbot/first-issue"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request should resolve #1318 by adding proper 404 responses for missing files.
I also noticed that
cargo testwasn't working in the default devshell, so i also fixed that by adding the library paths to theLD_LIBRARY_PATHenv variable.Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
@ -150,3 +150,3 @@content_type,content_disposition,} = fetch_file(&services, &mxc, user, body.timeout_ms, None).await?;}) = fetch_file(&services, &mxc, user, body.timeout_ms, None).await else {This handles any error as a 404, are we sure that's what we want here? I imagine more can happen in the course of fetch_file
From a little digging, it looks like there could be a permission issue fetching the file (in which case we should return 404 anyway to not leak that a file exists) and issues around running out of memory for the BufReader that the file loads into, which should throw a 500 (and probably crash soon after 😅)
i'll get that change in later.
Looking through fetch_file, the only other errors i can see us running into are from the std::Io package.
I handled the errors that the
openfunction says it will through and that we would care to report to a client.Hey @benbot, is this waiting on anything? Happy to fix this up and get it merged for you assuming it's mostly done.
@nex wrote in #1326 (comment):
Sorry, I just didn’t get a chance this week 😅
Was planning on fixing it up tomorrow.
@ -189,0 +191,4 @@} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {| Ok(meta) => meta,| Err(e) => {match e {I'm pretty unfamiliar with how error handling is done in this project, so please let me know if this isn't the preferred way to handle different ErrorKinds here. :)
This looks fine to me, just thinking the match case can be more consise
@ -153,0 +154,4 @@| Err(e) => {match e {| conduwuit::Error::Io(e) => {match e.kind() {This could probably be
@ -189,0 +212,4 @@| Err(e) => {match e {| conduwuit::Error::Io(e) => {match e.kind() {Same feedback as previous comment in
get_content_routeWIP: Added proper 404 for not found mediato Added proper 404 for not found media@ -16,14 +16,19 @@inunrelated change should really go into a different PR
I could extract those changes to a different PR, sure.
@ -189,0 +198,4 @@} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {| Ok(meta) => meta,| Err(conduwuit::Error::Io(e)) => {if matches!(e.kind(), std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::NotFound) {OK so I'm probably dumb for not thinking of this earlier but an io permission issue should only happen if the home server is misconfigured - we don't actually use file system permissions for anything ourselves. Hiding it as a 404 would make that a bit harder to debug
Oh true.
I'm also dumb for mixing system file permissions for api permissions 😅
probably best not to report misconfigurations to the end user and instead keep it in logs that only the people who can fix said misconfiguration can see, no?
absolutely.
i was just going to log it.
9cd789db51eaaa41d28aeaaa41d28a3a40825d6e3a40825d6e62c4b38cc862c4b38cc87bad4862f57bad4862f510afc1329710afc13297ee7acb8f0c