أمن مشاريع npm ، الجزء 1

أمن مشاريع npm ، الجزء 1



مرحبا! في آخر مشاركة، بدأنا ننظر في مسألة مهمة الأمن في الآلية الوقائية الوطنية، وتحدث عن ما يقيس الشركة نفسها تستخدم لتحديد ومنع التهديدات. هذه المرة أريد أن أتحدث عن الأدوات والأساليب المتاحة لك شخصيًا ، والتي أوصي بشدة أن يطبقها جميع المطورين في ممارساتهم.





npm install (: preinstall, install/postinstall), . , . , , .



, :



مثال على حزمة تحتوي على برنامج نصي ضار



: npm install malicious-package, evil.sh, unix-.



, , 2018 eslint-scope eslint-config-eslint, , .



, , , , , .



, npm npm, . , npm registry , , , , npm .



, , , , . , , .

, npm , npm , . .



, :



npm install suspicious-package --ignore-scripts


, ( .npmrc):



npm config set ignore-scripts true


, . , .





تحديد وقت التشغيل



, , npm, npm install. , Docker-, . , npm root-; , . . : npm, .



: - , . , . npm.





أمان الرموز والمفاتيح



: , . , npm .npmrc , .



npm - (, CI/CD), . , , read-only, . .



npm IP- (CIDR). IP ( IP) . , , (on-demand). , , .



.npmrc, (Git). NPM_TOKEN ( ).



npm token create, :



  • --read-only — , (. . , );
  • --cidr=<CIDR> — , IP. CIDR, IP. : --cidr=192.0.2.0/24.


, npm-, . npm, npm token list.



, npm adduser .npmrc . .



~/.npmrc :



//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000


npm registry, .



, ~/.npmrc unix-!

(, SSH), , . , . . , . SSH, EdDSA . , . : Ed25519 (EdDSA) RSA ( 2048 ) .





مقل العيون



, , . . , , npm install packae-name: 404, — .



npm , . , , , copy-and-paste.





تأمين كلمات المرور



, , :



  • , . (16 );
  • . ;
  • ;
  • , .


: . KeePass ( ). -, . -, , , . (., Google Drive DropBox), .



, , !


(MFA)



مصادقة متعددة العوامل (MFA)



, . . : - , . - SMS- . , . . .



, npm -. : « » « ». « », . . , npm OTP npm adduser, - (, npm publish).



, npm 2FA, . : , QR-, -. , CLI :



  • npm profile enable-2fa auth-and-writes

    — « » ()
  • npm profile enable-2fa auth-only

    — « »


CLI npm ( ), QR-. (OTP), , .



npm , , , .



, , 2FA npm profile disable-2fa, . , , npm (, ).





تقييد الملفات المنشورة



, npm publish, npm .



, npm
  • .git
  • CVS
  • .svn
  • .hg
  • .lock-wscript
  • .wafpickle-N
  • .*.swp
  • .DS_Store
  • ._*
  • npm-debug.log
  • .npmrc
  • node_modules
  • config.gypi
  • *.orig
  • package-lock.json


- registry , , , . . npm - , , .



, files package.json. , ( glob), . , - .



, , files:



  • package.json
  • README
  • CHANGES, CHANGELOG, HISTORY
  • LICENSE, LICENCE
  • NOTICE
  • , main


README, CHANGES, LICENSE NOTICE .



, .



, npm publish, --dry-run npm pack --dry-run. , , . --dry-run , , , .





, , npm-. — .



, .






, , , , . , .



- , , .



.




All Articles