-
Notifications
You must be signed in to change notification settings - Fork 0
ETT-477 Update under_server references in imgsrv
#196
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ use Plack::Request; | |
| use Plack::Util; | ||
| use Utils; | ||
|
|
||
| use SRV::Utils; | ||
|
|
||
| use Utils::Settings; | ||
| our $settings = Utils::Settings::load('imgsrv', 'download'); | ||
|
|
||
|
|
@@ -33,26 +35,22 @@ my $loader = sub { | |
| } | ||
| }; | ||
|
|
||
| sub under_server { | ||
| return ( ! defined $ENV{PSGI_COMMAND} ); | ||
| } | ||
|
|
||
| builder { | ||
|
|
||
| if ( under_server() ) { | ||
| if ( SRV::Utils::under_server() ) { | ||
| enable 'URLFixer'; | ||
| } | ||
|
|
||
| enable "PopulateENV", app_name => 'imgsrv'; | ||
|
|
||
| enable_if { (under_server() && $ENV{HT_DEV}) } 'StackTrace'; | ||
| enable_if { (SRV::Utils::under_server() && $ENV{HT_DEV}) } 'StackTrace'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we think of any reason not to enable solely based on |
||
|
|
||
| enable_if { (under_server() && ! $ENV{HT_DEV}) } | ||
| enable_if { (SRV::Utils::under_server() && ! $ENV{HT_DEV}) } | ||
| "HTErrorDocument", 500 => "/mdp-web/production_error.html"; | ||
|
|
||
| enable_if { (under_server() && ! $ENV{HT_DEV}) } "HTTPExceptions", rethrow => 0; | ||
| enable_if { (SRV::Utils::under_server() && ! $ENV{HT_DEV}) } "HTTPExceptions", rethrow => 0; | ||
|
|
||
| if ( under_server() ) { | ||
| if ( SRV::Utils::under_server() ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be inclined to just always enable these -- given we do local development in docker, I can't think of a case where we wouldn't be |
||
|
|
||
| enable 'Choke::Cache::Filesystem'; | ||
|
|
||
|
|
@@ -87,9 +85,5 @@ builder { | |
| mount "/image" => $loader->('SRV::Volume::Image::Bundle'); | ||
| mount "/remediated" => $loader->('SRV::Volume::Remediated::Bundle'); | ||
| }; | ||
| mount "/article" => builder { | ||
| mount "/pdf" => $loader->('SRV::Article::PDF'); | ||
| mount "/epub" => $loader->('SRV::Article::EPUB'); | ||
| } | ||
|
|
||
| }; | ||
This file was deleted.
This file was deleted.
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.
The question is, do we even need these at all? Applies to this file and imgsrv.psgi as well.
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'm not sure how I feel about
URLFixerin general. If there are percent-escaped ';' or '=' characters in the URL, then it will unescape the entire URL and redirect to that. That's a problem we see with the ChatGPT-created queries to ssd.I could imagine some kind of redirection attack though -- basically tricking imgsrv to redirecting to something unexpected - but I'm not sure exactly what the threat model would be.
It may be worthwhile seeing if there's evidence of legit requests to imgsrv that would trigger this (i.e. requests to imgsrv containing
%3Bor%3D), and if we can't find any, we just disableURLFixerentirely.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 honestly can't tell. It appears that the redirect is sticking the URL with escaped values into the http_referer, so I can't see what the upstream source is, that is, whether it's one of ours or something else that might hold some meaning. I will rely on some more guidance to answer this question, perhaps, and expect to return to this question.
Uh oh!
There was an error while loading. Please reload this page.
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.
Update: we can't completely remove
under_serverorURLFixeras things stand now. So here are two sample requests from the playwright tests. The second is called withPlack::App::Commandso the actual download action is notunder_server().URLFixeris only enabled whenunder_server(), the (second, below) request that comes back from the frontend contains%3dand... for some reason it's bad to fix it??? It looks like doing so would result in decoding a part of the URL (download_url) that is meant to be left encoded. EnablingURLFixeracross the board kills the playwright tests for some reason. Not sure why. I'm not sure if this is in scope for the current ticket. Why on earth are these URLs so bloody convoluted?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.
After some tracing I understand better what is happening. image.psgi and download.psgi can both be called via
Plack::App::Command->runand thus withunder_serverFALSE. I didn't realize that background processing was done by the bucket chain ofand by the time this gets to URLFixer (yes ultimately we're talking about that) the
REQUEST_URIin the environment is munged all to heck. So I would guess that's why that particular middleware is selectively enabled.Uh oh!
There was an error while loading. Please reload this page.
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.
To help answer the original question, however, %3B and %3D only seem to be showing up in unauthenticated requests from outside the US. I would tentatively recommend disabling URLFixer, though perhaps not removing it right away.