Test your login's brute-force protection

A login endpoint that answers every wrong password instantly, forever, lets anyone try a password list against any account. Most teams believe their login is protected by "the rate limiter". This test checks whether that's true, on the endpoint that matters most.

The folder

Brute force folder, three requests:

  1. Wrong password: POST {{baseUrl}}/auth/login with {"email": "{{bruteForceEmail}}", "password": "wrong-{{$guid}}"}.
  2. Unknown email: the same with an email that doesn't exist.
  3. Unlock test account: an admin or test-only endpoint that resets the lock, if your API has one.

Send the burst with setNextRequest

Make Wrong password repeat itself until it's refused or 20 attempts have passed:

JavaScript
// Tests on "Wrong password"
const attempts = Number(pm.variables.get('attempts') || 0) + 1;
pm.variables.set('attempts', attempts);

if (pm.response.code === 429 || pm.response.code === 423) {
  pm.variables.set('blockedAfter', attempts);
  pm.test(`login is limited after ${attempts} attempts`, () => {
    pm.expect(attempts).to.be.at.most(20);
  });
} else if (attempts < 20) {
  pm.execution.setNextRequest('Wrong password');
} else {
  pm.test('login is limited within 20 attempts', () => {
    pm.expect(pm.response.code).to.be.oneOf([423, 429]);
  });
}

When the run ends without a jump, it continues with the next request in the folder. setNextRequest works in the collection runner and the CLI; a single Send ignores it.

What a good response looks like

  • 429 Too Many Requests with a Retry-After header: the IP or account is rate limited.
  • 423 Locked or a specific error code: the account is locked for a while.
  • A CAPTCHA or "verify it's you" challenge: also fine. Adjust the check to your API's response.
JavaScript
pm.test('Retry-After tells the client when to try again', () => {
  if (pm.response.code === 429) pm.expect(pm.response.headers.has('Retry-After')).to.be.true;
});

Don't reveal which emails exist

Compare Wrong password with Unknown email. The status and message should be the same, so an attacker can't use the login to find out who has an account:

JavaScript
// Tests on "Unknown email"
pm.test('unknown email looks like a wrong password', () => {
  pm.response.to.have.status(401);
  pm.expect(pm.response.json().error).to.equal('invalid_credentials');
});

Also check the password reset endpoint the same way: "If this email has an account, we sent a link" for both cases.

Lock-out without a denial of service

Account lockout has a downside: anyone can lock anyone out by guessing wrong on purpose. If your API locks accounts, check that:

  • the lock lasts minutes, not until an admin steps in,
  • the right password from a known device, or a reset link, still gets the user in.

Clean up

End with Unlock test account, or wait out the lock in a cleanup step, so the next run starts fresh. If several pipelines share the test account, give each its own (bruteforce+ci@…, bruteforce+nightly@…).