-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release/2.8.0' into fix/#2116_XS…
…S_Vulnerabilities_in_2_8
- Loading branch information
Showing
24 changed files
with
547 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
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
21 changes: 21 additions & 0 deletions
21
src/org/scada_lts/web/beans/validation/xss/XssConstraintValidator.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,21 @@ | ||
package org.scada_lts.web.beans.validation.xss; | ||
|
||
import org.scada_lts.serorepl.utils.StringUtils; | ||
import org.scada_lts.web.beans.validation.AbstractConstraintValidator; | ||
import org.scada_lts.web.beans.validation.ScadaValidator; | ||
|
||
public class XssConstraintValidator extends AbstractConstraintValidator<XssProtect, String> { | ||
|
||
@Override | ||
public void beforeValidate(String value) throws Exception { | ||
if (StringUtils.isEmpty(value)) { | ||
throw new XssValidatorException("Input is empty"); | ||
} | ||
} | ||
|
||
@Override | ||
public void validate(String value) throws Exception { | ||
ScadaValidator<String> validator = new XssValidator(); | ||
validator.validate(value); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/org/scada_lts/web/beans/validation/xss/XssProtect.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,15 @@ | ||
package org.scada_lts.web.beans.validation.xss; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Constraint(validatedBy = XssConstraintValidator.class) | ||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface XssProtect { | ||
String message() default "Potential XSS detected in the request body."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/org/scada_lts/web/beans/validation/xss/XssValidator.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,15 @@ | ||
package org.scada_lts.web.beans.validation.xss; | ||
|
||
import org.scada_lts.web.beans.validation.ScadaValidator; | ||
|
||
import static org.scada_lts.web.security.XssUtils.validateHttpBody; | ||
|
||
public class XssValidator implements ScadaValidator<String> { | ||
|
||
@Override | ||
public void validate(String input) throws XssValidatorException { | ||
if(!validateHttpBody(input)) { | ||
throw new XssValidatorException("Potential XSS attack detected"); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/org/scada_lts/web/beans/validation/xss/XssValidatorException.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,25 @@ | ||
package org.scada_lts.web.beans.validation.xss; | ||
|
||
import org.scada_lts.web.beans.validation.ScadaValidatorException; | ||
|
||
public class XssValidatorException extends ScadaValidatorException { | ||
|
||
public XssValidatorException() { | ||
} | ||
|
||
public XssValidatorException(String message) { | ||
super(message); | ||
} | ||
|
||
public XssValidatorException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public XssValidatorException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public XssValidatorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
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
Oops, something went wrong.