Page MenuHomeFreeBSD

security/vuxml: Autofill CVE information
ClosedPublic

Authored by fernape on Mar 3 2023, 4:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 25 2024, 1:27 AM
Unknown Object (File)
Jan 18 2024, 1:49 PM
Unknown Object (File)
Jan 12 2024, 1:52 AM
Unknown Object (File)
Dec 24 2023, 8:30 PM
Unknown Object (File)
Dec 24 2023, 8:41 AM
Unknown Object (File)
Dec 20 2023, 8:10 AM
Unknown Object (File)
Nov 26 2023, 3:26 PM
Unknown Object (File)
Nov 23 2023, 8:29 AM

Details

Summary

The newentry target accepts an optional parameter CVE_ID. When
provided, the newentry.sh scripts tries to retrieve information from the NVD and
MITRE databaseis and fill the template accordingly.

Althoug it breaks the style in the script, I used the $() syntax in favor of
backtics.

The script needs textproc/jq and warns the user and exists if it is not found:

$ make newentry CVE_ID=CVE-2022-39282
textproc/jq is needed for CVE automatic entry fill
*** Error code 1

How to use it:

make newentry CVE_ID=CVE-2022-39282

creates the following entry:

  <vuln vid="7a2f7b82-b9d7-11ed-9818-dcfe074bd614">$
    <topic>freerdp -- RDP client: Read of uninitialized memory with parallel port redirection</topic>$
    <affects>$
      <package>$
>>>>>>>><name>freerdp</name>$
>>>>>>>><range><lt>2.8.1</lt></range>$
      </package>$
    </affects>$
    <description>$
      <body xmlns="http://www.w3.org/1999/xhtml">$
>>>>>>>><p>SO-AND-SO reports:</p>$
>>>>>>>><blockquote cite="https://github.com/FreeRDP/FreeRDP/releases/tag/2.8.1">$
>>>>>>>>  <p>FreeRDP is a free remote desktop protocol library and clients.$
>>>>>>>>FreeRDP based clients on unix systems using `/parallel` command$
>>>>>>>>line switch might read uninitialized data and send it to the server$
>>>>>>>>the client is currently connected to.  FreeRDP based server$
>>>>>>>>implementations are not affected.  Please upgrade to 2.8.1 where$
>>>>>>>>this issue is patched.  If unable to upgrade, do not use parallel$
>>>>>>>>port redirection (`/parallel` command line switch) as a workaround..</p>$
>>>>>>>></blockquote>$
      </body>$
    </description>$
    <references>$
      <cvename>CVE-2022-39282</cvename>$
      <url>https://nvd.nist.gov/vuln/detail/CVE-2022-39282</url>$
    </references>$
    <dates>$
      <discovery>2022-10-12</discovery>$
      <entry>2023-03-03</entry>$
    </dates>$
  </vuln>$

If used without the CVE_ID parameter, it generates the same output as before.

Note that this is just a helper. *YOU HUMAN* have to check that the information
is correct.

Test Plan

Apply patch and play with some CVEs. This is just a helper and maybe it would be
a good idea to add a XML comment similar to what make makeplist does:

<!-- YOU HAVE TO CHECK THE ENTRY THAT WAS FILLED FOR YOU! -->

Diff Detail

Repository
R11 FreeBSD ports repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Amazing!

security/vuxml/files/newentry.sh
58

Is there a way to sanitize this string further? (e.g., < -> &lt;), maybe using @html in jq? (I'm just being spoiled)

details=$(echo "${nvd_json_data}" | jq -r '.vulnerabilities[0].cve.descriptions[0].value|@html' | fmt -p -s | sed '1!s/^/\t/') || exit 1
75

I've noticed these new XML lines use tabs instead of spaces, I believe they all should be the same.

85

Some CVEs already include the final period.

Could you maybe use temporary files (mktemp(1)) for fetch output instead of variables, it makes the jq lines shorter (jq '.foo' /tmp/file instead of echo $foo | jq ".foo")

Also, could you please add set -u and set -e at the start of the script, so that errors are handled.

security/vuxml/files/newentry.sh
85

details is unset if the cve id was not passed to the script, it would be better to always define it.

Address feedback.

  • While here, gather always the first reference and drop the MAX_REFERENCES variable.
  • Shorten oneliners by using common prefixes.
fernape added inline comments.
security/vuxml/files/newentry.sh
58

You're absolutely right. Done.

75

I don't know exactly what you are referring too. I tried with make newentry in main and with the code in the review plus make newentry CVE_ID=CVE-XXXXXX and neither diff nor vimdiff shows changes between spaces and/or characters.

85

Fixed. Thanks!

85

All variables defined. Checked with set -u.

Thanks!

In D38894#885721, @mat wrote:

Could you maybe use temporary files (mktemp(1)) for fetch output instead of variables, it makes the jq lines shorter (jq '.foo' /tmp/file instead of echo $foo | jq ".foo")

Done. Also inspired by your comment I switched to use a prefix to shorten the oneliners even more.

Also, could you please add set -u and set -e at the start of the script, so that errors are handled.

Done.

security/vuxml/files/newentry.sh
75

It was only after submitting the review that I realized it has always been that way, with a mix of tabs and spaces for indentation, it is not a product of this differential. Sorry!

security/vuxml/files/newentry.sh
75

Ah, ok! No worries. Thanks for double checking.

Any more improvements we can make to this?

If there are no objections, I will commit this in a couple of days.

Thanks!

This revision was not accepted when it landed; it landed in state Needs Review.Mar 12 2023, 6:40 PM
This revision was automatically updated to reflect the committed changes.