Skip to content

Commit 619c686

Browse files
Copilotnomeguy
andcommitted
Final security improvements: sanitize logging and clarify optimization level
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
1 parent 4383fb7 commit 619c686

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/java/org/casbin/jcasbin/util/ExpressionEvaluator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public static AviatorEvaluatorInstance configureRestrictedEvaluator(AviatorEvalu
8080
java.util.Set<com.googlecode.aviator.Feature> restrictedFeatures = java.util.Collections.emptySet();
8181
aviatorEval.setOption(Options.FEATURE_SET, restrictedFeatures);
8282

83-
// Use optimized mode for better performance
83+
// Use EVAL optimization level: This provides compile-once execution for expressions.
84+
// EVAL is the most basic optimization level that compiles expressions without
85+
// aggressive optimizations, providing a balance between safety and performance.
8486
aviatorEval.setOption(Options.OPTIMIZE_LEVEL, com.googlecode.aviator.AviatorEvaluator.EVAL);
8587

8688
return aviatorEval;

src/main/java/org/casbin/jcasbin/util/function/EvalFunc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
4242
ExpressionEvaluator.validateExpression(eval);
4343
} catch (IllegalArgumentException e) {
4444
// Log at ERROR level for security violations to ensure visibility
45-
Util.logPrintfError("Security violation - invalid eval expression rejected: {}", e.getMessage());
45+
// Do not log the full expression to avoid exposing potentially malicious content
46+
Util.logPrintfError("Security violation - invalid eval expression rejected. " +
47+
"Expression contains non-standard Casbin operations that are not allowed.");
4648
// Return false to fail safely rather than throwing, which could break policy evaluation
4749
return AviatorBoolean.valueOf(false);
4850
}

0 commit comments

Comments
 (0)