Our support package for WordPress plugins has a redactor: before a site report leaves the site, it strips things like email addresses, IP addresses, JWTs and long tokens. Its tests need inputs that look like real credentials, or they prove nothing.
That is a problem. Secret scanners flag anything shaped like a Stripe, GitHub, AWS, Slack or Google key, a JWT or a PEM private key block, even when it is obviously fake. A fake key committed to a public repository still sets off alerts, and teaches everyone to ignore them.
So the rule in our tests/README.md is: never commit key-shaped literals, in source, docs or fixtures. Build them at runtime, so no contiguous key-shaped string exists in the file:
// Joined at runtime: the file never holds the full key shape.
$fake_stripe_key = implode( '_', array( 'sk', 'live', str_repeat( 'x', 24 ) ) );
$this->assertStringNotContainsString(
$fake_stripe_key,
Redactor::redact( "key=$fake_stripe_key" )
);
The redactor still sees the real shape. The scanner sees three harmless strings.
(The snippet shows the idea; adapt the class and method names to your own redactor.)
Two habits that go with it:
- Write the rule down where contributors look first, next to the tests.
- Don't silence the scanner for the test folder. Then a real key pasted into a fixture by mistake still gets caught.
Guide: https://mammothwp.com/guides/wordpress-plugin-support-screen-mammothwp-support/
Top comments (0)