mirror of
https://github.com/nestriness/nestri.git
synced 2026-09-26 20:42:25 +03:00
fix(api): a misshapen id is bad input, not a server fault
Ids are stored in a fixed-width column, so an overlong one is refused by Postgres rather than simply matching nothing. That refusal is not a foreign-key violation, so it fell through to the global error boundary and reached the caller as a 500 — telling a host to retry something that can never succeed. Measured: a 44-character user id returned 500, where an absent but well-formed one correctly returned 404. `Identifier.schema` is the natural place for the check and had no callers yet, so it now asserts the exact width an id has as well as its prefix — including the separator, without which `usrsomething` reads as a user id. The enrolment schema uses it for both foreign keys, so the refusal happens where the input arrives and names the field. Also index `steam_enrolment.user_id`. The primary key begins with the machine, which answers what one host holds and nothing else, so neither of the two things that read by user alone can use it: the cascade behind deleting a user, and asking which hosts hold a token for one person. The table's migration has not been released, so this is folded into it rather than following it with a correction.
This commit is contained in:
@@ -25,6 +25,12 @@
|
||||
-- itself only goes away when the machine or the user does, which the foreign
|
||||
-- keys already do.
|
||||
--
|
||||
-- The key begins with the machine, so it answers "what does this host hold" and
|
||||
-- nothing else. `user_id` gets its own index because the two things that read
|
||||
-- by user cannot use the key: deleting a user cascades into this table by that
|
||||
-- column alone, and asking which hosts hold a token for one person is the
|
||||
-- obvious next reader.
|
||||
--
|
||||
-- `last_ok_at` has no writer yet. A successful logon happens inside the
|
||||
-- workload, which holds no control-plane credential, so the report has to come
|
||||
-- back out through the host and nothing carries it today. The column exists
|
||||
@@ -44,4 +50,5 @@ CREATE TABLE "steam_enrolment" (
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "steam_enrolment" ADD CONSTRAINT "steam_enrolment_machine_id_machine_id_fk" FOREIGN KEY ("machine_id") REFERENCES "public"."machine"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "steam_enrolment" ADD CONSTRAINT "steam_enrolment_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
||||
ALTER TABLE "steam_enrolment" ADD CONSTRAINT "steam_enrolment_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "steam_enrolment_user_idx" ON "steam_enrolment" USING btree ("user_id");
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "5c6f5a6c-74ff-4b9d-95ac-bef2c2603273",
|
||||
"id": "d519bc2f-25f8-46e1-b7df-67bf6b5a927a",
|
||||
"prevId": "6fdda454-c7ee-42c1-931b-fa595385aac0",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@@ -1860,7 +1860,23 @@
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"indexes": {
|
||||
"steam_enrolment_user_idx": {
|
||||
"name": "steam_enrolment_user_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "user_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"steam_enrolment_machine_id_machine_id_fk": {
|
||||
"name": "steam_enrolment_machine_id_machine_id_fk",
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
{
|
||||
"idx": 12,
|
||||
"version": "7",
|
||||
"when": 1788690115352,
|
||||
"when": 1788691753961,
|
||||
"tag": "0012_steam_enrolment_without_a_token",
|
||||
"breakpoints": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user