Henri Biestro created JEXL-475:
----------------------------------

             Summary:  A jexl.options pragma modifies the engine options when 
evaluated with a plain context
                 Key: JEXL-475
                 URL: https://issues.apache.org/jira/browse/JEXL-475
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 3.7.0
            Reporter: Henri Biestro
            Assignee: Henri Biestro
             Fix For: 3.7.2


When a script declaring a {{jexl.options}} pragma is evaluated with a context 
that does not implement {{JexlContext.OptionsHandle}} (a {{MapContext}} or 
null), the pragma flags are applied to the engine's own options instance.

The modification persists: every subsequent evaluation on that engine, from any 
thread, runs with the pragma's flags.
{code:java}
  JexlEngine jexl = new 
JexlBuilder().features(JexlFeatures.createDefault().pragma(true)).strict(true).create();
  MapContext ctxt = new MapContext();
  ctxt.set("a.b", 42);
  jexl.createScript("a.b").execute(ctxt);                                  // 42
  jexl.createScript("#pragma jexl.options '-antish'\na.b").execute(ctxt);  // 
JexlException.Property, as expected
  jexl.createScript("a.b").execute(ctxt);                                  // 
JexlException.Property, expected 42
  {code}
Cause: {{Engine.evalOptions(JexlContext)}} returns the engine options instance 
as-is when the context
does not provide options; {{Engine.evalOptions(ASTJexlScript, JexlContext)}} 
then calls
{{processPragmas(script, context, opts)}} which calls {{opts.setFlags(...)}} on 
that instance.

The engine options are not a shared instance 
({{{}JexlOptions.isSharedInstance(){}}} is false by default) and
the rest of {{evalOptions}} assumes they are never modified at runtime 
(feature-driven settings are only
re-applied when {{{}opts != options{}}}).

Any flag can leak this way (strict, safe, silent, lexical, antish, ...). 
Pragmas are disabled by default
since 3.7, which limits exposure to engines that explicitly enable them.

Suggested fix: when the options to be modified by pragmas are the engine 
options, copy them before
processing the pragmas.
{code:java}
 {code}



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to