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

Enforce POST in form validation #61

Merged
merged 5 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.servlet.ServletException;
import java.io.IOException;
Expand Down Expand Up @@ -198,6 +199,7 @@ private void loadEnvVariables(){
* @throws IOException if there is an input/output exception.
* @throws ServletException if there is a servlet exception.
*/
@RequirePOST
public FormValidation doTestConnection(@QueryParameter("targetApiKey") final String targetApiKey)
throws IOException, ServletException {
if (DatadogHttpClient.validateDefaultIntakeConnection(this.getTargetApiURL(), Secret.fromString(targetApiKey))) {
Expand All @@ -218,6 +220,7 @@ public FormValidation doTestConnection(@QueryParameter("targetApiKey") final Str
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doTestHostname(@QueryParameter("hostname") final String hostname){
if(DatadogUtilities.isValidHostname(hostname)) {
return FormValidation.ok("Great! Your hostname is valid.");
Expand All @@ -238,6 +241,7 @@ private boolean validateTargetApiURL(final String targetApiURL){
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetApiURL(@QueryParameter("targetApiURL") final String targetApiURL) {
if(!validateTargetApiURL(targetApiURL)) {
return FormValidation.error("The field must be configured in the form <http|https>://<url>/");
Expand All @@ -258,6 +262,7 @@ private boolean validateTargetLogIntakeURL(final String targetLogIntakeURL) {
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetLogIntakeURL(@QueryParameter("targetLogIntakeURL") final String targetLogIntakeURL) {
if (!validateTargetLogIntakeURL(targetLogIntakeURL)) {
return FormValidation.error("The field must be configured in the form <http|https>://<url>/");
Expand All @@ -279,6 +284,7 @@ private boolean validateTargetHost(String targetHost) {
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetHost(@QueryParameter("targetHost") final String targetHost) {
if (!validateTargetHost(targetHost)) {
return FormValidation.error("Invalid Host");
Expand All @@ -300,6 +306,7 @@ private boolean validateTargetPort(String targetPort) {
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetPort(@QueryParameter("targetPort") final String targetPort) {
if (!validateTargetPort(targetPort)) {
return FormValidation.error("Invalid Port");
Expand All @@ -321,6 +328,7 @@ private boolean validateTargetLogCollectionPort(String targetLogCollectionPort)
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetLogCollectionPort(@QueryParameter("targetLogCollectionPort") final String targetLogCollectionPort) {
if (!validateTargetLogCollectionPort(targetLogCollectionPort)) {
return FormValidation.error("Invalid Port");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
checked="${instance.reportWithEquals('DSD')}" inline="true">

<f:entry title="DogStatsD Host" field="targetHostEntry">
<f:textbox field="targetHost" default="${targetHost}" />
<f:textbox field="targetHost" default="${targetHost}" checkMethod="post" />
</f:entry>

<f:entry title="DogStatsD Port" field="targetPortEntry">
<f:textbox field="targetPort" default="${targetPort}" />
<f:textbox field="targetPort" default="${targetPort}" checkMethod="post" />
</f:entry>

<f:entry title="Log Collection Port" field="targetLogCollectionPortEntry">
<f:textbox field="targetLogCollectionPort" default="${targetLogCollectionPort}" />
<f:textbox field="targetLogCollectionPort" default="${targetLogCollectionPort}" checkMethod="post" />
</f:entry>

</f:radioBlock>

<f:radioBlock title="Use Datadog API URL and Key to report to Datadog (not recommended)" name="reportWith" value="HTTP"
checked="${instance.reportWithEquals('HTTP')}" inline="true">
checked="${instance.reportWithEquals('HTTP')}" inline="true" >

<f:entry title="Datadog API URL" field="targetApiURLEntry" description="URL which the plugin reports to." >
<f:textbox field="targetApiURL" default="${targetApiURL}" />
<f:textbox field="targetApiURL" default="${targetApiURL}" checkMethod="post" />
</f:entry>

<f:entry title="Datadog Log Intake URL" field="targetLogIntakeURLEntry" description="URL which the plugin reports logs to." >
<f:textbox field="targetLogIntakeURL" default="${targetLogIntakeURL}" />
<f:textbox field="targetLogIntakeURL" default="${targetLogIntakeURL}" checkMethod="post" />
</f:entry>

<f:entry title="Datadog API Key" field="targetApiKeyEntry">
<f:password field="targetApiKey" default="${targetApiKey}" />
<f:password field="targetApiKey" default="${targetApiKey}" checkMethod="post" />
</f:entry>
<f:validateButton title="${%Test Key}" progress="${%Testing...}" method="testConnection" with="targetApiKey" />
<f:validateButton title="${%Test Key}" progress="${%Testing...}" method="testConnection" with="targetApiKey" checkMethod="post" />

</f:radioBlock>

Expand All @@ -59,7 +59,7 @@
<f:entry title="Hostname" field="hostnameEntry">
<f:textbox field="hostname" default="${hostname}" />
</f:entry>
<f:validateButton title="${%Test Hostname}" progress="${%Testing...}" method="testHostname" with="hostname" />
<f:validateButton title="${%Test Hostname}" progress="${%Testing...}" method="testHostname" with="hostname" checkMethod="post" />

<f:entry title="Blacklisted Jobs" description="A comma-separated list of job names that should not monitored." >
<f:textarea field="blacklist" optional="true" default="${blacklist}" />
Expand Down