A browser quiz or exam app still ships the answer key
Quiz widgets, certification practice tests, onboarding exams, and classroom tools often grade in the browser. It feels instant, it works offline, and it saves a round trip per question. It also means the answer key trave
Quiz widgets, certification practice tests, onboarding exams, and classroom tools often grade in the browser. It feels instant, it works offline, and it saves a round trip per question. It also means the answer key travels to every student who opens the page.
This article covers what a client-side grader actually exposes, which parts belong on a server, and where code protection helps a little and where it does not help at all.
The grader is a public download
A typical client-side grader looks something like this:
export function grade(attempt, bank) {
let score = 0;
for (const q of attempt.answers) {
const item = bank[q.id];
if (normalize(q.value) === item.correct) score += item.weight;
}
return { score, passed: score >= bank.passMark };
}
After a production build, bank is either inlined in a chunk or fetched from /questions.json. Either way it contains every question, every correct field, the weights, the pass mark, and frequently the question pool you meant to rotate over the next three cohorts.
Anyone with DevTools can:
- Open the Network tab, pretty-print the JSON, and read every answer before starting.
- Call
gradefrom the console with a perfect attempt and screenshot the "passed" screen. - Patch
passMarkor the result object before it is POSTed back to your API. - Scrape the whole pool once and publish it, which ruins it for everybody who comes after.
Shuffling questions, hashing the answers with a fixed salt, or base64-encoding the JSON does not change this. A hash of "B" is a lookup table away from "B" when there are four options.
Timers and tab-switch detection are UI, not integrity
Many exam apps add a countdown, a visibilitychange listener, or a "do not leave this tab" warning. Those are fine as nudges. They are not enforcement: the timer value and the "left the tab" flag are both computed in the same page the student controls. Treat them as signals to log, not as the reason a score is trustworthy.
What to keep on the server
- The answer key for anything that issues a certificate, a grade, a hiring decision, or a credential.
- The authoritative score and pass/fail result.
- The rotating question pool: send one question (or one page) at a time, without its correct answer.
- Attempt limits and timing, measured from server timestamps.
Practice mode is different. If the quiz is a self-check with no stakes, shipping answers so learners get instant feedback is a reasonable trade, and nobody should spend effort hiding it.
What protection can still do
There is a middle ground: low-stakes quizzes where you do not want the pool trivially scraped, or a scoring function with partial credit, fuzzy matching, and rubric weights that took real effort to write. For that slice:
- Keep the answer data out of the bundle anyway when you can; fetch it per question after the student answers.
- Extract the scoring or normalization function (partial credit, unit handling, synonym matching) into its own module.
- Apply real protection to that module — identifier renaming and string encryption as a floor, VM-based protection if copying the rubric logic is what you care about.
- Remove production source maps that would hand the original back.
A JS VM obfuscator compiles the function into custom bytecode run by a small interpreter, so pretty-printing the chunk no longer shows a readable rubric. It does not hide data the function needs at runtime, and it does not stop someone from replaying requests. It raises the cost of copying logic; it does not turn a client-side grade into a trustworthy one.
VEILVM is a browser-based JSVMP workspace (disclosure: I work on it) you can point at one extracted function before you wire protection into CI. Use it on a rubric or normalization function, not on the answer key itself, which should not be in the browser for a real exam.
Checklist
- [ ] High-stakes answer keys and pass marks are never in a chunk or a public JSON file.
- [ ] The server computes the score that is stored, emailed, or printed on a certificate.
- [ ] Questions are delivered one at a time without their correct answers in the payload.
- [ ] Timers and tab-switch flags are logged as signals, not trusted as enforcement.
- [ ] Only proprietary scoring logic is a candidate for protection; production source maps are off.
- [ ] End-to-end tests grade a fixture attempt against the protected production build.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.