Pentest in production or staging? Risks, conditions and who decides
By Kike Gandia · Co-Founder & CEO, OSCP · Last updated:
We recommend running the pentest in a staging environment that is equivalent to production and uses fictitious data, because it allows unrestricted testing without affecting users or exposing personal data. Production is kept for what only exists there and for the final retest. The decision belongs to the client, and should be taken with the risks in writing. This guide explains what is tested in each environment, what can go wrong in production and under which conditions it is done well.
What is tested in each environment
| Staging | Production | |
|---|---|---|
| Aggressive tests (injections, feature abuse, load) | Yes, without affecting real users | Only limited ones, agreed in advance |
| Data | Fictitious | Real |
| Business risk | Low | Real, though small if tests are controlled |
| Real configuration (WAF, CDN, DNS, certificates, integrations) | Only if the environment is equivalent | Yes: it is what exists |
| Role in the project | Main test | Verifying what only exists there and the final retest |
Real risks of testing in production
A pentest tries to break things in a controlled way, and in production what breaks is real. There are three concrete risks:
- SQL injection on real data: a test that writes, modifies or deletes can alter customer data.
- An IDOR that lists every customer's data: to demonstrate the flaw, the pentester may end up seeing personal data of real people who have nothing to do with the test.
- Loss of availability: an intensive test on an expensive endpoint can degrade the service for users.
With manual, controlled testing these risks are uncommon, but not zero, which is why the client must know them before deciding.
What a good staging environment needs
Testing in staging is only worthwhile if the environment resembles the real one. A pentest test environment should have:
- Equivalence with production: same code versions, same operating system, same server and same configuration. The closer it is, the more reliable what is found.
- Fictitious data: no real personal information, so that no finding exposes anyone's data.
- The same protections active, or a documented difference: if production has a WAF and staging does not, that must be known to interpret the results.
- Third-party integrations in test mode (payment gateways, email, ERP), so that an attack does not trigger payments or send real messages.
If staging differs greatly from the real environment, what is fixed there may not be what matters in production.
What can only be checked in production
Some things no test environment fully reproduces, which is why production does not disappear from the plan:
- The real network configuration: the WAF or CDN filtering traffic, DNS rules, certificates and the headers that actually reach the browser.
- Real integrations with third parties, which in staging are usually in test mode.
- Behaviour under real volume: request limits, caches and queues that go unnoticed with three test users.
- What was fixed and deployed: only in production can you confirm that the fix reached the place where it matters.
The key is that these checks are specific and limited, not a repeat of the whole pentest.
Controlled production: the conditions
When testing in production is necessary, or the client requires it, it can be done under conditions that reduce the risk:
- Agreed time windows, preferably during lower activity.
- Recent, verified backups before starting.
- Dedicated test accounts, so that data created or modified is identifiable and reversible.
- Exclusion of destructive tests: no mass deletions and no denial-of-service tests.
- A reachable technical contact during the tests, able to stop or restore.
All of this should be in the rules of engagement, signed before starting.
The recommended flow: staging first, production last
The combination that best balances risk and evidence is this:
1. Pentest in staging, with every test, including the most aggressive ones.
2. Remediation of the findings by the development team.
3. Deployment to production of the fixes.
4. Retest in production, limited and without destructive tests, so that the final evidence comes from the real environment and shows that what was fixed is still fixed where it matters.
This way testing is thorough where it is safe and confirmed where it is real. To see how these tests fit into a project, read the phases of a web pentest.
If your WAF or your SOC detect the tests
When a WAF or a SOC detects the pentest it is a good sign: the defence works. But you must decide beforehand how the testing is done:
- With defences active, to measure whether they detect and block the attacker. The report can include the detections as an annex.
- With the pentester's IPs on an allow list, to assess the application in depth without the WAF blocking every test.
If this is not agreed, the pentest ends up measuring the WAF and not the application: a real attacker who evades it would find the application unfiltered. You also need to notify whoever runs the SOC, the WAF or the hosting, with dates, windows and source IPs, so that an authorized test is not treated as a real incident and a real attack is not mistaken for the test.
How the report should reflect it
A good report makes clear in which environment each thing was tested. It should state the test environment, the known differences from production (for example, a disabled WAF or a simulated third-party service) and the limitations this entails. That way whoever reads it, be it the technical team, an auditor or a client, knows what the document claims and what it does not. The production retest should appear as a section of its own, with evidence that each fix works in the real environment.
Who decides
The decision belongs to the client, not the pentester. The provider recommends and explains the risks; the client chooses the environment and the conditions, and records them in writing in the contract or the rules of engagement. If they decide to test in production, they accept the risks to data and availability that have been described in writing, which is why it should be signed by someone with authority over both.
If you are not yet sure of the type of test, start with black, grey or white box; to organize access and documents, how to prepare for a pentest; and to choose a provider, how to hire a pentest.
FAQ
Is it better to run the pentest in production or in staging?
We recommend staging: an environment equivalent to production with fictitious data, where an aggressive test does not affect users or expose personal data. Production is for verifying what only exists there and for the final retest. The client decides, with the risks in writing.
What can go wrong in a production pentest?
A SQL injection altering real data, an IDOR showing the pentester every customer's data and an intensive test degrading the availability of the service. With manual, controlled testing it is uncommon, but the risk is not zero, which is why conditions are agreed in advance.
My client requires testing in production, what do I do?
It can be done, with conditions: time windows, recent backups, dedicated accounts, no destructive tests and a reachable technical contact. The usual alternative is to test in staging, fix, deploy and run the retest in production, so the final evidence comes from the real environment.
What happens if my WAF or my SOC detect the pentest?
It is a good sign. You need to agree beforehand whether testing is done with defences active or with the pentester's IPs allowed. Without that agreement, the report would measure the WAF and not the application. Detections are reported and can be attached to the report as an annex.
Do I have to notify my monitoring or hosting provider?
Yes. They need the dates, time windows and source IPs, so that an authorized pentest is not treated as a real incident and a real attack is not mistaken for the test. The client handles the notice, using the dates and IPs the pentester provides.
Related service
web penetration testing in Spain
Related content
- SaaS application penetration testing
- Cloud penetration testing: environments and configuration
- Phases of a web pentest
- How to hire a pentest
- Black, grey and white box: which type of pentest you need
- How to prepare for a pentest: documents, access and data
- WAF in the offensive security glossary
- Remediation retest in the glossary