
๐ ์ด ์ํฌํ๋ก๋ฅผ ์ฌ์ฉํ์ฌ JavaScript ํ๋ก์ ํธ๋ฅผ ๋ ์์ ํ๊ฒ ๋ง๋์ธ์
2022-10-19 last update
8 minutes reading security cicd node javascript๋ณด์ ๋ฌธ์
JavaScript ํ๋ก์ ํธ์ ๋ณด์์ ๋ํด ์๊ฐํด ๋ณธ ์ ์ด ์์ต๋๊น? ์๋? ๊ธ์, ๋งค์ผ
npm
์ ์๋ก์ด ์์ฒ ๊ฐ์ ํจํค์ง๊ฐ ๊ฒ์๋๋ฏ๋ก ์ทจ์ฝ์ ์ด ์์ฒด ์ฝ๋๋ฟ๋ง ์๋๋ผ ์ง์ ์ข
์์ฑ(node_modules)์์๋ ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ํด์ผ ํฉ๋๋ค.Few months ago, coa npm library was used to steal users' personal data by injecting malicious code.
As a reminder coa was:
- Downloaded approximately 9 million times per week
- Used by about 5 million GitHub projects
๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ ๋ง์ ๋ค๋ฅธ ์ด์ผ๊ธฐ๋ค ์ค ํ๋์ผ ๋ฟ์ ๋๋ค...
npm
๋ฅผ ์ฌ์ฉํ์ฌ ์ข
์์ฑ์ ๋ค์ด๋ก๋ํ๋ ๊ฒฝ์ฐ ์ด๋ฏธ ๋ค์ ๋ฉ์์ง๊ฐ ํ์๋์์ ์ ์์ต๋๋ค.
๊ฐ
npm install
, npm
์ดํ์ ์
๋ฐ์ดํธ๋ ์ข
์์ฑ์ ๋ํด ๊ฐ์ฌ ์ค์บ์ ์คํํฉ๋๋ค. ์ฌ๊ธฐ์๋ ํ๋ ์ด์์ ์ข
์์ฑ์์ ๋น๋กฏ๋ 79๊ฐ์ ์ทจ์ฝ์ ์ด ์์ต๋๋ค. ๊ฐ๊ฐ์ ์ ์ฌ์ ์ธ ์ํ์ ๋ํ๋ด๋ฉฐ ์์ ๋์ด์ผ ํฉ๋๋ค.์ด๋ฌํ ์ทจ์ฝ์ ์ ์ด๋์์ ๋ฐ์ํฉ๋๊น? ๊ธฐ๋ณธ์ ์ผ๋ก
npm
๋ ๋งค์ผ ์
๋ฐ์ดํธ๋๋ ์ทจ์ฝ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ์ง ๊ด๋ฆฌํฉ๋๋ค. ๋ค๋ฅธ ๋ง์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฐ ์กด์ฌํฉ๋๋ค. ๋ค์์ JavaScript ์ํ๊ณ์์ ๊ฐ์ฅ ๋๋ฆฌ ์ฌ์ฉ๋๋ ์คํ ์์ค ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ํ ์ ์ฒด ๋ชฉ๋ก์
๋๋ค.์ด๋ฌํ ๋ฆฌ์์ค๋ ํ๋ฅญํ์ง๋ง ์์ฐ์ฑ์ ์ค์ ์ ๋ ๊ฒ์ผ๋ฅธ ๊ฐ๋ฐ์์ด๋ฉฐ ์ด๋ฅผ ์๋ํํ๊ธฐ๋ฅผ ์ํ๋ฏ๋ก ๋งค์ผ ์ค์ 8์์ ์๋ก์ด ๊ธฐ๋ฅ์ ์ฒ๋ฆฌํ๊ธฐ ์ ์ ๋ชจ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์๋์ผ๋ก ํ์ธํ ํ์๊ฐ ์์ต๋๋ค.
๋ณด์ ์๋ฃจ์
๋จผ์ ๋ณด์ ๋ฌธ์ ์ ๋ํ ๋ง๋ณํต์น์ฝ์ ์๋ค๋ ์ฌ์ค์ ๊ฒฝ๊ณ ํ๊ณ ์ถ์ต๋๋ค.
If security were all that mattered, computers would never be turned on, let alone hooked into a network with literally millions of potential intruders. Dan Farmer, pioneer in the development of vulnerability scanners for Unix operating systems and computer networks.
๊ทธ๋ผ์๋ ๋ถ๊ตฌํ๊ณ ํ๋ก์ ํธ์ ์ฝ๊ฒ ํตํฉํ ์ ์๋ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ ์ทจ์ฝ์ ์ ์์ ํฌ๊ฒ ์ค์ผ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ์ด๋ฌํ ๋๊ตฌ๋ ์คํ ์์ค๊ฐ ์๋๋ฏ๋ก ๋ฌด๋ฃ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
NodeSecure ์ง์์ ํตํฉ
NodeSecure is an open source organization that aims to create free JavaScript security tools. Our biggest area of expertise is in npm package and code analysis.
๋ ๋ง์ ์ ๋ณด๋ฅผ ๋ณด๋ ค๋ฉด GitHub ์กฐ์ง์ ์ค๋ฆฝ์Thomas @fraxken๊ฐ ์์ฑํ ์ด ๋ฌธ์๋ฅผ ์ฝ์ผ์ญ์์ค.
@nodesecure/ci๋ ๋ฌด์์ ๋๊น?
@nodesecure/ci ์ ์ ์ฝ๋ ๋ถ์ ๋ฐ ์ทจ์ฝ์ฑ ๋ถ์์ ์ฌ์ฉํ์ฌ ์ข ์์ฑ ์ทจ์ฝ์ฑ์ ์๋ณํ๊ณ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ์ ์ฑ ์ฝ๋ ๋ฐ ํจํด์ ์ถ์ ํ๋ ๋๊ตฌ ์ธํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
ํ๋ก์ ํธ(์ฌ์ฉ์ ์ ์ ๊ตฌ์ฑ ์ฌ์ฉ ๊ฐ๋ฅ)๊ฐ ๋ชจ๋ ๋ณด์ ๊ฒ์ฌ๋ฅผ ํต๊ณผํ๋ฉด ํ๋ก์ธ์ค๊ฐ ์ค๋ฅ ์ฝ๋ ์์ด ์ข ๋ฃ๋๊ณ ๊ทธ๋ ์ง ์์ผ๋ฉด ์คํจํฉ๋๋ค.
๋ค์์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์ ๋๋ค.

