https://socket.dev/blog/introducing-safe-npm
Introducing "safe npm", a Socket npm Wrapper - Socket
Socket is proud to introduce an exciting new tool—“safe npm”—that protects developers whenever they use npm install.
socket.dev
npm install을 실행할 때, 우리는 어떤 transitive dependency가 설치될지 모른다.
npx는 코드가 즉시 실행되기 때문에 더 위험할 수 있다.
safe-npm은 npm의 wrapper로써, npm i 혹은 npx를 사용할 때, 다운받거나 실행될 파일이 안전할지 먼저 확인할 수 있게 해준다.
사용하기
npm install -g @socketsecurity/cli
이제 npm-socket react 처럼 사용하면 안전하게 사용할 수 있다.
npm만 입력하고 싶다면, alias를 설정해주면 된다.
mac (zsh) 설정 방법 예시
vi .zshrc
// i 누른 뒤
alias npm="socket-npm"
alias npx="socket-npx"
// esc + :wq
이제 npm i 를 사용하면 socket-npm i 로 실행된다.
yarn이나 pnpm이나 다른 것들은요..ㅠ?
지원 현황은 여기서 확인할 수 있다.
https://docs.socket.dev/docs/language-support
Ecosystem Support
Languages ecosystems, programming languages, package managers, and features that Socket supports
docs.socket.dev
동작
npm i reacts
reacts@0.0.0 (https://socket.dev/npm/package/reacts/overview/0.0.0) contains risks:
Potential typo squat - Package name is similar to other popular packages and may not be the package you want.
Accept risks of installing these packages (y/N)? N
npm ERR! Socket npm exiting due to risks
...