Safe software development
Secure software development from Secure by Design to CI/CD security gates and supply chain integrity by NIST SSDF, OWASP and SLSA.
Safety as design requirement
Secure by Design and Secure by Default
Secure by Design means security as a requirement from day one; Secure by Default means secure defaults (e.g. MFA enabled, ports closed) so that the user does not have to activate anything manually.
Tools and commands for this step
Check secure defaults and model threats before writing code.
Threat model
- OWASP Threat Dragon Application for data flow diagrams and STRIDE threats.
-
OWASP pytm: threat model as code, the output is a diagram.
python3 tm.py --dfd | dot -Tpng -o dfd.png
Secure defaults
-
Shows which ports are open by default.
nmap --top-ports 100 <resurss> -
Checks that security headers are on without extra settings.
curl -sI https://<resurss> | grep -iE 'strict-transport|content-security'
In practice
Safety is a business requirement, not an additional function. Key principles: minimum attack surface, minimum privileges, multilayer protection, safe secure failure (fail safely) and safe defaults.
Reference
Principles of safety design for CISA "Secure by Design" (2023), NIST SSDF (SP 800-218), OWASP, Saltzer & Schroeder (1975).
Safety Note
The responsibility for safety belongs to the manufacturer and not to the user. The safety to be manually activated in practice remains excluded - therefore the default must be safe.
Safe Development Life Cycle (SDLC)
Safety performance in each phase
Tools for each phase
One typical tool or command for each lifecycle phase.
1. Requirements
- OWASP ASVS A list of verifiable security requirements for the specification.
2. Design
- OWASP Threat Dragon Threat model for the architecture review.
3. Development
-
Runs lint and secret checks before a commit.
pre-commit run --all-files
4. Testing
-
ZAP passive check of a running application.
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://<testa-vide>
5. Deployment
-
Finds insecure infrastructure code before deployment.
checkov -d .
6. Maintenance
-
Rechecks dependencies against new vulnerabilities.
osv-scanner scan source -r .
In practice
For each phase your security action and responsible. Map on recognised frameworks - Microsoft SDL, NIST SSDF practices (PO, PS, PW, RV) and OWASP SAMM mature domains.
Reference
NIST SSDF SP 800-218, Microsoft Security Development Lifecycle, OWASP SAMM, BSIMM, ISO/IEC 27034 (user safety).
Safety Note
Danger modelling during the design phase finds architectural flaws that no code scanner sees - they are most expensive to repair later.
Safe coding practices
The most common risks (OWASP Top 10) and protection
Code checks
Static analysis finds known weaknesses while the code is being written.
Any language
-
Searches the whole project for OWASP Top 10 patterns.
semgrep scan --config p/owasp-top-ten
By language
-
Python: unsafe calls and weak cryptography.
bandit -r src/ -
Go: security checks for all packages.
gosec ./... -
JavaScript and TypeScript: lint with security plugins.
npx eslint . --ext .js,.ts
In practice
Practical checklist for the developer and code review. OWASP USS gives verifiable requirements at three levels (L1-L3) depending on the application's decline.
Reference
OWASP Top 10:2021, OWASP Application Security Verification Standard (USAS) 5.0 (2025), OWASP Cheat Sheet Series, CWE Top 25, SEI CERT Coding Standards.
Safety Note
Never trust the input and write your own cryptography. Valide input to server (not only browser) and uses proven libraries.
DevSecOps - Safety on conveyor
Automated safety gates at each stage
Change in conveyor step by step
Where automatic gates can stop the change. Green note shows when the gate stops it.
One change in production
- 1DeveloperBefore commit: mystery scanning locally
The key that goes into git history must be changed - deletion from history does not help.
- 2Developer → CIpull request
Gates are stopped if: a secret found in the code or a critical error found in SAST
Conveyer starts automatic checks. If the gate falls, no change is made.
- 3CISAST code, SCA dependence, second person reviews
Tools find certain samples, man - logic errors that the tools do not see.
- 4CIBuilds image → scans → SBOM → signs
SBOM is a list of ingredients. The signature proves that the image comes directly from this conveyor.
- 5CI → Environmentsigned image + SBOM
The gate is stopped if: signature does not match or the image has critical vulnerability
The environment only accepts signed images - a hand-made image is not launched.
- 6EnvironmentDAST in test environment: Checks the work app from the outside
Finds what is only seen in operation: configuration, headers, authentication.
- 7EnvironmentRelease into production with possibility to return to previous version
If something goes wrong, return is one step, no new building.
- 8NoteThe conveyor itself is aimed at: minimal rights, secrets outside the code, verified third party activities
That takes over the conveyor, it can deliver its code to all users.
A command for each pipeline stage
These commands become gates: a non-zero exit code stops the pipeline.
Pre-commit
-
Finds secrets in changes before they reach the history.
gitleaks git --pre-commit --staged .
Commit and pull request
-
SAST for the changed code only.
semgrep ci -
SCA: dependencies with known vulnerabilities.
osv-scanner scan source -r .
Build
-
Checks Dockerfile good practice.
hadolint Dockerfile -
Creates the image SBOM.
syft <attēls> -o cyclonedx-json=sbom.json -
Signs the built image.
cosign sign <attēls>@sha256:<summa>
Test
-
DAST against the test environment.
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://<testa-vide>
Deployment
-
IaC and configuration check.
trivy config . -
Accepts only a signed image.
cosign verify --certificate-identity <identitāte> --certificate-oidc-issuer <izdevējs> <attēls>
Runtime
- Falco Application that alerts on suspicious container behaviour.
In practice
Each security tool becomes an automatic conveyor gate. Its security is scaled up by design rather than relying on manual testing under time pressure.
Reference
OWASP Top 10 CI/CD Security Risks, NIST SSDF SP 800-218, SLSA, DevSecOps (culture + automation).
Safety Note
The conveyor itself is the goal - to protect the secrets of the construction, to limit the authorisation and verification of the work of the conveyor (GitHub Actions etc.) so that the conveyor cannot compromise.
From one function to the whole system
Unit tests, integration, systems and acceptance tests
Each level finds a different error class. The lower the pyramid, the faster and cheaper the test, so the unit tests are the most, but the system tests - only the main flows.
| Level | What is covered | Who checks | What and when |
|---|---|---|---|
| Unit test | What is coveredOne function or class without network and database. | Who checksLimit values, invalid input, error paths. | What and whenDeveloper, every committee. |
| Component test | What is coveredOne module or service with replacement dependings. | Who checksModule behaviour through its public interface. | What and whenDeveloper, every committee. |
| Integration test | What is coveredSeveral parts together: code, real database, row, cache. | Who checksTransactions, blocking, migration, data formats. | What and whenDeveloper, CI for each change request. |
| Contract test | What is coveredAPI agreement between the consumer and the provider. | Who checksWhether the change breaks another service or external partner. | What and whenTeams on both sides, CI. |
| System test (E2E) | What is coveredThe whole system along the right chain as user demand. | Who checksFull flows: registration, purchase, confirmation. | What and whenTester or CI, in the test environment. |
| Approval test (CAT) | What is coveredBusiness requirements from user view. | Who checksWhether a person can accomplish a task or not. | What and whenCustomer or users, before release. |
| Regression test | What is coveredThe behavior of already working after changes. | Who checksDoes the old mistake not return. Test for each modification. | What and whenAutomatically, in every construction. |
| Smoke test (smoke) | What is coveredSome major roads immediately after deployment. | Who checksWhether the system lives at all before watering. | What and whenAutomatically, after deployment. |
Typical commands for each level
Examples for a Python project, other languages have similar tools.
Unit tests and coverage
-
Fast tests without network or database.
pytest tests/unit -q -
The build fails when coverage is below the threshold.
pytest --cov=app --cov-fail-under=75 -
Mutation test: do the tests notice changed code.
mutmut run
Integration tests
-
Starts a real database and queue for the tests.
docker compose -f compose.test.yml up -d db redis -
The code together with its real dependencies.
pytest tests/integration -q -
Checks the API against its schema with generated input.
schemathesis run https://<resurss>/openapi.json
System and acceptance tests
-
A real browser walks a user flow from start to finish.
npx playwright test -
Acceptance tests in human-readable scenarios.
behave features/ -
Smoke test after deployment: does the system respond.
curl -fsS https://<resurss>/health/
Performance and accessibility
-
Load test with 100 concurrent users for five minutes.
locust -f locustfile.py --headless -u 100 -r 10 -t 5m --host https://<resurss> -
Load scenario with thresholds that can stop the build.
k6 run load.js -
Automatic accessibility check against WCAG.
npx pa11y https://<resurss>
Non-functional tests
- Performance: The load test measures the expected volume, the stress test finds the limit of a sustained memory leakage.
- Security: static analysis, addictive scanning, dynamic scanning and intrusion test (future tab).
- Availability: automatic check and hand check of keyboard or screen reader.
How to test the tests themselves
- The test first falls for the reason corrected. A test that has never been red does not guarantee anything.
- The coating shows what was not fulfilled, not what was verified.
- The mutation test shall change the code and shall measure whether it is visible by the tests.
- A control adjacent to a negative test which proves that the target is real.
Most frequent errors
- When you replace the database with a lighter one, you miss the errors of the real database, such as queue blocking.
- Only a lucky road: money and access must also be checked with repeated, parallel and foreign requests.
- An unstable test teaches the goal to ignore. Fix or remove it, do not repeat to green.
Automated safety testing
SAST, SCA, DAST, IAST - who finds anything
Typical commands for each method
Run only against your own projects or with written permission.
SAST
-
Static analysis with rules that fit the project.
semgrep scan --config auto
SCA
-
Dependencies against public vulnerability databases.
osv-scanner scan source -r . -
Python dependency check.
pip-audit -r requirements.txt -
Node.js dependency check.
npm audit
Secret scanning
-
Checks the whole git history.
gitleaks git .
DAST
-
Active scan. Test environment only, because it sends real requests.
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-full-scan.py -t https://<testa-vide>
IAST and fuzzing
- Contrast Assess IAST application: an agent in the app during functional tests.
-
Fuzzing one function with random input.
go test -fuzz=Fuzz<Funkcija> -fuzztime=60s
Containers and IaC
-
Vulnerabilities in image packages.
trivy image <attēls> -
Infrastructure code check.
checkov -d .
In practice
Combine methods according to conveyor section: static (SAST/SCA/secret) early, dynamic (DAST/IAST) tests, infrastructure scanning before deployment.
Reference
OWASP (test tools - ZAP, Dependency-Check), NIST SSDF SP 800-218, CIS Benchmarks, OSS-Fuzz (continuous fuzzing).
Safety Note
Tools find known templates, not business logic errors. Automated testing does not check whether access control is logically correct - it is found by a manual review and intrusion test.
Software supply chain integrity
SBOM, signature and SLSA levels
Supply chain commands
Each step leaves evidence that can be verified before running.
Source
-
Verifies the commit signature.
git verify-commit HEAD -
Pins dependencies with hashes.
pip-compile --generate-hashes requirements.in
Build
-
Verifies that the artifact was built from the expected source.
slsa-verifier verify-artifact <fails> --provenance-path <fails>.intoto.jsonl --source-uri github.com/<org>/<repo>
Artifact
-
Creates the SBOM.
syft <attēls> -o cyclonedx-json=sbom.json -
Answers whether a specific CVE affects you.
grype sbom:sbom.json
Deployment
-
Verifies the signature before running.
cosign verify --certificate-identity <identitāte> --certificate-oidc-issuer <izdevējs> <attēls>
In practice
SBOM allows a quick answer "do we are affected by this CVE?"; origin (provenance) and signature proves that the artefact (the final file of the building) comes from a reliable, genuine construction process. Together they protect the supply chain.
Reference
SLSA v1.0, NIST SSDF SP 800-218, SPDX/CycloneDX (SBOM formats), Sigstore/cosign, in-tototo, US EO 14028, EU Cyber Resilience Act (Regulation (EU) 2024/2847): reporting on active use of injuries from 11 September 2026, full requirements from 11 December 2027.
Safety Note
Most code is third party addiction. SolarWinds and similar incidents show - compromised construction or addiction to circumvent all other protections. Verify before launch.
Abbreviations
All abbreviations used in the guide (original and meaning).
- SDLC
- Software Development Life Cycle - software development life cycle.
- SSDLC
- Safe SDLC - life cycle with built-in safety.
- SDL
- Security Development Lifecycle - Microsoft secure development process.
- SSDF
- Secure Software Development Framework - NIST SP 800-218.
- SAMM
- Software Assurance Integrity Model - OWASP maturity model.
- BSIMM
- Building Security In Matrity Model - real practice measurement.
- E2E
- End-to-End - all system test along the right chain.
- UAT
- User Acceptance Testing - user acceptance test.
- SAST
- Static Application Security Testing - Statistical Source Analysis.
- DAST
- Dynamic Application Security Testing - Test of the running application.
- IAST
- Interactive Application Security Testing - instrumented performance test.
- SCA
- Software Composition Analysis - addiction/component analysis.
- RASP
- Runtime Application Self-Protection - self-defence of execution time.
- WAF
- Web Application Firewall for web applications.
- DevSecOps
- Security is embedded in DevOps culture and automation.
- CI/CD
- Continuous integration/delivery (conveyor).
- IaC
- Infrastructure as Code - infrastructure as code.
- SBOM
- Software Bill of Materials - a list of software components.
- SLSA
- Supply-chain Levels for Software Artifacts - supply chain levels.
- CWE
- Common Weakness Enumeration - software weakness classification.
- CVE
- Common Vulnerabilities and Exposures - a public vulnerability register.
- ASVS
- OWASP Application Security Verification Standard.
- STRIDE
- Threatened Modeling Categories (Microsoft).
- MFA
- Multi-Factor Authentication - Multifactor Authentication.
- TLS
- Transport Layer Security - transport layer encryption.
- CRA
- EU Cyber Resilience Act - EU cyber resilience regulation.
- provenance
- Origin note - how and from which the artefact was built (SLSA).
- artefakts
- Final result of the construction - executable, package or container image.
- build
- Construction - conversion of source to a launchable artefact.