-
-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 2455: Check auth for pictrs when instance is private. #2477
Fix 2455: Check auth for pictrs when instance is private. #2477
Conversation
You need to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires 1-2 DB reads for every single picture requested now, reading the site to check if its a private instance, and if it is, reading from local_user to make sure they're actually a user.
That performance hit scares me, because some pages like Home can request hundreds of pictures.
I don't think this is on you to fix tho, its on us to create a in-memory singleton of local site settings, that gets updated on every save. Then we could at least reduce this to one read validating the local user, that should only get run on a private instances.
Also the format check is failing, run cargo +nightly fmt
to fix
crates/routes/src/images.rs
Outdated
if site.private_instance { | ||
let jwt = req | ||
.cookie("jwt") | ||
.expect("No auth header for picture access"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No expect, do a .map_err(error::ErrorUnauthorized)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that should be done in upload() on line 92 as well i think?
.cookie("jwt") | ||
.expect("No auth header for picture access"); | ||
if get_local_user_view_from_jwt(jwt.value(), context.pool(), context.secret()).await.is_err() { | ||
return Ok(HttpResponse::Unauthorized().finish()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better to return the Error(error::ErrorUnauthorized)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in both cases we should return a HttpResponse. I'm not sure how to do that honestly.
Is replacing expect() with .map_err(error::ErrorUnauthorized) enough above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spose that's fine, althoug that actix errors are also HttpResponses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dessalines I'm getting errors about types not being correct. I'm really unsure how to do that, and need help on those - sorry not yet familiar with those rust libs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other examples in this file of .map_err
. If you run cargo check
, it should tell you the exact error.
I agree on the performance concern. I see up to 600 requests per user easily if you have some image intense posts. Thanks for the review, i did run the formatter now. |
91ed275
to
f24678f
Compare
#2455