代码之家  ›  专栏  ›  技术社区  ›  Blanca Hdez

重写ESAPI OWASP方法java

  •  0
  • Blanca Hdez  · 技术社区  · 13 年前

    我正试图通过使用重写ESAPI OWASP库中的现有方法 ESAPI.override() 。不知怎么的,它不起作用,你知道为什么吗?

    这里是我的代码:

    public class AntiSamyDOMScannerExpansion extends AbstractAntiSamyScanner {
    
    //...
    public CleanResults scan(String html, String inputEncoding, String outputEncoding) throws ScanException {
            ESAPI.override(new DefaultSecurityConfiguration());
    //...
    
    1 回复  |  直到 13 年前
        1
  •  0
  •   Blanca Hdez    13 年前

    ESAPI.override() 仅用于覆盖配置。为了扩展其他类型的方法,在我的情况下 AntiSamy.scan ,需要扩展调用结构中的每个类。
    这是因为执行不灵活。例如,我们在 HTMLValidationRule.java 以下为:

    private String invokeAntiSamy( String context, String input ) throws ValidationException {
            // CHECKME should this allow empty Strings? "   " us IsBlank instead?
            if ( StringUtilities.isEmpty(input) ) {
                if (allowNull) {
                    return null;
                }
                throw new ValidationException( context + " is required", "AntiSamy validation error: context=" + context + ", input=" + input, context );
            }
    
            String canonical = super.getValid( context, input );
    
            try {
                AntiSamy as = new AntiSamy();
                CleanResults test = as.scan(canonical, antiSamyPolicy);
    
                List<String> errors = test.getErrorMessages();
                if ( !errors.isEmpty() ) {
                    LOGGER.info( Logger.SECURITY_FAILURE, "Cleaned up invalid HTML input: " + errors );
                }
    
                return test.getCleanHTML().trim();
    
            } catch (ScanException e) {
                throw new ValidationException( context + ": Invalid HTML input", "Invalid HTML input: context=" + context + " error=" + e.getMessage(), e, context );
            } catch (PolicyException e) {
                throw new ValidationException( context + ": Invalid HTML input", "Invalid HTML input does not follow rules in antisamy-esapi.xml: context=" + context + " error=" + e.getMessage(), e, context );
            }
        }
    

    由于 AntiSamy as = new AntiSamy(); 我们无法使其在自定义实现中可用。