-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1010 from lunasec-io/1009-cwe-common-names-for-gi…
…thub-advisories cwe common names and cwe viewer
- Loading branch information
Showing
27 changed files
with
957 additions
and
201 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
lunatrace/bsl/backend/src/graphql-yoga/generated-resolver-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ query GetCweDetails($id: Int!) { | |
extended_description | ||
id | ||
name | ||
common_name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query GetCwes($limit: Int!, $offset: Int!, $where: vulnerability_cwe_bool_exp = {}) { | ||
vulnerability_cwe(limit: $limit, offset: $offset, where: $where, order_by: {id: desc}) { | ||
id | ||
name | ||
description | ||
extended_description | ||
common_name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright by LunaSec (owned by Refinery Labs, Inc) | ||
* | ||
* Licensed under the Business Source License v1.1 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt | ||
* | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import React from 'react'; | ||
import { Container, Row, Spinner } from 'react-bootstrap'; | ||
|
||
import { CweListItem } from './CweListItem'; | ||
import { GetCwes } from './types'; | ||
|
||
interface ListProps { | ||
cwes: GetCwes[]; | ||
isLoading: boolean; | ||
} | ||
|
||
export const CweList: React.FunctionComponent<ListProps> = ({ cwes, isLoading }) => { | ||
const vulnCards = cwes.map((cwe) => { | ||
return ( | ||
<Row key={cwe.id}> | ||
<CweListItem cwe={cwe} /> | ||
</Row> | ||
); | ||
}); | ||
return ( | ||
<Container className="cwe-list"> | ||
{vulnCards} | ||
{isLoading ? <Spinner animation="border" variant="primary" /> : null} | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright by LunaSec (owned by Refinery Labs, Inc) | ||
* | ||
* Licensed under the Business Source License v1.1 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt | ||
* | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import React from 'react'; | ||
import { Card, Col, Container, Row } from 'react-bootstrap'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { GetCwes } from './types'; | ||
|
||
interface ListItemProps { | ||
cwe: GetCwes; | ||
} | ||
|
||
export const CweListItem: React.FunctionComponent<ListItemProps> = ({ cwe }) => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<> | ||
<Card | ||
onClick={() => navigate(`/cwes/${cwe.id.toString()}`)} | ||
className="flex-fill w-100 vulnerability clickable-card" | ||
> | ||
<Card.Header> | ||
<Container fluid> | ||
<Row> | ||
<Col sm="6"> | ||
<Card.Title> | ||
<h3>{cwe.name}</h3> | ||
</Card.Title> | ||
</Col> | ||
<Col sm={{ span: 6 }} className="mt-xs-2 mt-sm-0"> | ||
<div> | ||
<Card.Title className="text-right"> | ||
<span className="darker h4"> ID: </span> | ||
<div style={{ display: 'inline-block' }}> | ||
<h4 style={{ display: 'inline' }}>{`CWE-${cwe.id}`}</h4> | ||
</div> | ||
</Card.Title> | ||
</div> | ||
</Col> | ||
</Row> | ||
</Container> | ||
</Card.Header> | ||
<Card.Body className="d-flex"> | ||
<Container> | ||
<Row> | ||
<Col md={12}> | ||
<p>{cwe.description}</p> | ||
</Col> | ||
</Row> | ||
</Container> | ||
</Card.Body> | ||
</Card> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Col, Container, Form, InputGroup, Row, Spinner } from 'react-bootstrap'; | ||
import { useBottomScrollListener } from 'react-bottom-scroll-listener'; | ||
import { Search } from 'react-feather'; | ||
import { Helmet } from 'react-helmet-async'; | ||
|
||
import api from '../../api'; | ||
import { Vulnerability_Cwe_Bool_Exp } from '../../api/generated'; | ||
|
||
import { CweList } from './CweList'; | ||
|
||
export const CwesMain: React.FunctionComponent = () => { | ||
const [search, setSearch] = useState(''); | ||
const [cweLimit, setCweLimit] = useState(20); | ||
const submitSearch = (search: string) => { | ||
setSearch(search); | ||
}; | ||
|
||
const parsedSearch = parseInt(search.toLowerCase().replace('cwe-', ''), 10); | ||
const searchIsNumber = !isNaN(parsedSearch); | ||
|
||
const searchConditions: Vulnerability_Cwe_Bool_Exp[] = [{ name: { _ilike: `%${search}%` } }]; | ||
|
||
if (searchIsNumber) { | ||
searchConditions.push({ id: { _eq: parsedSearch } }); | ||
} | ||
|
||
const where: Vulnerability_Cwe_Bool_Exp = { | ||
_or: searchConditions, | ||
}; | ||
|
||
const { data, isFetching, refetch } = api.useGetCwesQuery({ | ||
limit: cweLimit, | ||
offset: 0, | ||
where, | ||
}); | ||
|
||
// lazy loading. Reloads all the old vulns when expanding the batch size but..it works fine | ||
useBottomScrollListener( | ||
() => { | ||
if (data && data.vulnerability_cwe) { | ||
const cweCount = data.vulnerability_cwe.length; | ||
if (cweCount === cweLimit) { | ||
setCweLimit(cweLimit + 20); | ||
refetch(); | ||
} | ||
} | ||
}, | ||
{ offset: 200 } | ||
); | ||
|
||
return ( | ||
<> | ||
<Helmet title="Common Weakness Enumeration (CWE) Index" /> | ||
<Container> | ||
<Row className="mb-2 mb-xl-3"> | ||
<Col sm="6" md="4"> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
submitSearch(search); | ||
}} | ||
> | ||
<InputGroup> | ||
<Form.Control | ||
placeholder="Search CWEs" | ||
aria-label="Search CWEs" | ||
value={search} | ||
onChange={(e) => setSearch(e.target.value)} | ||
/> | ||
<Button type="submit" variant=""> | ||
{isFetching ? ( | ||
<Spinner as="span" animation="border" size="sm" role="status" aria-hidden="true" /> | ||
) : ( | ||
<Search className="feather" /> | ||
)} | ||
</Button> | ||
</InputGroup> | ||
</form> | ||
</Col> | ||
</Row> | ||
<CweList cwes={data?.vulnerability_cwe || []} isLoading={isFetching} /> | ||
</Container> | ||
</> | ||
); | ||
}; |
41 changes: 41 additions & 0 deletions
41
lunatrace/bsl/frontend/src/pages/cwes/detail/CweDetailMain.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { Spinner } from 'react-bootstrap'; | ||
import { Helmet } from 'react-helmet-async'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import api from '../../../api'; | ||
|
||
import { CweDetails } from './CweDetails'; | ||
|
||
export const CweDetailMain: React.FC = () => { | ||
const { cwe_id } = useParams(); | ||
|
||
if (!cwe_id) { | ||
return <p>Missing CWE ID in url.</p>; | ||
} | ||
|
||
const parsedCweId = parseInt(cwe_id, 10); | ||
|
||
const cweIdIsNotANumber = isNaN(parsedCweId); | ||
if (cweIdIsNotANumber) { | ||
return <p>CWE ID is not a number: ${cwe_id}.</p>; | ||
} | ||
|
||
const { data, isFetching } = api.useGetCweDetailsQuery({ id: parsedCweId }); | ||
if (!data) { | ||
return <Spinner animation="border" />; | ||
} | ||
|
||
return ( | ||
<> | ||
{data && data.vulnerability_cwe_by_pk && !isFetching ? ( | ||
<> | ||
<Helmet title={`CWE-${data.vulnerability_cwe_by_pk.id}`} /> | ||
<CweDetails cwe={data.vulnerability_cwe_by_pk} sideBySideView={false} /> | ||
</> | ||
) : ( | ||
<Spinner animation="border" /> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { GetCwesQuery } from '../../api/generated'; | ||
|
||
export type GetCwes = GetCwesQuery['vulnerability_cwe'][number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.