Skip to content
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

OSCAL 1.0.5 JSON schema uses allOf where anyOf is more appropriate #1773

Closed
laurelmay opened this issue Apr 24, 2023 · 11 comments
Closed

OSCAL 1.0.5 JSON schema uses allOf where anyOf is more appropriate #1773

laurelmay opened this issue Apr 24, 2023 · 11 comments
Assignees
Labels
Milestone

Comments

@laurelmay
Copy link
Contributor

Describe the bug

There are many fields with well-known values but that also "may be locally defined". In OSCAL v1.0.5's JSON schema, these are represented as allOf between an enum and the string-with-format data type. allOf requires that the data match all given schemas, effectively limiting values to only the enum. anyOf may be more appropriate.

For example https://pages.nist.gov/OSCAL/reference/1.0.5/catalog/json-reference/#/catalog/metadata/parties/external-ids/scheme is shown in JSON schema as

  { "title" : "External Identifier Schema",
                  "description" : "Indicates the type of external identifier.",
                  "allOf" : 
                  [ 
                    { "$ref" : "#/definitions/URIDatatype" },

                    { "enum" : 
                      [ "http://orcid.org/" ] } ] },

I found the commit view useful to see the difference.

See: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7

Who is the bug affecting

Consumers of the OSCAL JSON schema

What is affected by this bug

Tooling & API

How do we replicate this issue

Evaluate a value such as "https://example.com/" against the given field.

Expected behavior (i.e. solution)

The JSON schema should not reject valid data when the value "may be locally defined".

Other comments

For Draft 07, allOf (and friends) are defined the validation specification but have moved to Core in the latest spec.

For allOf:

An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value.

