当前位置:   article > 正文

ESAPI使用_esapi怎么用

esapi怎么用

依赖

<dependency>
    <groupId>org.owasp.esapi</groupId>
    <artifactId>esapi</artifactId>
    <version>2.2.3.1</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

ESAPI.properties

  1. ESAPI.printProperties=true
  2. # 这个地方是配置ESAPI的实现类,项目中用到那个就选择性配置即可
  3. ESAPI.Encoder=org.owasp.esapi.reference.DefaultEncoder
  4. ESAPI.Validator=org.owasp.esapi.reference.DefaultValidator
  5. # 以下是选择性配置,可以在官网找到对应的介绍
  6. ESAPI.Logger=org.owasp.esapi.logging.java.JavaLogFactory
  7. Encoder.AllowMultipleEncoding=false
  8. Encoder.AllowMixedEncoding=false
  9. Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
  10. Logger.ApplicationName=ExampleApplication
  11. Logger.LogEncodingRequired=false
  12. Logger.LogApplicationName=true
  13. Logger.LogServerIP=true
  14. Logger.LogFileName=ESAPI_logging_file
  15. Logger.MaxLogFileSize=10000000
  16. Logger.UserInfo=true
  17. Logger.ClientInfo=true

validator.properties

  1. # The ESAPI validator does many security checks on input, such as canonicalization
  2. # and whitelist validation. Note that all of these validation rules are applied *after*
  3. # canonicalization. Double-encoded characters (even with different encodings involved,
  4. # are never allowed.
  5. #
  6. # To use:
  7. #
  8. # First set up a pattern below. You can choose any name you want, prefixed by the word
  9. # "Validation." For example:
  10. # Validation.Email=^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,4}$
  11. #
  12. # Then you can validate in your code against the pattern like this:
  13. # ESAPI.validator().isValidInput("User Email", input, "Email", maxLength, allowNull);
  14. # Where maxLength and allowNull are set for you needs, respectively.
  15. #
  16. # But note, when you use boolean variants of validation functions, you lose critical
  17. # canonicalization. It is preferable to use the "get" methods (which throw exceptions) and
  18. # and use the returned user input which is in canonical form. Consider the following:
  19. #
  20. # try {
  21. # someObject.setEmail(ESAPI.validator().getValidInput("User Email", input, "Email", maxLength, allowNull));
  22. #
  23. Validator.SafeString=^[.\\p{Alnum}\\p{Space}]{0,1024}$
  24. Validator.Email=^[A-Za-z0-9._%'-]+@[A-Za-z0-9.-]+\\.[a-zA-Z]{2,4}$
  25. Validator.IPAddress=^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
  26. Validator.URL=^(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\:\\'\\/\\\\\\+=&;%\\$#_]*)?$
  27. Validator.CreditCard=^(\\d{4}[- ]?){3}\\d{4}$
  28. Validator.SSN=^(?!000)([0-6]\\d{2}|7([0-6]\\d|7[012]))([ -]?)(?!00)\\d\\d\\3(?!0000)\\d{4}$

esapi-java-logging.properties

  1. handlers= java.util.logging.ConsoleHandler.level= INFO
  2. java.util.logging.ConsoleHandler.level = INFO
  3. java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  4. java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%3$-7s] %5$s %n

测试

  1. public static void main(String[] args) {
  2. System.out.println("======="+ESAPI.encoder().encodeForHTML("<a href='sdfs'></a> < script > alert(); </ script >"));
  3. }

官网地址

OWASP Enterprise Security API (ESAPI) | OWASP Foundation

WEB安全编程技术规范

https://wenku.baidu.com/view/c24d4e642af90242a895e588.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/150502
推荐阅读
相关标签
  

闽ICP备14008679号