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

Improving handling of XCCDF fields that may contain HTML #4971

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4,854 changes: 2,400 additions & 2,454 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel7-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6,472 changes: 3,236 additions & 3,236 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel8-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4,677 changes: 2,349 additions & 2,328 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel7-hdf.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6,472 changes: 3,236 additions & 3,236 deletions libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel8-hdf.json

Large diffs are not rendered by default.

96 changes: 62 additions & 34 deletions libs/hdf-converters/src/xccdf-results-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export class XCCDFResultsMapper extends BaseConverter {
path: 'Benchmark.reference.publisher'
},
summary: {
path: ['Benchmark.description.text', 'Benchmark.description']
path: ['Benchmark.description.text', 'Benchmark.description'],
transformer: parseHtml
},
description: {
path: 'Benchmark',
Expand Down Expand Up @@ -293,7 +294,11 @@ export class XCCDFResultsMapper extends BaseConverter {
for (const path of paths) {
const item = _.get(input, path);
if (item !== undefined) {
fullDescription[path] = item;
if (typeof item === 'string') {
fullDescription[path] = parseHtml(item);
} else {
fullDescription[path] = item;
}
}
}
}
Expand Down Expand Up @@ -327,22 +332,26 @@ export class XCCDFResultsMapper extends BaseConverter {
description: {
path: ['description.text', 'description'],
transformer: (description: string): string =>
_.get(
parseXml(description),
'VulnDiscussion',
description
) as string
parseHtml(
_.get(
parseXml(description),
'VulnDiscussion',
description
) as string
)
},
group_id: {path: 'group.id'},
group_title: {path: ['group.title.text', 'group.title']},
group_description: {
path: ['group.description.text', 'group.description'],
transformer: (description: string): string =>
_.get(
parseXml(description),
'GroupDescription',
description
) as string
parseHtml(
_.get(
parseXml(description),
'GroupDescription',
description
) as string
)
},
rule_id: {path: 'id'},
check: {
Expand All @@ -354,7 +363,7 @@ export class XCCDFResultsMapper extends BaseConverter {
fix_id: {path: 'fix.id'},
fixtext_fixref: {
path: ['fixtext.fixref.text', 'fixtext.fixref'],
transformer: (text: string) => text || undefined
transformer: (text: string) => parseHtml(text) || undefined
},
ident: {
path: 'ident',
Expand All @@ -375,11 +384,13 @@ export class XCCDFResultsMapper extends BaseConverter {
description: {
path: ['description.text', 'description'],
transformer: (description: string): string =>
_.get(
parseXml(description),
'ProfileDescription',
description
) as string
parseHtml(
_.get(
parseXml(description),
'ProfileDescription',
description
) as string
)
},
title: {path: ['title.text', 'title']}
}
Expand All @@ -393,12 +404,14 @@ export class XCCDFResultsMapper extends BaseConverter {
values: Record<string, unknown> | Record<string, unknown>[]
) =>
asArray(values).map((value) => ({
title: _.get(value, 'title'),
description:
title: _.get(value, 'title.text') || _.get(value, 'title'),
description: parseHtml(
_.get(value, 'description.text') ||
_.get(value, 'description'),
warning:
_.get(value, 'warning.text') || _.get(value, 'warning'),
_.get(value, 'description')
),
warning: parseHtml(
_.get(value, 'warning.text') || _.get(value, 'warning')
),
value: _.get(value, 'value'),
Id: _.get(value, 'Id'),
id: _.get(value, 'id'),
Expand Down Expand Up @@ -466,11 +479,13 @@ export class XCCDFResultsMapper extends BaseConverter {
desc: {
path: ['description.text', 'description'],
transformer: (description: string): string =>
_.get(
parseXml(description),
'ProfileDescription',
description
) as string
parseHtml(
_.get(
parseXml(description),
'ProfileDescription',
description
) as string
)
},
descriptions: [
{
Expand Down Expand Up @@ -553,11 +568,13 @@ export class XCCDFResultsMapper extends BaseConverter {
code_desc: {
path: ['description.text', 'description'],
transformer: (description: string): string =>
_.get(
parseXml(description),
'VulnDiscussion',
description
) as string
parseHtml(
_.get(
parseXml(description),
'VulnDiscussion',
description
) as string
)
},
start_time: {
path: ['ruleResult.time']
Expand Down Expand Up @@ -603,7 +620,18 @@ export class XCCDFResultsMapper extends BaseConverter {
}
};
constructor(scapXml: string, withRaw = false) {
super(parseXml(scapXml));
super(
parseXml(scapXml, {
stopNodes: [
'*.fixtext',
'*.fix',
'*.rationale',
'*.warning',
'*.title',
'*.description'
]
})
);
this.withRaw = withRaw;
}
}