[Bug]: JSON body null returns 500 on /api/clipboard/copy and /api/clipboard/paste

Open Beginner friendly
#522 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript, vite
Domain
api, backend

Research direction

Start at the parseJsonBody helper, which currently returns whatever JSON.parse yields, then check the /api/clipboard/copy and /api/clipboard/paste handlers that read body.sessionId. The /api/rtc/answer, /api/rtc/ice and /api/config handlers show the other error paths. Done when a null body returns 400 with "Request body must be a JSON object" on every caller, with a test covering it.

Written by the indexing model from the issue text.

Description

bug enhancement
Bug Description

parseJsonBody resolves whatever JSON.parse returns, so a request body of null resolves to null. The clipboard handlers then read body.sessionId, which throws a TypeError and is returned as a 500. Other invalid bodies ([], {}, malformed JSON) correctly return 400.

/api/clipboard/paste behaves the same. /api/rtc/answer and /api/rtc/ice return 400 because their catch handles it, but both log the same TypeError at error level. /api/config also returns 400, but the response carries a raw TypeError: Cannot destructure property 'framerate'... message.

Proposed fix: reject non-object JSON in parseJsonBody so every caller gets a 400. I would like to send the PR with tests.

Steps to Reproduce
  1. Start the dev server: node node_modules/vite/bin/vite.js dev --host 127.0.0.1 --port 3000
  2. Send a request with the JSON body null:
curl.exe -i -X POST -H "Content-Type: application/json" -d null http://127.0.0.1:3000/api/clipboard/copy
  1. The response is:
HTTP/1.1 500 Internal Server Error
{"ok":false,"error":"Failed to copy clipboard"}
  1. Repeat with /api/clipboard/paste and get the same result.
Expected Behavior

HTTP 400 with a clear "Request body must be a JSON object" error, and no TypeError in the server log.

Desktop Operating System

Windows 11

Client OS and browser

Microsoft Windows 11 Home Single Language (build 10.0.26300, 64-bit), curl.exe (curl 8.22.0), no browser, same machine as the server

Rein Version

1.0.0

Console Logs / Error Messages (Optional)
error: Error in /api/clipboard/copy: TypeError: Cannot read properties of null (reading 'sessionId') {"service":"rein-server","timestamp":"2026-11-24 21:31:06"}
error: Error in /api/clipboard/paste: TypeError: Cannot read properties of null (reading 'sessionId') {"service":"rein-server","timestamp":"2026-11-24 21:31:07"}
Screenshots / Recordings (Optional)

No response

Checklist
  • I have searched for existing issues to avoid duplicates
Dominant language
TypeScript
Stars
55
Forks
120
Avg merge
4d 5h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/Rein

All issues in AOSSIE-Org/Rein

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.