簡體   English   中英

SPEL 如何防范注入攻擊

[英]SPEL how to protect against injection attacks

一些像這樣的代碼

    StandardEvaluationContext context = new StandardEvaluationContext();
    context.addPropertyAccessor(new EmptyValueMapAccessor());
    context.addPropertyAccessor(new MapAccessor());
    context.addPropertyAccessor(DataBindingPropertyAccessor.forReadOnlyAccess());
    ExpressionParser paser = new SpelExpressionParser();
    Expression expression = paser.parseExpression("#{T(java.lang.System).exit(0)}", new TemplateParserContext());
    expression.getValue(context,obj);

它將執行exit方法。

改用SimpleEvaluationContext - 它是專門為此目的而設計的。

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-evaluation-context

SimpleEvaluationContext旨在僅支持 SpEL 語言語法的一個子集。 它不包括 Java 類型引用、構造函數和 bean 引用。 它還要求您明確選擇對表達式中的屬性和方法的支持級別。 默認情況下,create() 靜態工廠方法僅啟用對屬性的讀取訪問。 您還可以獲得構建器來配置所需的確切支持級別,針對以下一項或某些組合:

  • 僅自定義 PropertyAccessor(無反射)
  • 只讀訪問的數據綁定屬性
  • 用於讀取和寫入的數據綁定屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM