Skip to content

core: guard domainId against non-string override in request args - #1232

Closed
hydrodevbot[bot] wants to merge 1 commit into
masterfrom
fix/domainid-type-guard
Closed

hydrodevbot[bot] wants to merge 1 commit into
masterfrom
fix/domainid-type-guard

Conversation

@hydrodevbot

@hydrodevbot hydrodevbot Bot commented Nov 19, 2026

Copy link
Copy Markdown

Problem

Creating a problem (e.g. objective type) via a JSON POST that carries a non-string domainId field fails with a 500 and the error toast:

domainId.toLowerCase is not a function

Cause

packages/hydrooj/src/service/layers/base.ts builds handler args as:

const args = { domainId, ...ctx.params, ...ctx.query, ...ctx.request.body, __start: Date.now() };

so a JSON body such as {"domainId": 123} (or true, arrays, objects — any non-string) overrides the route-inferred domainId. The user layer then passes it to UserModel.getById → DomainModel.get(), which calls domainId.toLowerCase() on a non-string and crashes.

Fix

After the merge, fall back to the route-inferred domainId when the merged value is not a string:

if (typeof args.domainId !== 'string') args.domainId = domainId;

String overrides (e.g. the domainId query param used by record-conn websocket URLs) still work as before.

Verification

  • POST /d/{domain}/problem/create with JSON body domainId: 123 / true / ["a"] → previously 500 domainId.toLowerCase is not a function, now creates the problem in the route domain (HTTP 200)
  • JSON body domainId: "system" (string) → still honored, problem created in system
  • Regular form-encoded create (what the browser UI sends) → unchanged
  • Full browser flow (create problem → open Judge Config → select Objective → save) → works

@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ecfa5879-2e19-4240-875c-ba1932cae72e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant