Skip to content

fix: validate BigInt input before it reaches Postgres - #665

Open
Indian-boult wants to merge 1 commit into
supabase:masterfrom
Indian-boult:fix/bigint-input-validation
Open

Indian-boult wants to merge 1 commit into
supabase:masterfrom
Indian-boult:fix/bigint-input-validation

Conversation

@Indian-boult

Copy link
Copy Markdown

Fixes #641

validate_arg_from_type let any string or number through for BigInt, so a bad filter, insert, update or function argument value was only caught by the int8 cast in the generated SQL. On Postgres 17 from the Debian image that comes back as the raw Postgres message, for example invalid input syntax for type bigint: "not-an-int". The issue reports a backend abort on an Alpine musl build.

BigInt now accepts JSON integers and strings that parse as an i64 after surrounding spaces are trimmed. Anything else returns Invalid input for BigInt type, the same error the other scalars return. Strings are limited to decimal digits with an optional sign because Postgres 16 and later also accept 0x10 and 1_000 while 14 and 15 reject them. With the check in Rust every supported version gives the same answer.

Strings like 0x10 or 1_000 worked on Postgres 16 and later and are now rejected. Strings with surrounding spaces such as " 1 " keep working, as Postgres reads them on every version. JSON numbers with a fraction or outside the int8 range already failed and now fail with the GraphQL error.

byPk arguments do not go through validate_arg_from_type for any type, so a bad BigInt there still reaches the cast. I left that for a separate change.

The new cases are in test/sql/bigint_is_string.sql. The full installcheck passes on Postgres 17.

validate_arg_from_type accepted any string or number for BigInt, so a
value like "not-an-int", "1.5" or a number outside the int8 range was
only rejected by the int8 cast in the generated SQL. Users got the raw
Postgres message, and the issue reports a backend abort on an Alpine
musl build.

BigInt now accepts JSON integers and strings that parse as an i64 after
surrounding spaces are trimmed. Anything else returns "Invalid input for
BigInt type", the same error the other scalars return. Strings must be
decimal digits with an optional sign because Postgres 16 and later also
accept 0x10 and 1_000 while 14 and 15 reject them, and the result should
not depend on the server version.

Fixes supabase#641

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.

graphql.resolve crashes backend process on invalid BigInt filter value (signal 6, Postgres enters recovery)

1 participant