Reviews and testimonials
Reviews: star picker, testimonials, moderation queue
For when the answer to “It shows reviews or testimonials from the public” is yes.
Rebuilt in ~16/20 projects. Takes text from strangers and puts it on your most-trusted page, so it is the easiest place on a small site to get XSS'd, and the easiest place to accidentally publish spam.
Built by hand again in 16 of 20 audited projects before this existed. Each rebuild was another chance to make the mistake below.
Skip the rebuild
You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.
- Download the Playground. It is free and runs on your own machine.
- Start a new app and tick “It shows reviews or testimonials from the public”.
- This block is written in, along with anything else you ticked.
The mistake it removes
The two failure modes are structural, not stylistic: rendering submitted text as HTML, and publishing on submit because 'pending' felt like day-two work.
What is already handled
Some are checked by running the block’s own tests every time its checks run and some only by reading the shipped source. Each item’s label says which. An item tested only in part says so in its label. Tested means the block’s own test suite runs that code. It does not mean a live run against an outside service such as a payment provider.
- 124 assertions (counted here: test/ui-reviews.test.mjs), including the ones that load vanilla/reviews.js itself and drive it against a hand-rolled DOM double, plus 17 browser assertions (counted here: test/ui-reviews.browser.test.mjs) that import vanilla/reviews.js into headless Chromium, all passing Tested
- 5 real XSS payloads (script, img onerror, svg onload, attribute-break, javascript: iframe) render as visible TEXT. In headless Chromium (test/ui-reviews.browser.test.mjs) the shipped widget, imported as a module and rendered through createReviews() with showAll and rotating, leaves zero SCRIPT, IMG, SVG or IFRAME elements in the page beyond the harness's own script and no B element in the widget, shows each payload character for character as text, and trips nothing: no dialog, no write to the page's tripwire, no request for the img payload's src. In the same run a copy of the file with its one text path switched to innerHTML is caught by that counter and that tripwire, so the zero is not a counter that sees nothing. The node suite also loads the widget against a DOM double and asserts no innerHTML, outerHTML or insertAdjacentHTML write happens. Tested
- the element helper has no innerHTML path at all, so the safety is structural rather than a rule to remember Read in the source, not run
- submit() always writes status:'pending'; no code path sets 'approved' on submit Tested
- omitting requireAdmin makes moderate() and listPending() return 503 (verified), so an unguarded queue is unreachable rather than merely discouraged Tested
- a rejected admin mutates nothing (state compared before/after) Tested
- an append-only store is refused: the first approval answers 500, nothing becomes public, and a retry writes nothing more; an upsert store and a store with update(id, patch) moderate normally with exactly one row per review Tested
- listPublic() filters to approved AND projects through PUBLIC_FIELDS, so submitter ip/status never serialize to the public Tested
- the widget renders a review's author, body, date and rating and nothing else: a review row carrying ip, email, status, moderatedBy, previousStatus, forwardedForClaimed and moderatedAt puts none of them into any text or attribute on the page (node suite, DOM double). Ratings are rounded and clamped into 1 to 5, 5,000 loaded reviews render as 50 cards, an empty list says 'No reviews yet.', and a failed load shows a role=alert message that never carries the error text. Tested
- rating coerced and range-checked: 99, 0, -3, NaN, Infinity and 'abc' all rejected; 4.6 rounds to 5 Tested in part
- rejected submissions do not burn rate-limit budget, so a typo can't lock out a real reviewer; the 4th VALID review from one IP is still limited and not stored Tested
- the limiter's memory is bounded: a key whose window has passed is swept on the next stored review, and past 10,000 distinct live keys the oldest is evicted. A client rotating forwarded addresses behind a trusted proxy cannot grow the process without limit, and a real peer inside its window is still limited while the map is under the cap. Tested
- createReviews().destroy() removes every listener it added and stops the timer, so nothing leaks across SPA re-mounts. Graded in the node suite against a DOM double: three mount and destroy cycles on one node each hold 4 mount listeners, 1 media-query listener and 1 timer, and after the last destroy() all three are empty. A widget destroyed while load() is in flight ignores the late answer. Tested
- auto-rotation shows one card at a time on the caller's interval and wraps; it starts no timer under prefers-reduced-motion, with showAll, or with a single review, and starts when the reduced-motion preference is switched off; mouseenter and focusin on the mount stop the timer and mouseleave and focusout restart it. Graded in the node suite with the timer captured. What is NOT graded: real hover and real focus. Tested in part
- while it rotates, the wrapper holds a Pause/Play button (type=button, first in the wrapper, named 'Pause reviews' or 'Play reviews' by what pressing it does) for WCAG 2.1 2.2.2. Pressing it stops the timer and keeps the shown card, a user pause survives the pointer or focus leaving and a refresh(), and pressing again restarts it. It is the widget's one focusable element, so focusing it pauses rotation through the focusin handler. No button is rendered with showAll, with a single review, or under prefers-reduced-motion, and it appears or goes when that preference changes. The rotating wrapper carries no aria-live, so a screen reader is not told about each new card. Graded in the node suite against a DOM double; that a real browser puts the button in the tab order and a screen reader reads its name was not run here. Tested in part
- star picker is a fieldset with the legend 'Your rating' and five radio inputs sharing one name, each with a label whose for names it; a starting value reads back and choosing a star calls onChange with it (graded in the node suite against a DOM double). THAT A SCREEN READER ANNOUNCES IT AS ONE GROUP WAS JUDGED IN THE AUDIT BROWSER RUN OF 2026-07-17, not here. Tested in part
- internal errors log server-side but never reach the client or the page Tested
- a request body that is not valid JSON, or is JSON but not an object, is answered 400 with the one message 'the request body is not valid JSON' on both submit and moderate, never a 500 and never the parser's own error text; nothing is stored and nothing is moderated. A valid JSON string body is read as before. Tested
- the 'may quote in ads' box is drawn unticked with no option to pre-tick it; submit() stores only JSON true or the checkbox's 'on' as quoteConsent { given: true, at } and everything else, 'yes' included, as not given; the answer never reaches the public reader; withdrawQuoteConsent guards itself, keeps when the yes was given, adds when and by whom it was withdrawn, and leaves the review's status alone Tested
What the audit found
Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.
- The rate-limit ceiling is not pinned: MAX_PER_WINDOW 3->4 and >= -> > both survive every test major · Verification integrity Fixed after the audit in
930d57c94 - moderate() assumes store.put() upserts by id; the documented store contract never says so, and an append-only store yields a review that is both pending and public major · Correctness Fixed after the audit in
5fee0802e - The in-memory `hits` Map grows one entry per distinct key and is never pruned; behind a trusted proxy the key is header-chosen, so an attacker can grow it without bound major · Stress & robustness under extremes Fixed after the audit in
2b421b2e7 - Approving or rejecting a review leaves no record of who did it, when, or what it was before major · Security Fixed after the audit in
136a95c56 - A malformed JSON string body answers 500, not 400 minor · Error handling & resilience Fixed after the audit in
92fa921ee - Rotation 'pauses on focusin for keyboard users' but nothing in the rendered widget can take focus, and there is no visible stop control (WCAG 2.1 2.2.2) minor · Accessibility Fixed after the audit in
b0ce8ad85 - installReviewStyles() writes a page-wide `:focus-visible` rule, not a widget-scoped one minor · Code quality Fixed after the audit in
295d2291b
One more finding is written in the auditors' internal shorthand, so it is not listed here. The full text is in the report inside the block. It was fixed after the audit, in 44fe1d7dd.
What you still have to do
A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.
- Supply requireAdmin (admin-kit's, or your own) and serve over HTTPS. Without requireAdmin, moderate() and listPending() return 503: the queue is unreachable rather than unguarded, which is safe but also unusable, so an install that skips it has no moderation at all.
- A keyboard-and-screen-reader pass on YOUR page. The block ships the wiring it can ship (aria-label on the rating controls and an aria-live region for the submission result), but color contrast, heading order and the focus order across everything around it are properties of the page you drop this into, and no test here can see them. Run one manual keyboard pass and one screen-reader pass before you launch.
- Set a retention policy for the stored submitter IP and disclose it in your privacy page. Under GDPR an IP is personal data, and the block keeps it for moderation without expiring it.
- A rate limiter backed by Redis or by your edge if you become a spam target. The one shipped here is in-memory and best-effort; on serverless it covers one warm instance.
- You supply the store, so its durability and backups are yours. The block is storage-agnostic and guarantees only that it writes through your put().
- Reviews render client-side, so crawlers won't see them in the HTML. If testimonials matter for SEO, server-render them or emit schema.org JSON-LD.
- The block validates and caps; it does not detect spam content. A human still approves each review: deliberately.
What lands in your project
vanilla
- vanilla/reviews.js
createReviews({ mount, load, limit }) rotates testimonials and returns { refresh, stop, destroy, count }: call destroy() when unmounting. createStarPicker({ mount, onChange }) is a radio group. createQuoteConsent({ mount }) draws the 'may quote in ads' box, always unticked; send its .checked as quoteConsent. Call installReviewStyles() or bring your own CSS.
node
- node/reviews-api.js
createReviewsApi({ store, requireAdmin }) returns { submit, listPublic, listPending, moderate, withdrawQuoteConsent }. submit() stores the 'may quote in ads' answer as quoteConsent { given, at }; withdrawQuoteConsent records a customer taking it back. The admin routes guard themselves: omit requireAdmin and they answer 503 rather than opening up.
What you supply
- store: { all(): Promise<Review[]>, put(review): Promise<void>, update?(id, patch): Promise<void> }: the block is storage-agnostic, but put(review) MUST replace the row with the same id, never append a second one. Supply update(id, patch) and moderation uses it instead; without it, the first moderation checks that put() replaces and refuses every approval with a 500 if it appends, because an appended approval would leave one review pending and public at once.
- requireAdmin: admin-kit's requireAdmin(req,res). Required for listPending/moderate to function at all.
- publicLimit: max approved reviews returned publicly (default 100)
- limit: max cards rendered by createReviews (default 50)
Licensed MIT. It is a starting point, not a finished product.
Get it
Download the Playground See the other blocks
Nothing here is locked. The files are yours, in your folder, under a permissive license.
Questions
- Is Reviews and testimonials audited?
- It was audited on 2026-09-29, and the verdict was not a clean pass. 8 findings have been fixed since then, and the verdict stands until the block is audited again.
- What do I still have to do myself?
- Supply requireAdmin (admin-kit's, or your own) and serve over HTTPS. Without requireAdmin, moderate() and listPending() return 503: the queue is unreachable rather than unguarded, which is safe but also unusable, so an install that skips it has no moderation at all.
- How do I get this code?
- Download the Playground, start a new app, and tick “It shows reviews or testimonials from the public”. The block is written into your project as ordinary source you can read and edit.
All pre-built code blocks · Learn to build from zero · The coding guide