-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are conditional expressions that have test expressions without parentheses valid Metapath? #258
Comments
Given the expression
Given a correct statement
It would be helpful to look into the how to adjust the grammar to deal with failing the error case. Here is a quick test for doing this using metaschema-java: Metapath10Lexer lexer = new Metapath10Lexer(CharStreams.fromString("if ('a' = '1.1.2') then true() else false()"));
lexer.removeErrorListeners();
lexer.addErrorListener(new FailingErrorListener());
CommonTokenStream tokens = new CommonTokenStream(lexer);
Metapath10 parser = new Metapath10(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new FailingErrorListener());
parser.setErrorHandler(new DefaultErrorStrategy() {
@Override
public void sync(Parser recognizer) {
// disable
}
});
ParseTree tree = ObjectUtils.notNull(parser.expr());
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
try (PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8)) {
ParseTreePrinter printer = new ParseTreePrinter(ps);
printer.print(tree, Metapath10.ruleNames);
ps.flush();
}
System.out.println(String.format("Metapath AST:%n%s", os.toString(StandardCharsets.UTF_8)));
} |
Turns out this is caused here: metaschema-java/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java Line 136 in 964b845
This is parsing the
It should be parsing
This one line change will fix the issue. |
… used if the first part was seen as valid. Fixes metaschema-framework#258
Describe the bug
Per previous discussion with the FedRAMP developer team, metaschema-java 2.2.0 (as released with
oscal-cli
2.3.1) allows conditional Metapath expressions where the test expression after theif
does not have parentheses. According to my read of the spec, the EBNF specifies that behavior is non-conformant.Who is the bug affecting
Developers using conditonal logic for Metapath constraints'
test
attribute.How do we replicate this issue
Integration and/or unit tests TBD. For now, reveiw the following OSCAL-specific example in the FedRAMP developer team's notes page in the wiki with a simple constraint module with one constraint and a sample file.
The sample SSP:
Validation completes but with a constraint violation error with the document instance above (there are no library exceptions, evaluation completes).
The above constraint also, when violated, has a DEBUG value of 1.1.2, meaning the constraint should not be violated.
The issue is resolved when the test expression properly uses parens.
Expected behavior (i.e. solution)
When usng invalid test expression syntax, the Metaschema process in metaschema-java returns an exception indicating the syntax is invalid.
Other comments
No response
The text was updated successfully, but these errors were encountered: