Skip to content

feat(quiz): add quiz integrity system with Standard and Secure modes - #242

Open
codebysana wants to merge 10 commits into
devweekends:mainfrom
codebysana:feature/quiz-anti-cheating
Open

codebysana wants to merge 10 commits into
devweekends:mainfrom
codebysana:feature/quiz-anti-cheating

Conversation

@codebysana

Copy link
Copy Markdown
Collaborator

Summary

In an online written quiz, a learner can paste answers from another window, ask an AI tool, share their screen, or get help from someone nearby. A browser alone can't see what else is running on the computer, so it can't stop most of this.

This PR adds an integrity layer to quizzes. Each course picks one of two modes:

  • Standard mode is for quick quizzes. The quiz is protected: full screen, no copying or pasting, notice when the learner leaves the window, and optional camera photos.
  • Secure mode is for final exams. The exam opens in the desktop app after a system check, and runs in lockdown with a live heartbeat and a face check.

The goal is to discourage, detect and document. Nothing here fails a learner automatically. Every attempt gets a risk score and a list of timestamped notes, and a mentor makes the final call.

What learners will notice

  • A short rules screen with a consent checkbox before the quiz starts.
  • A status bar while the quiz runs: connection state, a countdown timer, camera state and a Leave button.
  • Friendly messages when something isn't allowed, like "Copying is not allowed during the quiz."
  • Monitoring only happens while the quiz is open.

What's in this PR

Standard mode

  • Full screen, with a prompt to return if the learner leaves it.
  • No text selection, copy, cut, paste, drag or right-click during the quiz. The clipboard is overwritten so old text or a stale screenshot can't be pasted back as an answer.
  • Notice when the learner switches tabs or windows, and how long they were away.
  • Screenshot keys (PrintScreen, snipping shortcuts) are noticed and logged. A browser can't block them.
  • A heartbeat every few seconds, and every event is saved with a real timestamp.
  • Optional camera photos (small 320 × 240 stills, about once a minute, no video or sound), only if the course turns them on and the learner agrees.

Secure mode (desktop app)

  • The website's Start exam in the app button asks the server for a one-time link (valid for two minutes, usable once) and opens the app.
  • System check before the exam starts:
    • blocks remote-access tools, screen recorders and AI desktop apps
    • blocks extra monitors and virtual machines
    • checks that the camera works
    • only warns about meeting apps such as Zoom or Teams
    • only the names of matched programs are sent, never the full app list, files or screen
  • Lockdown during the exam: full screen, always on top, content protection, blocked shortcuts and a guarded clipboard.
  • Heartbeat during the whole exam. The server only accepts answers while the desktop session is alive.
  • A clear consent screen, and an easy way to leave at any time.
  • Windows and Mac handle some low-level shortcuts differently, so where a hard block isn't possible we detect, log and warn instead.

Camera and face check

  • The camera starts automatically in a Secure exam that requires it. There is no "continue without camera" option there.
  • Face detection runs on the learner's computer with MediaPipe. Frames are never saved or sent. Only a note like "no face" or "more than one face" is sent to the mentor.
  • The exam bar shows the camera and face-check state, and a Retry camera button when something fails.
  • The Content Security Policy now allows WebAssembly ('wasm-unsafe-eval'). Without it the face model could not load, and the face check stayed "unavailable".

Typing patterns

  • Typed answers are compared with pasted-in-one-go answers, so a mentor can see when text arrived all at once.

Quiz timer

  • The quiz length comes from the chapter's estimatedMinutes, so instructors don't need a new setting. No minutes means no timer.
  • A countdown sits in the exam bar, with reminders at 5 minutes and 1 minute.
  • When time runs out, the answers are saved and the quiz closes.
  • The finish time is stored, so leaving and coming back doesn't restart the clock.

Server

  • Integrity attempts, timestamped events, a risk score and a review flow.
  • Secure launch and secure session services (one-time link, exchange, start, heartbeat, finish).
  • Camera snapshots with signed links and a retention job that deletes old photos.
  • Answer similarity checks (word overlap, plus an optional open-source embedding model on our own server).
  • Live updates for mentors through the realtime hub.

