Skip to content
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

ProxyUrl: Determine whether to proxy via web service #3199

Merged
merged 18 commits into from Nov 13, 2023

Conversation

maccabeelevine
Copy link
Member

@maccabeelevine maccabeelevine commented Nov 7, 2023

The current behavior of the ProxyUrl view helper is to proxy everything or nothing. However an institution's EZproxy server is often set up to selectively identify specific URLs that do not need to be proxied, i.e. local or open resources. This is problematic for two reasons:

  • Historically this was handled (globally) via the RedirectUnknown option, now renamed UnsafeRedirectUnknown. As the link explains this is a security issue, as phishing sites use the blind redirection to take advantage of the university domain trust to redirect to unexpected sites.
  • The replacement RedirectSafe directive works, but creates a burden to create all of those RedirectSafe directives, which can also have conflicts with existing EZproxy config directives and cause other side effects.

This PR takes advantage of a separate, lightweight OSS tool from @joecorall that integrates with EZproxy, parses its config files, and exposes a web service that translates a URL (or domain) into a yes/no answer of whether it requires the proxy prefix. This PR integrates that web service into the existing ProxyUrl view helper, to prefix only when needed and avoid both the UnsafeRedirectUnknown security issues and all the RedirectSafe configuration setup & maintenance.

TODO

  • Note BC break (change to ProxyUrl helper constructor signature) in changelog when merging
  • Document in wiki when merging

config/vufind/config.ini Outdated Show resolved Hide resolved
Co-authored-by: Joe Corall <joe@libops.io>
@maccabeelevine maccabeelevine marked this pull request as ready for review November 7, 2023 18:08
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just took a quick first look at this!

config/vufind/config.ini Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
@demiankatz
Copy link
Member

@maccabeelevine, this is looking pretty good -- I'll wait for the encoding conversation to get resolved before doing hands-on testing, but I expect this can be approved and merged pretty quickly once it's finalized. Please just let me know when you're feeling ready!

@maccabeelevine
Copy link
Member Author

Please just let me know when you're feeling ready!

@demiankatz I think it's ready for you.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a couple of possible opportunities for improvement/simplification in my latest review. Let me know what you think!

module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php Outdated Show resolved Hide resolved
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more minor thoughts, but I think this can be merged after these are addressed.

|| $this->config->EZproxy->prefixLinks;
$useWebService = $this->config->EZproxy->prefixLinksWebServiceUrl ?? false;
if ($useWebService) {
$usePrefix = $this->checkUrl($url) ?? $this->checkConfig();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On closer examination, I'm not really sure if it makes sense to use checkConfig() as the fallback here. It looks to me like the main purpose of the prefixLinks setting is to allow prefixing to be globally disabled. I think if somebody configures both prefixLinks and prefixLinksWebServiceUrl at the same time, that's essentially a configuration error. I suppose it doesn't necessarily hurt anything to leave this as it is, but it just feels to me like it might not be the best option. Maybe we should just fall back to true instead of falling back to checkConfig, for example...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree on this, although not strongly. That fallback to checkConfig() is going to happen on any exception checking the web service, such as a connection error, which itself is likely enough from time to time (even if the services are co-hosted; things break). So people should think about what the fallback default should be, i.e. it's better as a configured param than hard-coded, and so we may as well reuse prefixLinks. Admittedly the config.ini isn't clear that it's a fallback, so I just fixed that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense -- I was thinking about it differently, but tweaking the comments is a good solution. :-)

$this->logError('Exception during EZproxy web service request: ' . $ex->getMessage());
return null;
}
return '1' === $responseData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it might be a good idea to trim $responseData? I tested this by putting a text file in VuFind's public directory and pointing the configuration at that -- I could then edit the file to change it to 0 or 1 to test both cases. However, my editor initially added line breaks, and 1\n is interpreted as "not 1." This caused me a little bit of confusion, and I imagine it's possible if somebody builds their own custom web service that the responses might end up having stray whitespace in them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, done.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @maccabeelevine!

@demiankatz demiankatz merged commit 2c3a12e into vufind-org:dev Nov 13, 2023
7 checks passed
@maccabeelevine maccabeelevine deleted the proxyurl-web-service branch November 13, 2023 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants