Cloud Native Security 02: Secure the Code¶
On 31 March 2026, someone published two bad versions of axios, one of the most used JavaScript packages. They were online for about three hours1. Any project that waits a few days before taking new versions never saw them.
That's one setting in a file. This post covers the cheap checks like it, the ones you run while the code is still on a developer's screen or in a pull request.
Prefer to watch? This 5-minute video covers the whole post. It's in Thai, and the voice and presenter are AI versions of me.
The Cloud Native Security series
Put each check where it's cheapest¶
A check that takes ten minutes doesn't belong on every save, and a check that needs a running app can't happen in the editor. Spread them out:
| When | What to check | How long it should take |
|---|---|---|
| Before the commit | Secrets | Seconds |
| On the pull request | Code, configuration, dependencies, a second person | Minutes |
| After deploying to a test environment | The running application | Tens of minutes |
Show the results where developers already look, in the pull request. A finding in a separate security portal tends to wait there.
Keep passwords and keys out of Git¶
Git remembers everything. Delete a password in the next commit and it's still in the history for anyone who can clone the repository.
Run a secret scanner on your whole history once, then on every change. Betterleaks is a good default, since the author of the popular Gitleaks moved there and Gitleaks now gets security fixes only. TruffleHog is the alternative.
If it finds a real secret, replace the secret first. Cleaning the history doesn't help if someone has already copied it.
Let a tool read the code before a person does¶
Static analysis reads your source and looks for known dangerous patterns, such as user input going straight into a database query. It won't find a flaw in your business logic, which is what human reviewers are for.
| Your situation | Use |
|---|---|
| Most teams | Semgrep CE |
| Public repositories on GitHub | CodeQL, free there |
| You're building a product around the rules | Opengrep, after checking the rule licences |
Start with only the high-severity rules blocking a merge. If you switch on everything, people will learn to ignore it.
Check the configuration like code¶
Your Kubernetes files, Terraform and Dockerfiles decide whether a container runs as root or a storage bucket is public. They get far less review than the application does.
Trivy reads all three, and --exit-code 1 fails the pipeline when it finds something serious. Checkov is the alternative. If you still use tfsec, its checks moved into Trivy.
Look out for these four first:
- Containers that can gain more privileges than they started with
- Containers with no memory limit
- Storage or databases open to the internet
- Cloud roles that allow everything
Trivy was itself compromised in March 2026, so install it from a pinned version and give it no secrets. Post 3 explains how.
Update dependencies, with a short delay¶
Old packages have known holes, and brand-new ones may be poisoned. Waiting a few days covers both, because most bad releases get caught quickly.
| Tool | What it does for you |
|---|---|
Renovate with config:best-practices | Opens update pull requests, pins exact versions, and adds a waiting period for npm |
| Dependabot | Waits three days by default since July 2026, and skips the wait for security fixes2 |
npm 12 helps too. It no longer runs a package's install scripts unless you allow it3, and those scripts are a common way for a bad package to run code on your machine.
Make two people look at risky changes¶
Tools miss intent. A one-line change to a login check can be valid code and still open the whole system.
- Protect the main branch, so nobody can push to it directly
- Require one approval, from someone other than the author
- Require the platform team's approval for pipeline files, cluster rules and access settings
- Have a person review code written by AI assistants too
GitHub and GitLab both have a code owners file that sends certain paths to certain people.
Turn every security bug into a test¶
When you fix a security bug, write an automated test that fails if it comes back. Do the same for infrastructure. If a database was once open to the internet, add a test that tries to connect from outside.
Spend the effort on code that handles money or personal data, code that changes often, and code that has broken before.
Attack your own test environment¶
Some problems only appear when the application runs, such as a missing security header or an admin page with no login. ZAP is a free tool that visits your site and reports what it finds. Its baseline scan looks without attacking, so it's a safe place to begin:
Scan only systems you own or have written permission to test. The eShop pipeline in another series shows many of these checks running together.
Summary¶
| If you're worried about... | Start with | Alternative |
|---|---|---|
| Passwords in Git | Betterleaks | TruffleHog |
| Dangerous code | Semgrep CE | CodeQL or Opengrep |
| Bad cluster or cloud settings | Trivy | Checkov |
| Poisoned packages | Renovate with a delay | Dependabot |
| Problems in the running app | ZAP baseline scan | A penetration test |
- Scan the full Git history for secrets this week
- Add one blocking check to pull requests, high severity only
- Set a waiting period on dependency updates
- Require a second person for pipeline and access changes
Next: Secure the supply chain
-
axios, post-mortem of the compromised releases: 1.14.1 and 0.30.4 were bad. ↩
-
GitHub, Dependabot version updates get a default cooldown. ↩
-
GitHub, Breaking changes in npm 12. ↩
Discussion
Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.