Mentor tools

  • A course Quiz integrity page with live sittings, flagged attempts and answer similarity.
  • Review screens for individual attempts, and a learner comparison view.
  • The mentee tabs now wrap onto a new line instead of scrolling sideways, so every section is visible.

Fixes along the way

  • A learner no longer sees internal details when a quiz has no questions. They get a short message, and the technical reason goes to the server log.
  • Changing a course to Secure mode no longer breaks a learner who already had an open attempt ("This exam no longer uses the desktop app"). A resumed attempt now follows the course's current mode.
  • Removed a harmless but noisy full-screen error in the console.
  • The exam bar has a cleaner layout, using the existing theme colors.

Database and configuration

  • server/prisma/schema.prisma has changes. A migration is needed (see reviewer notes).
  • New or changed settings live in server/src/config/env.ts.
  • In development, camera photos go to a temp folder. In production they need photo storage and INTEGRITY_MEDIA_SECRET, otherwise camera photos are turned off.
  • The face model is not committed. Run pnpm face:setup in desktop/ once to download it. Without it the quiz still works and only the face check is off.

How to try it

  1. Start the server and the desktop app.
  2. In Course settings → Quiz integrity, choose Secure (desktop app) and turn on camera photos.
  3. Open a quiz chapter in the desktop app, accept the rules and run the system check.
  4. Close any blocked app first (screen recorders, remote-access tools, AI desktop apps).

@AQIB-NAWAB

Copy link
Copy Markdown
Collaborator

Hi @codebysana, thanks for this big PR. I found one important problem in Secure mode. Here it is in simple words, with an example.

The problem

The server believes the desktop app without any proof. A learner can skip the app and send the same messages from a normal browser.

Example

Ali must take a quiz in Secure mode. The rule: use the desktop app, no blocked apps open, camera on.

What should happen

  1. Ali opens the desktop app.
  2. The app checks Ali's computer. It sends the server a report: "no blocked apps, no virtual machine, camera OK".
  3. The server accepts and the quiz starts.

What can happen now

  1. Ali opens the quiz in a normal browser. A chat or remote-help program is open next to it.
  2. Ali's browser sends the server the same "all OK" report by hand.
  3. The server cannot tell who sent it. It sees an OK report and starts the quiz.

So the check works like a guard who asks "do you have a ticket?" and accepts "yes" without looking.

What the words mean

  • Blocked apps: programs that must not run during a Secure quiz, for example remote-control tools like TeamViewer or AnyDesk. The list is SECURE_BLOCKED_APPS in server/src/shared/api/integrity.ts. The desktop app reads the names of running programs (desktop/src/secure/process-scan.ts) and only sends the names that matched the list.
  • Camera on: the learner's camera is working and allowed, so a mentor can trust the sitting. In the report it is the camera field. When the course requires a camera, the server accepts only camera: "OK" (evaluateSecurePrecheck, server/src/shared/api/integrity.ts, "Turn on your camera").

Where the gap is

  • POST /attempts/:attemptId/secure/start (server/src/routes/v1/integrity.ts) and startSecureSession (server/src/services/integrity/secure-session.ts) take apps, virtualMachine and camera from the request body and trust them.
  • The login is the same session the browser uses. The one-time launch link (secure-launch.ts) is also handed to the browser.
  • The heartbeat route has no proof that the app sent it either.

Suggested fix

  1. The desktop app signs each report (precheck and heartbeat) with a key that only the real app has. The server checks the signature and refuses unsigned or old reports.
  2. Tie the signed report to this attempt and a short time window, so an old report cannot be reused.
  3. Be honest in the UI and docs: no desktop check is 100% safe, because a determined person can still extract a key. The mentor review queue stays the final decision, which you already have. Signing still stops the easy bypass.

Also please check

  • A time limit that exists only in the browser (quiz-timer.ts keeps the deadline in local storage). The server never checks the time.
  • The branch conflicts with main (about 29 files) and needs a Prisma migration for the new columns and tables. I prepared both locally and can share them if that helps.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants