Case study
Code IQ website audit
A free tool that checks a small business’s website and reports what needs fixing in plain English, with a suggested fix for each finding. The findings are produced by deterministic checks written in TypeScript. A language model is used to write the summary at the top of the report.
- Role
- Design and development
- Built for
- Code IQ, my own web agency
- Timeline
- September to November 2026
The brief
Small-business owners often don’t know what condition their website is in or what to fix first. I built the audit to tell them. It needed to be free to use, safe to run against any address a member of the public enters, and understandable to someone without a technical background.
The main design decision was to keep language models out of the checking. If you give a model a web page and ask it to list the problems, it returns a plausible report whether or not it has read the page correctly, and there is no reliable way to tell which reports are wrong. A coded check gives the same result every time, and when a result is wrong the cause can be found and fixed.
What was built
The system is a single Node service with a web front end and a scheduled job for weekly re-checks. An audit runs in stages.
-
Request
The user enters a domain at codeiq.co.uk/audit. Results are shown section by section as they become available, so the first ones appear after about a second while the slower checks are still running.
-
Data collection
The service fetches the site’s pages the way a browser would, with rate limiting and a cap on the number of requests. It also queries DNS, the domain registry, Google PageSpeed, Google Maps, Google Safe Browsing and the main AI assistants.
-
Checks
Each check takes the collected data and produces findings. The checks are pure functions, so the same input always produces the same findings.
-
Report
Findings are grouped by priority: fix now, fix soon and hardening. A language model writes a summary of them for the top of the report. If the model is unavailable or returns something unusable, a template produces the summary.
-
Monitoring
Sites on a monitoring plan are re-checked weekly, and the owner is emailed when something has changed.
- TypeScript
- Node 22
- Fastify
- SQLite
- Zod
- Vitest
- Astro
- GitHub Actions
- nginx
Back end. The service does not run a headless browser. Google PageSpeed already loads the page in Chrome as part of its test, so the audit uses that data for anything that needs a rendered page, such as layout shift, tracking tags that load before consent, and colour contrast.
Front end. The audit page is part of the Code IQ site, built with Astro and the agency’s shared UI library. It renders each section of the report as the data arrives and announces progress to screen readers through an ARIA live region. Text that came from the audited site is inserted with textContent, so it cannot be interpreted as HTML.
What it checks
-
Security and exposure
HTTPS and certificates, security headers, cookies, API keys exposed in JavaScript, and files left in the web root such as
.env,.git, backups and AI-assistant config files. -
Signs of compromise
Scripts loaded from hosts known to have served malware, hidden spam links, obfuscated inline scripts, and Google Safe Browsing warnings.
-
Speed
Google PageSpeed scores and Core Web Vitals, including which element is the largest contentful paint and which loading phase takes the most time.
-
Search and sharing
Titles, descriptions, canonical tags and share previews on the home page and a sample of other pages, plus the contents of the sitemap.
-
AI assistants
Asks ChatGPT, Gemini, Perplexity and Claude about the business, and checks whether robots.txt allows their crawlers to read the site.
-
Google Maps
Finds the Google Business Profile by website or phone number, then checks where the business ranks in local results for its service.
-
Email and domain
SPF, DKIM and DMARC records, blocklist status, and the domain’s expiry date from the registry.
-
WordPress and PHP
Core, plugin and theme versions compared with published security fixes, and the PHP version the site runs on.
-
Accessibility and privacy
Alt text, colour contrast, form labels and keyboard navigation, and tracking tags that load before consent is given.
Technical problems and solutions
The code excerpts below are taken from the service and shortened for the page. Each one is followed by a test that covers it. The most relevant lines are highlighted.
4.1Checking whether an AI assistant knows the business
The audit asks each assistant: “I’m thinking of using {business} in {town}. What can you tell me about them?” Checking the reply for the business’s name is not reliable, because assistants tend to repeat the name from the question even when the details they give belong to a different company with a similar name.
A reply is counted as a match if it links to the business’s website or includes its phone number or postcode. This is done with string comparison. Phone numbers are normalised to their last ten digits and postcodes are compared with spaces removed. No model is involved in assessing the reply.
/** The answer gives the business's own phone number or postcode. */
export function hasContactDetails(
text: string,
phone: string | null,
postcode: string | null,
): boolean {
if (
postcode &&
text.toUpperCase().replace(/\s+/g, '').includes(postcode.toUpperCase().replace(/\s+/g, ''))
) return true;
if (!phone) return false;
const want = phoneDigits(phone).slice(-10);
if (want.length < 10) return false;
return [...text.matchAll(/\+?\d[\d\s().-]{8,18}\d/g)]
.some((m) => phoneDigits(m[0]).slice(-10) === want);
}
// …and where each assistant's answer is scored:
found: q.kind === 'about'
? linked || hasContactDetails(answer.text, business.phone, business.postcode)
: mentioned || linked,
// "needs the website, phone number or postcode:
// assistants repeat the name they were asked about"
expect(await run('If you mean Rooftech Acme Roofing Ltd, the Bridlington firm…'))
.toMatchObject({ mentioned: true, found: false });
expect(await run('Acme Roofing Ltd, 0113 496 0000, is well reviewed.'))
.toMatchObject({ found: true });
expect(await run('Acme Roofing Ltd is based at 1 Main St, Leeds LS14AB.'))
.toMatchObject({ found: true });
This runs the same comparison in your browser. The business is the made-up one from the test: Acme Roofing Ltd, phone 0113 496 0000, postcode LS1 4AB, website acmeroofing.co.uk. Pick an example or edit the reply.
The phone number and postcode comparison is the function shown above. The name and website checks are simplified for this demo.
4.2Preventing prompt injection from the audited site
The summary is written by a language model. If content from the audited site were included in the prompt, the site’s owner could add text to their pages instructing the model to ignore the findings or to describe the site as secure.
The prompt contains text written by the service and nothing fetched from the site: finding titles, categories, priorities and fixes. The reply is validated against a Zod schema, and the overall verdict is calculated from the finding counts and added afterwards. If validation fails, the function returns null and the template summary is used.
/** The prompt payload: only this service's own fixed text, never target content. */
export function llmPayload(report: AuditReport): object {
return {
site: report.finalUrl ? new URL(report.finalUrl).host : null,
platform: report.platform?.name ?? null,
auditType: report.tier,
// Our own detection result (a provider name we chose), never site content.
blockedByBotProtection: report.blockedBy ?? null,
counts: report.counts,
findings: report.findings.map((f) => ({
title: f.title,
category: f.category,
priority: f.priority,
severity: f.severity,
fix: f.remediation,
})),
};
}
/** Parses the model's reply; anything off-shape returns null so the template is used. */
export function parseLlmSections(raw: string, report: AuditReport): SummarySections | null {
const body = raw.trim().replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/, '');
try {
const parsed = LlmSections.safeParse(JSON.parse(body));
if (!parsed.success) return null;
return { ...parsed.data, verdict: verdictFor(report) };
} catch {
return null;
}
}
it('never sends target-derived evidence or URLs to the model', () => {
const payload = JSON.stringify(llmPayload(report()));
expect(payload).not.toContain('IGNORE PREVIOUS');
expect(payload).not.toContain('<injected>');
expect(payload).toContain('No Content-Security-Policy');
});
4.3Telling fixed problems apart from unchecked ones
Monitored sites are re-checked weekly and the owner is sent the changes. A finding can be missing from the new report because its check did not run, for example when Google PageSpeed is rate-limited, when bot protection blocks the request, or when the weekly run skips the paid checks. A direct comparison of the two reports would list those findings as fixed.
Each audit records the categories of finding it was unable to check. When a finding is missing from the new report, it is listed as fixed if its category was checked and as “not checked” if it was not. Google Maps and AI assistant results are compared when both runs queried them.
const unjudged = to.notChecked ?? [];
for (const [cls, f] of Object.entries(before)) {
if (now[cls] !== undefined) continue;
(classMatches(cls, unjudged) ? unchecked : fixed).push({ class: cls, ...f });
}
// Findability lines only mean something against an audit that asked the same sources. The
// weekly check does not pay for Google Maps or the AI assistants, so without this every
// week would report the listing lost and the recommendations withdrawn, and every monthly
// check would report them all won back.
const sameSources = key(from.asked) === key(to.asked);
const gained = sameSources
? (to.findability ?? []).filter((l) => !(from.findability ?? []).includes(l))
: [];
const lost = sameSources
? (from.findability ?? []).filter((l) => !(to.findability ?? []).includes(l))
: [];
it('reports a finding that is gone as unchecked, not fixed, when its check was skipped', () => {
const before = rec({
open: open(['perf/lcp', 'fix-now', 'The main content takes too long to appear']),
});
const after = rec({ at: '2026-10-20T09:00:00Z', jobId: 'j2', open: {}, notChecked: ['perf/lcp'] });
const d = diffRecords(before, after);
expect(d.fixed).toEqual([]);
expect(d.unchecked).toEqual([
{ class: 'perf/lcp', priority: 'fix-now', title: 'The main content takes too long to appear' },
]);
});
4.4Blocking requests to internal addresses (SSRF)
The service makes HTTP requests to addresses supplied by the public, which makes it a target for server-side request forgery. Validating the address before connecting is not enough, because a domain can return a public IP address during validation and a private one when the connection is opened (DNS rebinding).
The address check is implemented as a custom DNS lookup function that is passed to the connection, so the address that is checked is the address that is used. If any address in the DNS response is non-public, the connection is refused.
/**
* A drop-in `lookup` for net/tls.connect that resolves normally, then refuses
* the connection if ANY resolved address is non-public. Refusing on any (not
* just filtering) keeps a mixed public/private answer from being a lottery.
*/
// …inside that lookup, once DNS has answered:
if (err) return callback(err, []);
// …
if (!allowPrivate) {
const bad = list.find((a) => !isPublicAddress(a.address));
if (bad) return callback(new BlockedAddressError(hostname, bad.address), []);
}
if (opts.all) return callback(null, list);
const first = list[0]!;
return callback(null, first.address, first.family);
// "refuses to connect when a public-looking domain
// resolves to a private address (SSRF / rebinding)"
const toLoopback: Resolver = (_h, _o, cb) => cb(null, [{ address: '127.0.0.1', family: 4 }]);
const http = new AuditHttp({
targetUrl: 'http://innocent.example.co.uk/',
paceMs: 0,
resolver: toLoopback,
});
const r = await http.request('/');
await http.close();
expect(r).toEqual({ refused: 'blocked: resolves to a non-public address' });
-
Bot-protection pages
When a site’s bot protection returns a challenge page, the audit detects it and skips the checks that would otherwise run against that page. The report states that the site could not be read.
-
Wildcard DNS
Before looking for test and staging subdomains, the audit requests a random subdomain that should not exist. If it resolves, responses that match it are treated as a wildcard record and ignored.
-
Back-ported security fixes
Linux distributions often patch security issues without changing the version number. Findings about old PHP or library versions are worded as “predates the fix” and do not state that the site is vulnerable.
-
Domain ownership checks
The deeper checks require a DNS TXT record to show that the user controls the domain. The token in the record is an HMAC of the domain name, so the service does not need to store issued tokens.
Design decisions and trade-offs
The main decisions I made, why I made them, and what each one costs.
| Decision | Why | Trade-off |
|---|---|---|
| Deterministic checks for all findings | Results are repeatable, and an incorrect finding can be traced to the check that produced it. | Each check has to be written and maintained, and the audit finds a problem only if a check exists for it. |
| No headless browser | Google PageSpeed already loads the page in Chrome, which avoids running and maintaining a browser on the server. | The audit depends on Google’s rate limits. Forms are not tested, because that would involve submitting them. |
| SQLite in a single process | Reports persist across restarts without a separate database server. | The service cannot run as more than one instance without changing the storage. |
| Quick and full audit tiers | The quick audit makes the same requests a browser would, so it is open to anyone. The full audit makes additional probes and requires proof of domain ownership. | Users have to add a DNS record before they can run a full audit. |
| Weekly free checks, monthly paid checks | Google Maps and AI assistant queries have a cost per request, and their results change slowly. | A change in those results can take up to a month to be reported. |
Tests and delivery
The service is covered by automated tests, and the whole suite runs in a second or two, so it gets run on every change. Nothing in the tests touches the outside world. DNS responses come from an in-memory table, HTTP responses from a local fixture server with test certificates, and AI assistant replies from a stubbed fetch.
Test names describe the behaviour they cover. Some examples:
- needs the website, phone number or postcode: assistants repeat the name they were asked about
- never sends target-derived evidence or URLs to the model
- falls back to the template when no key or model is configured
- reports a finding that is gone as unchecked, not fixed, when its check was skipped
- never lists an unchecked finding as fixed
- reports an outage and claims nothing about findings
- stays quiet when the site was already down
- refuses to connect when a public-looking domain resolves to a private address (SSRF / rebinding)
- refuses a mixed public/private DNS answer rather than picking one
Build and deployment
-
Type checking
TypeScript runs in strict mode with
noUncheckedIndexedAccessenabled, so array and object lookups that may be undefined have to be handled explicitly. -
Continuous integration
GitHub Actions runs the type check and the full test suite on every push. Pushes to main are then built, deployed and health-checked automatically.
-
Production permissions
The service runs as a dedicated system user with no login and no write access to its own code. The deploy user’s only elevated permission is restarting the service.
-
Pull requests
Later changes were made through numbered pull requests with descriptive titles, for example “Read the names ChatGPT recommends, not just the ones it bolds”.
Lessons from the project
-
Limit what the model is responsible for
The model writes the summary and has no part in the checks or the verdict. Any mistakes it makes are limited to wording, which is easy to spot and low-risk.
-
Keep untrusted content out of prompts
Anything fetched from the audited site is treated as untrusted input and left out of the prompt. This avoids prompt injection through site content without relying on filtering.
-
Report what could not be checked
Recording which checks did not run, and showing that in the report, prevents missing data from being presented as a pass or as a fix.
Current status
The audit is live at codeiq.co.uk/audit. It is free to use and takes about a minute. Sites on a monitoring plan are re-checked weekly, and an email is sent when something has changed. No email is sent when nothing has changed, so that owners don’t learn to ignore them.