์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
- GitHub ์์
GitHub Actions ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๊ณต์NodeSecure ci-action ์์ ์ ์ํฌํ๋ก์ ์ถ๊ฐํ๋ ๋งค์ฐ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
์ํฌํ๋ก.yaml
steps:
- uses: actions/[email protected]
- uses: NodeSecure/[email protected]
์ด์ ์์ด๋ฌ๋ํ๊ฒ๋ ํ๋ก์ ํธ์ ์๋ก์ด ์ข ์์ฑ์ ์ถ๊ฐํ์ง ์๊ณ ๋ ์์ค ์ฝ๋์ ํด๋น ์ข ์์ฑ์ด ์๋์ผ๋ก ๋ถ์๋ฉ๋๋ค. ๊ธฐ์ ๋ฆฌ๋๊ฐ ์๋ก์ด ์ข ์์ฑ์ ์ถ๊ฐํ๋ ๊ฒ์ ์ํ์ง ์๋ ๊ฒฝ์ฐ์๋ ์ ํฉํฉ๋๋ค(node_modules๋ ์ด๋ฏธ ์ฐ์ฃผ๋ณด๋ค ๋ฌด๊ฒ์ต๋๋ค).
- Node.js ์คํฌ๋ฆฝํธ
@nodesecure/ci ํจํค์ง๋ฅผ ์ค์นํ๊ณ ์ ๋ ฅ ์คํฌ๋ฆฝํธ
node_modules/.bin/nsci
๋ฅผ ์ฌ์ฉํ์ฌ ์์ํ์ญ์์ค.GitHub ์์ ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก CLI ์ธ์๋ฅผ ํตํด ์ฌ์ฉ์ ์ง์ ๊ตฌ์ฑ์ ์ ๊ณตํ ์ ์์ต๋๋ค.
๋จผ์ package.json์ ๋ฐ์ด๋๋ฆฌ ์คํฌ๋ฆฝํธ๋ฅผ ์ฐธ์กฐํ์ญ์์ค.
{
"scripts": {
"nsci": "nsci"
}
}
๊ทธ๋ฐ ๋ค์ ๋ค๋ฅธ ์ธ์๋ฅผ ์ ๊ณตํ์ฌ ์์ํฉ๋๋ค(๊ทธ๋ฐ๋ฐ ๋ชจ๋ ํ ๋ฒ์ ์ฌ์ฉํ ์ ์์).
$ npm run nsci -- --directory=/Users/user1/myproject
$ npm run nsci -- --strategy=npm
$ npm run nsci -- --vulnerability=all
$ npm run nsci -- --warnings=error
$ npm run nsci -- --reporters=console
- ๋ชจ๋ API
@nodesecure/ci๋ ํ์ดํ๋ผ์ธ ๋ฌ๋๋ฅผ API๋ก ๋ ธ์ถํ์ฌ ๋ค๋ฅธ ๊ฒฐํฉ๋ ์ํฌํ๋ก์์ ์ฌ์ฉํ ์ ์๋๋ก ํฉ๋๋ค.
import {ย runPipeline } from "@nodesecure/ci";
const optionsExample = {
directory: process.cwd(),
strategy: "node",
vulnerabilities: "all",
warnings: "error",
reporters: ["console"]
}
await runPipeline(optionsExample);
// => the process can either exit with error code (1)
// or no error code (0), depending on the pipeline status.
๊ทธ๊ฒ ๋ค์ผ, ์ด์ ๋ ์ด์ ์ฐ์ตํ์ง ์์ ํ๊ณ๊ฐ ์๋คDevSecOps =)
@nodesecure/ci์ ๋ํ ๋ชจ๋ ํผ๋๋ฐฑ์ ํ์ํฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ด์ ๋ง ์์๋์์ต๋๋ค.
GitHub @antoine-coulon์์ ์ ์๊ฒ ์ฐ๋ฝ ์ฃผ์๊ธฐ ๋ฐ๋๋๋ค.
์ฝ์ด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.