apache / apache/polaris

Malformed pageToken on list endpoints returns HTTP 500 instead of 400

Open
#5,465 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2.1k
Forks
522
Avg merge
1d 22h
Merged PRs (30d)
137

Description

### Describe the bug

List endpoints (listNamespaces, listTables, listViews) accept an opaque `pageToken` query parameter.
When the value is well-formed Base64 but not a valid Polaris page token (garbage, a truncated token, or a token produced by an incompatible Polaris version), the server answers 500 Internal Server Error and logs an ERROR-level stack trace ("Unhandled exception returning INTERNAL_SERVER_ERROR").
Invalid client input should be a 400.

Root cause: `PageTokenUtil.decodePageRequest` (polaris-core, pagination package) performs Base64 decode + SMILE deserialization without error handling. Failures surface as Jackson 3 `tools.jackson.core.JacksonException` (unchecked) or `IllegalStateException` (unknown token type id).
Neither is handled: `IcebergJsonProcessingExceptionMapper` only maps Jackson 2 `JsonProcessingException`, and `IcebergExceptionMapper` falls to `default -> 500`.
Only the "not Base64 at all" case already yields IllegalArgumentException -> 400.

### To Reproduce

1. Start Polaris (e.g. the RustFS quickstart) and obtain a bearer token.
2. curl -i -H "Authorization: Bearer $TOKEN" \
"http://localhost:8181/api/catalog/v1/quickstart_catalog/namespaces?pageToken=AAAA"
("AAAA" is valid url-safe Base64 but not a serialized page token.)
3. Also reproducible with pageToken=aGVsbG8gd29ybGQ= (plain text) or any truncated real token.

### Actual Behavior

HTTP/1.1 500 with {"error":{"type":"StreamReadException", ...}} (type varies: StreamReadException, DatabindException, MismatchedInputException) and an ERROR log entry per request.

### Expected Behavior

HTTP/1.1 400 Bad Request with message "Invalid page token", no ERROR log

### Additional context

Affected call sites: IcebergCatalogHandler listNamespaces / listTables / listViews.
Policy and generic-table listing will be affected too once #5311 (page-token support there) lands.
Fix and tests are ready; PR to follow.

### System information

Polaris main @ 715cf86ff6 (1.8.0-SNAPSHOT), Iceberg 1.11.0, Jackson 3.2.2.
Backend-independent (reproduced with in-memory and Relational JDBC).

Contributor guide

Open the contributing guide

Research direction

Start with PageTokenUtil.decodePageRequest in the polaris-core pagination package, then inspect IcebergJsonProcessingExceptionMapper and IcebergExceptionMapper. Reproduce with the listed curl requests and trace the IcebergCatalogHandler listNamespaces, listTables, and listViews call sites. Done means malformed but Base64-valid tokens return HTTP 400 with “Invalid page token” and do not emit an ERROR stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.