Proof of work

Proof-of-work CAPTCHA extension

The Proof of work extension is a CAPTCHA built into Comentario. Before a protected action, the visitor’s browser has to solve a small computational puzzle, which makes every action cost a bot some CPU time.

It needs no API key, sends nothing to a third party, sets no cookies, and works on installations without internet access. The visitor doesn’t have to do anything: the puzzle is solved in the background when they submit, which typically takes under a second.

How it works

  1. When a visitor submits a protected action, the comments widget requests a challenge from Comentario.
  2. The browser finds the number that, appended to the challenge’s salt, produces a given SHA-256 hash. The puzzle runs in a Web Worker, so that the page stays responsive.
  3. The solution is sent along with the action, and Comentario checks it before doing anything else.

A challenge is signed by the server, and it’s bound to the domain and the action it was issued for. It expires after five minutes and can only be used once. The challenge follows the ALTCHA format.

Which actions require a solution is set in the domain configuration:

All of them are on by default, so enabling the extension is all it takes to protect the domain.

NOTE
Proof of work doesn’t tell humans from bots: it only makes each action more expensive. A determined spammer with enough computing power still gets through, which is where the spam checking extensions and moderation come in. A solved CAPTCHA doesn’t let a comment skip moderation.

Configuration

The extension has a single parameter:

ParameterDefaultDescription
maxNumber100000Difficulty: the largest number the challenge’s secret number is picked from, an integer from 1000 to 10000000

The browser tries the numbers one by one, so solving takes half as many hashes on average, and up to maxNumber at most. The default takes a phone about a second. Raising the difficulty makes each protected action costlier for a bot, and slower for a human too. A change applies to the challenges issued from then on, which makes it something to turn up while under attack.

It can be disabled for the whole instance with extensions.pow.disable in the secrets.

Proof of work can also protect the Administration UI’s registration, password reset and login pages, see CAPTCHA provider for Administration UI. Its difficulty there is set by Proof-of-work CAPTCHA difficulty.

If you run several Comentario instances serving the same website, set the server signing key: challenges are signed with a key derived from it, and one issued by an instance is otherwise refused by another.

Content Security Policy

The puzzle runs in a Web Worker started from a blob: URL. If the embedding page has a Content Security Policy, allow it with:

worker-src blob:

Without it, the puzzle is solved on the page’s main thread, which works just as well, but may make the page less responsive while it runs.

See also