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

[FIX JENKINS-39433] Make URI encoding check into admin monitor #2661

Merged
merged 1 commit into from
Dec 16, 2016

Conversation

daniel-beck
Copy link
Member

Basically move the code into an administrative monitor.

Tested manually that sending a different string than expected results in a warning, and that the deprecated code still works as expected despite being obsolete.

The original request in JENKINS-39433 was to be able to disable the check, but the implementation was a hack anyway. Now it's an admin monitor, and can be disabled in Configure System as a side effect.

@daniel-beck daniel-beck added the needs-more-reviews Complex change, which would benefit from more eyes label Dec 9, 2016
@@ -4454,20 +4434,21 @@ public void doResources(StaplerRequest req, StaplerResponse rsp) throws IOExcept
* Checks if container uses UTF-8 to decode URLs. See
* http://wiki.jenkins-ci.org/display/JENKINS/Tomcat#Tomcat-i18n
*/
@Restricted(NoExternalUse.class)
@RestrictedSince("since TODO")
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

I would also add the deprecated Javadoc comment with usage guidelines

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no legitimate usage. The new admin monitor is now also @Restricted.

import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.*;
Copy link
Member

Choose a reason for hiding this comment

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

hmm.... If you use IDEA, you can disable it

if (!expected.equals(value))
return FormValidation.warningWithMarkup(Messages.Hudson_NotUsesUTF8ToDecodeURL());
return FormValidation.ok();
return ExtensionList.lookup(URICheckEncodingMonitor.class).get(0).doCheckURIEncoding(request);
Copy link
Member

Choose a reason for hiding this comment

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

I would add the syntax sugar to the URICheckEncodingMonitor class (as a public static method?). lookup.get(0) is formally incorrect, hence that method may at least do the check inside and throw IllegalState or log&return warnings

Copy link
Member Author

Choose a reason for hiding this comment

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

@oleg-nenashev

lookup.get(0) is formally incorrect

Could you explain? Is there an alternative I missed (other than moving the code into the monitor)?

Copy link
Member

Choose a reason for hiding this comment

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

So technically it is possible to remove the AdministrativeMonitor from the extension list. E.g.
...

  1. if there is a bug there, as an admin I can remove it from the extension list using the System Groovy script.
  2. Then ExtensionList.lookup(URICheckEncodingMonitor.class) will start returning the empty list
  3. .get(0).doCheckURIEncoding(request) will fail with RuntimeException in this case

It would be more relevant to return FormValidation error in such case than to blow u the UI

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be more relevant to return FormValidation error in such case than to blow u the UI

These deprecated methods aren't used anymore. I tried to be nice here instead of just returning false or something similar…

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:if test="${it.checkEnabled}">
<script>
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure you really need JavaScript and AJAX here. It will unlikely work properly since the administrative monitor needs to be calculated before the message is shown. Or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

This admin monitor is always active, similar to ReverseProxyMonitor, and only shows a message upon AJAX failure. I just moved the existing code over, it works exactly the same otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

OK

@oleg-nenashev
Copy link
Member

I agree with merge after the discussion

@daniel-beck
Copy link
Member Author

@jenkinsci/code-reviewers

package jenkins.diagnostics;

import hudson.Extension;
import hudson.model.*;
Copy link
Member

Choose a reason for hiding this comment

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

Still an 🐜 for this

Copy link
Member Author

@daniel-beck daniel-beck Dec 14, 2016

Choose a reason for hiding this comment

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

I have the threshold for a * import at 15. This seems reasonable.

@oleg-nenashev
Copy link
Member

@jenkinsci/code-reviewers anybody else?

@oleg-nenashev oleg-nenashev added ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback and removed needs-more-reviews Complex change, which would benefit from more eyes labels Dec 16, 2016
@oleg-nenashev oleg-nenashev merged commit 7bb4a59 into jenkinsci:master Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants