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

Improve xccdf_results_mapper when converting XCCDF Results to HDF Results #4255

Merged
merged 28 commits into from
Jul 13, 2023

Conversation

candrews
Copy link
Contributor

Bug: mitre/saf#1163
Fixes: #4194

@candrews candrews force-pushed the xccdf_results_mapper-improvements branch 2 times, most recently from dfeb1a9 to 326a8ba Compare March 24, 2023 04:02
@em-c-rod em-c-rod requested review from Amndeep7 and Hookwitz March 24, 2023 15:39
@aaronlippold aaronlippold added enhancement New feature or request Community Contribution Contribution from the open source community labels Mar 27, 2023
@aaronlippold
Copy link
Member

Hi the team @Amndeep7 @em-c-rod @wdower @Hookwitz @georgedias are looking over this and seeing if some of our other PR work can be rolled into this as well.

A couple questions:

  • Given some of the changes that were make, would we be able to make some smaller unit tests that cover actual function @em-c-rod @Amndeep7 @candrews
  • Should we add test data for other XCCDF profiles -windows, Ubuntu, DB, IIS, etc or would a subset of XCCDF content element likely be sufficient
  • Have we seen any corner cases - nesting, tags inside tags, etc - that we should make specific tests for?

@aaronlippold
Copy link
Member

@candrews looks like SonarCloud is also unhappy about something - which we may want to poke at as well as doing a rebase from master/main

@aaronlippold
Copy link
Member

Question: Is any of the work here also useful or overtaken by this PR? #2958

@candrews candrews force-pushed the xccdf_results_mapper-improvements branch 3 times, most recently from 592a324 to 47f4747 Compare March 31, 2023 16:35
@candrews
Copy link
Contributor Author

looks like SonarCloud is also unhappy about something - which we may want to poke at as well as doing a rebase from master/main

I fixed the SonarCloud findings. The only finding now is in the test for a comment (the same comment is in every other test, so I think it should be in this one as well) and I believe that finding should be suppressed.

@candrews
Copy link
Contributor Author

Question: Is any of the work here also useful or overtaken by this PR? #2958

This PR completely supersedes #2958 - it does everything that PR does and more.

@candrews
Copy link
Contributor Author

candrews commented Apr 4, 2023

Can I do something to help this along?

I'd really like to have these issues fixed soon as it's blocking progress on a project which is import to my corporate overlords.

@Amndeep7
Copy link
Contributor

Amndeep7 commented Apr 7, 2023

Sorry for the delay @candrews - could you address the findings for the HDF-Converters tests? It seems like some of the other XML mappers such as the Veracode are now having issues.

Also now that I've enabled workflows in the repo, they should continue to be enabled for this PR, but shoot me a ping if they aren't after you push up some changes.

@Amndeep7
Copy link
Contributor

Amndeep7 commented Apr 7, 2023

Another point that I wanted to bring up was that we were intending on eventually rewriting this mapper to use jsonix to be able to match against the XCCDF schema properly instead of using the fast-xml-parser which has issues with (for example) determining the difference between singular nodes and arrays of length one. This isn't a request for you to rework this entire PR to use that other library, just a heads up about part of the delay in dealing with this mapper since we're still exploring how to use jsonix and write a mapper properly with it in our checklist mapper work (#3859).

@Amndeep7
Copy link
Contributor

Amndeep7 commented Apr 7, 2023

Still need to finish reading/reviewing the code, which I'll try to do next week.

Also @candrews - it would be really nice if we could arrange a meeting to discuss how you and your corporate overlords are using HDF-Converters / the SAF. We don't do any tracking, so we gotta go the old fashioned way and actually talk to our users in order to learn how/why they're using our stuff, and what we could do to deepen the partnership.

If you could email me at [email protected] with some dates/times that you/your team/your management chain are available, I'd appreciate it a lot.

@mergify
Copy link
Contributor

mergify bot commented Apr 12, 2023

This pull request has a conflict. Could you fix it @candrews?

@candrews candrews force-pushed the xccdf_results_mapper-improvements branch from 47f4747 to adf7131 Compare April 13, 2023 01:43
@candrews
Copy link
Contributor Author

This pull request has a conflict. Could you fix it @candrews?

I've addressed the conflict.

@candrews
Copy link
Contributor Author

@Amndeep7 I believe that I have addressed all the feedback.

As you know, I'm not terribly familiar with the heimdall tool, but with that disclaimer, I think the output looks good and is definitely improvement over when we last looked at this together.

Can you please take another look and let me know what else needs to be done?

Copy link
Contributor

@Amndeep7 Amndeep7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feeling like this should probably be able to be merged in after this final set of changes is made. Thanks for bearing with the process for so long.

libs/hdf-converters/src/xccdf-results-mapper.ts Outdated Show resolved Hide resolved
.map((x) => x.text)
.map(parse_nist)
.filter((x) => !!x)
.filter(is_control)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like your sample is not updated properly still? or this function is borked lol

xccdf-scc-rhel7-hdf.json

image

seems like the nist tag array is including the stig control ids, which it shouldn't do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_control(parse_nist('SV-86515')) return true... so as far as inspectjs is concerned, 'SV-86515' is a nist control and therefore should be included.

Am I misunderstanding nist.js? How should I determine if an item should be included or excluded from this list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like a failure on inspecjs' part in not removing things that are clearly wrong. parse_nist should throw errors/explicitly fail when they are not nist controls/control families. it not doing so confuses the type system by mistakenly typing that string. is_control more or less is only used to narrow down types and doesn't do much actual validation.

anyways as shown there and in 'raw_nist.ts', nist controls look like 'two_letter_family-small_number possibly followed by letters and numbers in parentheses' whereas stig ids are 'S?V-5__or_6_digit_number'.

the issue that arose here is that it thinks 'sv' is a control family and then processes the numbers after it as like 'control "big number" from within that control family' but doesn't take into account the reality of the situation where 'sv' is not a valid control family nor is there a control with an index as high as '86515' in existence.

looking briefly, it seems like the regexes that parse_nist uses are vastly broader than the actually allowed set of inputs. i will experiment to see if it's possible to restrict it to allowed control families.

@candrews
Copy link
Contributor Author

candrews commented Jun 21, 2023

Using stopNodes would be a great way to fix the parsing problem that occurs with nodes that contain HTML.

However... stopNodes doesn't work for XML documents that use namespaces: https://github.com/NaturalIntelligence/fast-xml-parser/blob/v4.2.4/src/xmlparser/OrderedObjParser.js#L308 Attempting to use it results in an "Unexpected end of " error. I reported this issue at NaturalIntelligence/fast-xml-parser#607

If this issue in the xml parser is fixed, then modifying xccdf-results-mapper.ts to say:

  constructor(scapXml: string, withRaw = false) {
    super(
      parseXml(scapXml, {
        stopNodes: [
          '*.fixtext',
          '*.fix',
          '*.rationale',
          '*.warning',
          '*.title',
          '*.description'
        ]
      })
    );

would solve the html parsing problem.

libs/inspecjs/src/nist.ts Show resolved Hide resolved
libs/inspecjs/src/nist.ts Outdated Show resolved Hide resolved
@candrews
Copy link
Contributor Author

candrews commented Jul 6, 2023

@Amndeep7 do you have a guess as to when we'll be able to progress this PR?

@Amndeep7
Copy link
Contributor

Amndeep7 commented Jul 7, 2023

Sorry I've been swamped this week. I'll try to take a look next week to fix that bug in Heimdall that I mentioned.

Amndeep7 added 4 commits July 12, 2023 22:59
…t zero-padded. also changed default behaviors so there's no need to supply a parameter to the canonize function at all.

Signed-off-by: Amndeep Singh Mann <[email protected]>
…file, it makes no sense to have that replicated here anymore really - there are some particularly egregious cases too where a control is replicated at least 3 times in the array

Signed-off-by: Amndeep Singh Mann <[email protected]>
Signed-off-by: Amndeep Singh Mann <[email protected]>
@mergify
Copy link
Contributor

mergify bot commented Jul 13, 2023

This pull request has a conflict. Could you fix it @candrews?

@Amndeep7 Amndeep7 added the ready-to-merge Used by mergify to identify if a PR is ready to merge into master. label Jul 13, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mergify mergify bot merged commit fca56fe into mitre:master Jul 13, 2023
@Amndeep7
Copy link
Contributor

Thank you for your patience and hard work on this PR @candrews. You did some absolutely fantastic work here that'll be appreciated across many of the users of Heimdall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution Contribution from the open source community enhancement New feature or request Needs Review ready-to-merge Used by mergify to identify if a PR is ready to merge into master.
Projects
None yet
6 participants