Security Auditing for Project Packages
Introduction
In previous articles, I have guided you through various ways to enhance project security through direct implementation. Now, I will demonstrate how to perform security audits for the packages you use. This is also a critical factor because while your codebase may be secure, a library you are using could contain hidden security risks that hackers can exploit.
Detail
First, let us look at how to check a package for security risks. Before installing, you can visit certain websites to verify package information, such as using https://security.snyk.io. This website provides comprehensive information to assess the health of a package and supports multiple languages.
NPM
Next is auditing security for the packages your project is currently using. Because technology changes rapidly, a package you use today might be fine, but it could reveal security risks a few months later. Therefore, this check needs to be performed regularly depending on the scale of the product you are developing.
If you do not want to set up a lot, you can use built-in tools like the following for npm:
npm audit
npm audit fix
If you use yarn, the default only supports auditing. You can install yarn-audit-fix, which will automatically create a package-lock.json file to fix all packages via npm and then update the results into yarn.lock:
yarn audit
npx yarn-audit-fix
For example, when checking, it will inspect the corresponding package-lock.json or yarn.lock file to search for vulnerabilities and include priority levels (moderate, high). You should prioritize fixing packages with high vulnerabilities first.
$ yarn audit
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate │ fast-xml-parser XMLBuilder: XML Comment and CDATA Injection │
│ │ via Unescaped Delimiters │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ fast-xml-parser │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=5.7.0 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @aws-sdk/client-s3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ @aws-sdk/client-s3 > @aws-sdk/credential-provider-node > │
│ │ @aws-sdk/credential-provider-ini > │
│ │ @aws-sdk/credential-provider-sso > @aws-sdk/token-providers │
│ │ > @aws-sdk/nested-clients > @aws-sdk/util-user-agent-node > │
│ │ @aws-sdk/middleware-user-agent > @aws-sdk/core > │
│ │ @aws-sdk/xml-builder > fast-xml-parser │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://www.npmjs.com/advisories/1117911 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high │ fast-xml-builder allows attribute values with unwanted │
│ │ quotes to bypass malicious or unwanted attributes │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ fast-xml-builder │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=1.1.7 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @aws-sdk/client-s3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ @aws-sdk/client-s3 > @aws-sdk/core > @aws-sdk/xml-builder > │
│ │ fast-xml-parser > fast-xml-builder │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://www.npmjs.com/advisories/1118965 │
└───────────────┴──────────────────────────────────────────────────────────────┘
Snyk
Next, I will introduce another package called Snyk. This is a commercial product (SaaS) with advantages such as:
- Private data, extremely fast updates and low noise.
- Very high accuracy with few false positives.
- Extremely fast scanning speed.
- Easy integration when deploying for both local and CI/CD environments.
- Support for many languages such as NodeJS, Python, Java and more.
Of course, it is not entirely free. You need to create an account and there are certain limits on the number of project scans.
To use it, simply install and log in first:
$ npm install -g snyk
$ snyk auth
Now redirecting you to our auth page, go ahead and log in,
and once the auth is complete, return to this prompt and you'll
be ready to start using snyk.
After logging in successfully, you can use Snyk:
$ snyk test
Testing /project/path...
Tested 478 dependencies for known issues, found 16 issues, 16 vulnerable paths.
Issues to fix by upgrading:
Upgrade next@16.2.0 to next@16.2.6 to fix
✗ Cross-site Scripting (XSS) (new) [Low Severity][https://security.snyk.io/vuln/SNYK-JS-NEXT-16638684] in next@16.2.0
introduced by next@16.2.0
✗ Acceptance of Extraneous Untrusted Data With Trusted Data (new) [Medium Severity][https://security.snyk.io/vuln/SNYK-JS-NEXT-16638675] in next@16.2.0
introduced by next@16.2.0
✗ Interpretation Conflict (new) [Medium Severity][https://security.snyk.io/vuln/SNYK-JS-NEXT-16638676] in next@16.2.0
introduced by next@16.2.0
✗ Authentication Bypass Using an Alternate Path or Channel (new) [High Severity][https://security.snyk.io/vuln/SNYK-JS-NEXT-16638686] in next@16.2.0
introduced by next@16.2.0
✗ Allocation of Resources Without Limits or Throttling (new) [High Severity][https://security.snyk.io/vuln/SNYK-JS-NEXT-16638674] in next@16.2.0
introduced by next@16.2.0
Issues with no direct upgrade or patch:
✗ Cross-site Scripting (XSS) [Medium Severity][https://security.snyk.io/vuln/SNYK-JS-POSTCSS-16189065] in postcss@8.4.31
introduced by next@16.2.0 > postcss@8.4.31
This issue was fixed in versions: 8.5.10
✗ Use of Uninitialized Resource [Medium Severity][https://security.snyk.io/vuln/SNYK-JS-WS-16722635] in ws@8.18.3
introduced by socket.io-client@4.8.3 > engine.io-client@6.6.4 > ws@8.18.3
This issue was fixed in versions: 8.20.1
Organization: organization
Package manager: yarn
Target file: yarn.lock
Project name: project-name
Open source: no
Project path: /project/path
Licenses: enabled
Happy coding!
Comments
Post a Comment