-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX JENKINS-39433] Make URI encoding check into admin monitor (#2661)
- Loading branch information
1 parent
159192f
commit 7bb4a59
Showing
6 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
core/src/main/java/jenkins/diagnostics/URICheckEncodingMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package jenkins.diagnostics; | ||
|
||
import hudson.Extension; | ||
import hudson.model.*; | ||
import hudson.util.FormValidation; | ||
import jenkins.model.Jenkins; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.io.IOException; | ||
|
||
import static hudson.Util.fixEmpty; | ||
|
||
@Restricted(NoExternalUse.class) | ||
@Extension | ||
public class URICheckEncodingMonitor extends AdministrativeMonitor { | ||
|
||
public boolean isCheckEnabled() { | ||
return !"ISO-8859-1".equalsIgnoreCase(System.getProperty("file.encoding")); | ||
} | ||
|
||
@Override | ||
public boolean isActivated() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.URICheckEncodingMonitor_DisplayName(); | ||
} | ||
|
||
public FormValidation doCheckURIEncoding(StaplerRequest request) throws IOException { | ||
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); | ||
// expected is non-ASCII String | ||
final String expected = "\u57f7\u4e8b"; | ||
final String value = fixEmpty(request.getParameter("value")); | ||
if (!expected.equals(value)) | ||
return FormValidation.warningWithMarkup(hudson.model.Messages.Hudson_NotUsesUTF8ToDecodeURL()); | ||
return FormValidation.ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
core/src/main/resources/jenkins/diagnostics/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
CompletedInitializationMonitor.DisplayName=Jenkins Initialization Monitor | ||
SecurityIsOffMonitor.DisplayName=Disabled Security | ||
URICheckEncodingMonitor.DisplayName=Check URI Encoding |
16 changes: 16 additions & 0 deletions
16
core/src/main/resources/jenkins/diagnostics/URICheckEncodingMonitor/message.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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> | ||
var url="${rootURL}/${it.url}/checkURIEncoding"; | ||
var params = {value : '\u57f7\u4e8b'}; | ||
var checkAjax = new Ajax.Updater( | ||
'message', url, | ||
{ | ||
method: 'get', parameters: params | ||
} | ||
); | ||
</script> | ||
<span id="message"></span> | ||
</j:if> | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters