Skip to content

Commit

Permalink
Fix oscal bugs (#329)
Browse files Browse the repository at this point in the history
* fix oscal bugs

* linting
  • Loading branch information
northdpole authored Jul 15, 2023
1 parent d5fccbd commit b5ec17d
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 87 deletions.
56 changes: 28 additions & 28 deletions application/frontend/src/components/DocumentNode/DocumentNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import './documentNode.scss';
import axios from 'axios';
import React, { FunctionComponent, useContext, useEffect, useMemo, useState } from 'react';
import { Link, useHistory } from 'react-router-dom';
import { Icon } from 'semantic-ui-react';

import {
TYPE_CONTAINS,
TYPE_IS_PART_OF,
TYPE_RELATED,
} from '../../const';
import { TYPE_CONTAINS, TYPE_IS_PART_OF, TYPE_RELATED } from '../../const';
import { useEnvironment } from '../../hooks';
import { applyFilters } from '../../hooks/applyFilters';
import { Document } from '../../types';
import { getDocumentDisplayName, groupLinksByType } from '../../utils';
import { getApiEndpoint, getDocumentTypeText, getInternalUrl } from '../../utils/document';
import { FilterButton } from '../FilterButton/FilterButton';
import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator';
import { Icon } from 'semantic-ui-react';

export interface DocumentNode {
node: Document;
Expand Down Expand Up @@ -107,9 +103,9 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({
}

return (
<a href={hyperlink.hyperlink} target="_blank">
<Icon name="external" />
</a>
<a href={hyperlink.hyperlink} target="_blank">
<Icon name="external" />
</a>
);
};
const SimpleView = () => {
Expand All @@ -118,7 +114,7 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({
<div className={`title external-link document-node f2`}>
<Link to={getInternalUrl(usedNode)}>
<i aria-hidden="true" className="circle icon"></i>
{getDocumentDisplayName(usedNode)}
{getDocumentDisplayName(usedNode)}
</Link>
<HyperlinkIcon hyperlink={usedNode.hyperlink} />
</div>
Expand All @@ -139,30 +135,34 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({
<Hyperlink hyperlink={usedNode.hyperlink} />
{expanded &&
getTopicsToDisplayOrderdByLinkType().map(([type, links], idx) => {
const sortedResults = links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document)))
let lastDocumentName = sortedResults[0].document.name
const sortedResults = links.sort((a, b) =>
getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))
);
let lastDocumentName = sortedResults[0].document.name;
return (
<div className="document-node__link-type-container" key={type}>
{idx > 0 && <hr style={{backgroundColor: "transparent", border: "none"}}/>}
{idx > 0 && <hr style={{ backgroundColor: 'transparent', border: 'none' }} />}
<div>
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:{/* Risk here of mixed doctype in here causing odd output */}
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
{/* Risk here of mixed doctype in here causing odd output */}
</div>
<div>
<div className="accordion ui fluid styled f0">
{sortedResults.map((link, i) =>{const temp = (
<div key={Math.random()}>
{lastDocumentName !== (link.document.name) &&<span style={{margin:"5px"}}/>}
<DocumentNode
node={link.document}
linkType={type}
hasLinktypeRelatedParent={isNestedInRelated()}
key={Math.random()}
/>
<FilterButton document={link.document} />
</div>
)
lastDocumentName = link.document.name
return temp;
{sortedResults.map((link, i) => {
const temp = (
<div key={Math.random()}>
{lastDocumentName !== link.document.name && <span style={{ margin: '5px' }} />}
<DocumentNode
node={link.document}
linkType={type}
hasLinktypeRelatedParent={isNestedInRelated()}
key={Math.random()}
/>
<FilterButton document={link.document} />
</div>
);
lastDocumentName = link.document.name;
return temp;
})}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,30 @@ export const CommonRequirementEnumeration = () => {
<div className="cre-page__links-container">
{Object.keys(linksByType).length > 0 &&
Object.entries(linksByType).map(([type, links]) => {
const sortedResults = links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document)))
let lastDocumentName = sortedResults[0].document.name
const sortedResults = links.sort((a, b) =>
getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))
);
let lastDocumentName = sortedResults[0].document.name;
return (
<div className="cre-page__links" key={type}>
<div className="cre-page__links-eader">
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:{/* Risk here of mixed doctype in here causing odd output */}
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
{/* Risk here of mixed doctype in here causing odd output */}
</div>
{sortedResults.map((link, i) => {
const temp = (
<div key={i} className="accordion ui fluid styled cre-page__links-container">
{lastDocumentName !== (link.document.name) && <span style={{ margin: "5px" }} />}
{lastDocumentName !== link.document.name && <span style={{ margin: '5px' }} />}
<DocumentNode node={link.document} linkType={type} />
<FilterButton document={link.document} />
</div>
)
lastDocumentName = link.document.name
return temp
);
lastDocumentName = link.document.name;
return temp;
})}
</div>
)})}
);
})}
</div>
</>
)}
Expand Down
6 changes: 4 additions & 2 deletions application/frontend/src/pages/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export const Search = () => {
Your gateway to security topics
</Header>
<div>
<SearchBar />
<Button primary fluid href="/root_cres">Browse Topics</Button>
<SearchBar />
<Button primary fluid href="/root_cres">
Browse Topics
</Button>
</div>
<SearchBody />
</div>
Expand Down
10 changes: 7 additions & 3 deletions application/frontend/src/pages/Search/components/BodyText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export const SearchBody = () => {
</p>
<p>
OpenCRE currently links OWASP standards (Top 10, ASVS, Proactive Controls, Cheat sheets, Testing
guide, ZAP, SAMM), plus several other sources (CWE, CAPEC, NIST-800 53, NIST-800 63b, Cloud Control Matrix,
ISO27001, ISO27002, NIST SSDF, and PCI-DSS).
guide, ZAP, SAMM), plus several other sources (CWE, CAPEC, NIST-800 53, NIST-800 63b, Cloud Control
Matrix, ISO27001, ISO27002, NIST SSDF, and PCI-DSS).
</p>
<p>
Contact us via (rob.vanderveer [at] owasp.org) to join the movement. Currently, a stakeholder group is
Expand All @@ -61,7 +61,11 @@ export const SearchBody = () => {
<p>
For more details, see this
<a href="https://www.youtube.com/watch?v=7knF14t0Svg"> presentation video</a>, read the
<a href="https://github.com/OWASP/www-project-integration-standards/raw/master/writeups/CRE-Explained6.pdf">{' '}CRE explanation document{' '}</a> or click the diagram below.
<a href="https://github.com/OWASP/www-project-integration-standards/raw/master/writeups/CRE-Explained6.pdf">
{' '}
CRE explanation document{' '}
</a>{' '}
or click the diagram below.
</p>

<a href="/opencregraphic2.png" target="_blank">
Expand Down
11 changes: 6 additions & 5 deletions application/frontend/src/pages/Search/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const SearchBar = () => {
}
};


return (
<Form onSubmit={onSubmit}>
<Form.Group>
Expand All @@ -45,10 +44,12 @@ export const SearchBar = () => {
term: e.target.value,
});
}}
label={<Button primary onSubmit={onSubmit}>
<Icon name="search" />
Search
</Button>}
label={
<Button primary onSubmit={onSubmit}>
<Icon name="search" />
Search
</Button>
}
labelPosition="right"
placeholder="Search..."
/>
Expand Down
34 changes: 19 additions & 15 deletions application/frontend/src/pages/Search/components/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { DOCUMENT_TYPES } from 'application/frontend/src/const';
import { getDocumentDisplayName } from 'application/frontend/src/utils/document';
import React from 'react';

