๐Ÿ”’ ์ด ์›Œํฌํ”Œ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ JavaScript ํ”„๋กœ์ ํŠธ๋ฅผ ๋” ์•ˆ์ „ํ•˜๊ฒŒ ๋งŒ๋“œ์„ธ์š”

๐Ÿ”’ ์ด ์›Œํฌํ”Œ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 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 ์ƒํƒœ๊ณ„์—์„œ ๊ฐ€์žฅ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์˜คํ”ˆ ์†Œ์Šค ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋Œ€ํ•œ ์ „์ฒด ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
  • Node.js Security Working Group
  • Snyk
  • GitHub

  • ์ด๋Ÿฌํ•œ ๋ฆฌ์†Œ์Šค๋Š” ํ›Œ๋ฅญํ•˜์ง€๋งŒ ์ƒ์‚ฐ์„ฑ์— ์ค‘์ ์„ ๋‘” ๊ฒŒ์œผ๋ฅธ ๊ฐœ๋ฐœ์ž์ด๋ฉฐ ์ด๋ฅผ ์ž๋™ํ™”ํ•˜๊ธฐ๋ฅผ ์›ํ•˜๋ฏ€๋กœ ๋งค์ผ ์˜ค์ „ 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์—์„œ ์ €์—๊ฒŒ ์—ฐ๋ฝ ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

    ์ฝ์–ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.