For `anyOf:

An instance validates successfully against this keyword if it validates successfully against at least one schema defined by this keyword's value.

Revisions

No response

@laurelmay laurelmay added the bug label Apr 24, 2023
@laurelmay
Copy link
Contributor Author

Better reproduction:

git clone --recursive https://github.com/usnistgov/oscal-content
git clone --recurisve https://github.com/usnistgov/OSCAL

npm install -g ajv-cli ajv-formats

ajv validate --spec=draft7 -c ajv-formats -s OSCAL/json/schema/oscal_catalog_schema.json -d oscal-content/nist.gov/SP800-53/rev5/json/NIST_SP-800-53_rev5_catalog.json
ajv validate --spec=draft7 -c ajv-formats -s OSCAL/json/schema/oscal_catalog_schema.json -d oscal-content/nist.gov/SP800-53/rev4/json/NIST_SP-800-53_rev4_catalog.json

ajv validate --spec=draft7 -c ajv-formats -s OSCAL/json/schema/oscal_profile_schema.json -d oscal-content/nist.gov/SP800-53/rev4/json/NIST_SP-800-53_rev4_MODERATE-baseline_profile.json

All of those ajv invocations will fail because the fields don't match a value in an enum because of the use of allOf.

Very aggressively changing all occurrences of allOf (which probably isn't correct in every case but should be good-enough for the specific validation failure):

sed -i'' -e 's/allOf/anyOf/g' OSCAL/json/schema/oscal_catalog_schema.json

you can then perform the catalog validations and see them succeed.

@GaryGapinski
Copy link

I attempted to find out why there are two allOf possibilities, considering the first (a URI) would suffice. My JSON schema expertise is minimal. Your observation regarding allOf appears correct.

So I attempted to find the XML equivalent and found it is not equivalent. It is just a URI (i.e., the only possibility).

The reproduction faults with allOf seem a bit odd since the instance documents each have one party, each of which has no external identifier defined. The reported locus of the fault seems to be displaced from parties (seems to be metadata prop):

gapinski@flexion-mac-C02FCBVSMD6N usnistgov % ajv validate --spec=draft7 -c ajv-formats -s OSCAL/json/schema/oscal_catalog_schema.json -d oscal-content/nist.gov/SP800-53/rev5/json/NIST_SP-800-53_rev5_catalog.json
oscal-content/nist.gov/SP800-53/rev5/json/NIST_SP-800-53_rev5_catalog.json invalid
[
  {
    instancePath: '/catalog/metadata/props/0/name',
    schemaPath: '#/properties/name/allOf/1/enum',
    keyword: 'enum',
    params: { allowedValues: [Array] },
    message: 'must be equal to one of the allowed values'
  }
]
gapinski@flexion-mac-C02FCBVSMD6N usnistgov % 

which has an analogous allOf with two subordinate items.

@laurelmay
Copy link
Contributor Author

@aj-stein-nist
Copy link
Contributor

aj-stein-nist commented May 3, 2023

I think the cause of this is one of the following:
...
The latter feels more likely but I am not sure whether it can be fixed by naively changing to anyOf or if it requires more logic like the former.

Sorry we hadn't responded. Yesterday I looked into this but I am still uncertain as to why it is happening in the context of OSCAL. For the referenced usnistgov/metaschema#253 PR, we specifically tested the implementation change to drop allow-other="yes" enumerations since it is obvious that you do not want to force the issue there. I was the one who wrote the tests for this, so ...

I guess it is back to the drawing board since it did not work as intended when running the updated codebase against OSCAL. I am glad you figured all this out and reported it here and the relevant issue. Kudos to you, @kylelaker.

@aj-stein-nist
Copy link
Contributor

Metaschema devs will need to look into the issue reported and determine where the bug is exactly and circle back on this, potentially in the next sprint or the one after.

@aj-stein-nist aj-stein-nist self-assigned this Jun 2, 2023
@aj-stein-nist aj-stein-nist moved this from Todo to In Progress in NIST OSCAL Work Board Jun 2, 2023
@aj-stein-nist
Copy link
Contributor

@JustKuzya, I know we discussed this earlier today during standup, but here is the PR feedback based on when you and I met with @nikitawootten-nist and paired.

usnistgov/metaschema#360 (review)

I am going to wait to hear back from @kylelaker to determine how we want to work together on the necessary unit tests to increase the coverage we were missing for this bit, and then the work is more or less done on this.

@aj-stein-nist aj-stein-nist moved this from In Progress to Blocked in NIST OSCAL Work Board Jun 2, 2023
@aj-stein-nist aj-stein-nist moved this from Blocked to In Progress in NIST OSCAL Work Board Jun 5, 2023
@aj-stein-nist
Copy link
Contributor

aj-stein-nist commented Jun 12, 2023

@JustKuzya and @nikitawootten-nist, let me know if you want to talk about perf testing this afternoon let me know. Well at least everyone got the right idea, I was alluding to the Metaschema change.

@aj-stein-nist aj-stein-nist moved this from In Progress to Under Review in NIST OSCAL Work Board Jun 12, 2023
@JustKuzya
Copy link
Contributor

JustKuzya commented Jun 12, 2023 via email

aj-stein-nist added a commit to aj-stein-nist/metaschema that referenced this issue Jun 15, 2023
Previously in usnistgov#360, @kylelaker reported a needed
improvement to fix a regression for usnistgov/OSCAL#1773. While I had
been completing testing in usnistgov#360 and properly expanding test coverage to
address how we handle enumerations based on allow-other and target
attributes for field and flag elements in Metaschema (both act similarly
but subtly different with more scenarios for field), I observed my test data
instances needed further correction in a way that cannot be address in the
PR by Kyle. This merges the changes from the commit reffed by the URL
below, adds my enhancement, tests, and all examples that helped me
uncover missing code.

usnistgov@6fb8a74

Co-authored-by: Kyle Laker <kyle@laker.email>
@aj-stein-nist aj-stein-nist moved this from Under Review to Blocked in NIST OSCAL Work Board Jun 16, 2023
@aj-stein-nist
Copy link
Contributor

Marking blocked until Metaschema PR reviewed and merged.

david-waltermire pushed a commit to usnistgov/metaschema that referenced this issue Jun 26, 2023
* Correct field and flag enumerations in JSON schemas.

Previously in #360, @kylelaker reported a needed
improvement to fix a regression for usnistgov/OSCAL#1773. While I had
been completing testing in #360 and properly expanding test coverage to
address how we handle enumerations based on allow-other and target
attributes for field and flag elements in Metaschema (both act similarly
but subtly different with more scenarios for field), I observed my test data
instances needed further correction in a way that cannot be address in the
PR by Kyle. This merges the changes from the commit reffed by the URL
below, adds my enhancement, tests, and all examples that helped me
uncover missing code.

6fb8a74

* Surpress bottlecaps.de link fail

More info below:
https://github.com/usnistgov/metaschema/actions/runs/5228171226/jobs/9440341454


Co-authored-by: Kyle Laker <kyle@laker.email>
@aj-stein-nist
Copy link
Contributor

#380 has been merged. Separate of the PR there, I also tested the pushed up models and confirm many of the enumerations across 4/7 models had flag and field enumerations correctly updated by diffing them with Oxygen and ignoring whitespace. The only changes were correct updates from allOf to anyOf. I will close this out once I pull up the Metaschema module and that is merged into a pending release branch.

@aj-stein-nist aj-stein-nist moved this from Blocked to In Progress in NIST OSCAL Work Board Jun 26, 2023
@aj-stein-nist aj-stein-nist moved this from In Progress to Under Review in NIST OSCAL Work Board Jun 27, 2023
aj-stein-nist added a commit that referenced this issue Jun 27, 2023
This PR commit will update the Metaschema submodule to update. We need
to update the underlying version of the MIMF to address the following:

Closes #1773.
Closes #1774.
aj-stein-nist added a commit that referenced this issue Jun 27, 2023
This PR commit will update the Metaschema submodule to update. We need
to update the underlying version of the MIMF to address the following:

Closes #1773.
Closes #1774.
aj-stein-nist added a commit that referenced this issue Jun 28, 2023
* Update metaschema for 1.0.6 release

This PR commit will update the Metaschema submodule to update. We need
to update the underlying version of the MIMF to address the following:

Closes #1773.
Closes #1774.

* Fix Metaschema XML schema URL

Per @nikita-wootten-nist's feedback, fix this URL which has not been updated in either
develop or main branches as the Metaschema 0.9.0 and directory restructuring occurred
during the course of the drafting of the 1.0.6 release.
@aj-stein-nist aj-stein-nist moved this from Under Review to Done in NIST OSCAL Work Board Jun 28, 2023
@aj-stein-nist
Copy link
Contributor

Closing with 1.0.6. pre-release.

aj-stein-nist added a commit that referenced this issue Jul 10, 2023
* Update metaschema for 1.0.6 release

This PR commit will update the Metaschema submodule to update. We need
to update the underlying version of the MIMF to address the following:

Closes #1773.
Closes #1774.

* Fix Metaschema XML schema URL

Per @nikita-wootten-nist's feedback, fix this URL which has not been updated in either
develop or main branches as the Metaschema 0.9.0 and directory restructuring occurred
during the course of the drafting of the 1.0.6 release.
@aj-stein-nist aj-stein-nist added this to the v1.0.6 milestone Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

5 participants