import { DocumentNode } from '../../../components/DocumentNode';
import { getDocumentDisplayName } from 'application/frontend/src/utils/document';
import { DOCUMENT_TYPES } from 'application/frontend/src/const';

export const SearchResults = ({ results }) => {
if (results && results.length != 0) {
const sortedResults = results.sort((a, b) => getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b)))
let lastDocumentName = sortedResults[0].name
const sortedResults = results.sort((a, b) =>
getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b))
);
let lastDocumentName = sortedResults[0].name;
return (
<>
{sortedResults.map((document, i) => {let temp = (
<>
{document.doctype != DOCUMENT_TYPES.TYPE_CRE && lastDocumentName !== document.name &&<span style={{margin: "5px"}} />}
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={document} linkType={'Standard'} />
</div>
</>

)
lastDocumentName = (document.id ?? document.name);
return temp
{sortedResults.map((document, i) => {
let temp = (
<>
{document.doctype != DOCUMENT_TYPES.TYPE_CRE && lastDocumentName !== document.name && (
<span style={{ margin: '5px' }} />
)}
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={document} linkType={'Standard'} />
</div>
</>
);
lastDocumentName = document.id ?? document.name;
return temp;
})}
</>
);
Expand Down
12 changes: 7 additions & 5 deletions application/frontend/src/pages/Standard/Standard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ export const Standard = () => {
<LoadingAndErrorIndicator loading={loading} error={error} />
{!loading &&
!error &&
documents.sort((a, b) => getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b))).map((standard, i) => (
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={standard} linkType={'Standard'} />
</div>
))}
documents
.sort((a, b) => getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b)))
.map((standard, i) => (
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={standard} linkType={'Standard'} />
</div>
))}
{data && data.total_pages > 0 && (
<div className="pagination-container">
<Pagination
Expand Down
21 changes: 12 additions & 9 deletions application/frontend/src/pages/Standard/StandardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export const StandardSection = () => {
return (
<>
<div className="standard-page section-page">
<h5 className="standard-page__heading">
{getDocumentDisplayName(document)}
</h5>
<h5 className="standard-page__heading">{getDocumentDisplayName(document)}</h5>
{document && document.hyperlink && (
<>
<span>Reference: </span>
Expand All @@ -76,13 +74,18 @@ export const StandardSection = () => {
Object.entries(linksByType).map(([type, links]) => (
<div className="cre-page__links" key={type}>
<div className="cre-page__links-header">
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:{/* Risk here of mixed doctype in here causing odd output */}
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
{/* Risk here of mixed doctype in here causing odd output */}
</div>
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
<div key={i} className="accordion ui fluid styled cre-page__links-container">
<DocumentNode node={link.document} linkType={type} />
</div>
))}
{links
.sort((a, b) =>
getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))
)
.map((link, i) => (
<div key={i} className="accordion ui fluid styled cre-page__links-container">
<DocumentNode node={link.document} linkType={type} />
</div>
))}
</div>
))
) : (
Expand Down
9 changes: 4 additions & 5 deletions application/frontend/src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export const getApiEndpoint = (doc: Document, apiUrl: string): string => {
};

export const getDocumentTypeText = (linkType, docType): string => {
let docText = DOCUMENT_TYPE_NAMES[linkType];
if(linkType === TYPE_LINKED_TO && docType === DOCUMENT_TYPES.TYPE_CRE)
{
let docText = DOCUMENT_TYPE_NAMES[linkType];
if (linkType === TYPE_LINKED_TO && docType === DOCUMENT_TYPES.TYPE_CRE) {
docText = DOCUMENT_TYPE_NAMES[TYPE_IS_PART_OF];
}
return docText
}
return docText;
};
8 changes: 5 additions & 3 deletions application/utils/external_project_parsers/pci_dss.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def __parse(
"([CUSTOMIZED APPROACH OBJECTIVE]:.*)",
"",
str(row.get(standard_to_spreadsheet_mappings["section"], "")),
),
sectionID=str(row.get(standard_to_spreadsheet_mappings["sectionID"], "")),
).strip(),
sectionID=str(
row.get(standard_to_spreadsheet_mappings["sectionID"], "")
).strip(),
description=str(
row.get(standard_to_spreadsheet_mappings["description"], "")
),
).strip(),
version=version,
)
existing = cache.get_nodes(
Expand Down
21 changes: 17 additions & 4 deletions application/utils/oscal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def document_to_oscal(
oscal_version="1.0.0",
version=version,
links=[common.Link(href=hyperlink)],
remarks=document.description,
remarks=document.description.strip(),
)
else:
m = common.Metadata(
Expand Down Expand Up @@ -96,18 +96,31 @@ def list_to_oscal(documents: List[defs.Standard | defs.Tool]) -> str:

if documents[0].doctype == defs.Credoctypes.Standard:
for doc in documents:
props = []

if doc.section:
props.append(
common.Property(
name="section", value="".join(doc.section.splitlines()).strip()
)
)
if doc.sectionID:
props.append(
common.Property(
name="sectionID",
value="".join(doc.section.splitlines()).strip(),
)
)
controls.append(
catalog.Control(
id=f"_{random.getrandbits(1024)}",
title=doc.name,
props=[common.Property(name="section", value=doc.section)],
props=props,
links=[common.Link(href=doc.hyperlink)],
)
)
elif documents[0].doctype == defs.Credoctypes.Tool:
for doc in documents:
from pprint import pprint

controls.append(
catalog.Control(
id=f"_{random.getrandbits(1024)}",
Expand Down

0 comments on commit b5ec17d

Please sign in to comment.