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

7807 ๋‹จ์–ด securitycicdnodejavascript

๋ณด์•ˆ ๋ฌธ์ œ



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/checkout@v2
          - uses: NodeSecure/ci-action@v1
    


    ์ด์ œ ์•„์ด๋Ÿฌ๋‹ˆํ•˜๊ฒŒ๋„ ํ”„๋กœ์ ํŠธ์— ์ƒˆ ์ข…์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ ๋„ ์†Œ์Šค ์ฝ”๋“œ์™€ ํ•ด๋‹น ์ข…์†์„ฑ์ด ์ž๋™์œผ๋กœ ๋ถ„์„๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ธฐ์ˆ  ์ฑ…์ž„์ž๊ฐ€ ์ƒˆ๋กœ์šด ์ข…์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ์›ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ(node_modules๋Š” ์ด๋ฏธ ์šฐ์ฃผ๋ณด๋‹ค ๋ฌด๊ฒ์Šต๋‹ˆ๋‹ค)์— ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค.

    - Node.js ์Šคํฌ๋ฆฝํŠธ

    @nodesecure/ci ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์‹œ์ž‘ ์Šคํฌ๋ฆฝํŠธnode_modules/.bin/nsci๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    GitHub Action๋ฟ๋งŒ ์•„๋‹ˆ๋ผ 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์œผ๋กœ ์—ฐ๋ฝ์ฃผ์„ธ์š”.

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

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