Skip to content

Fix tenant token generation for non-ASCII search rules - #2230

Merged
Strift merged 2 commits into
meilisearch:mainfrom
soroush5:fix/tenant-token-unicode-search-rules
Sep 9, 2026
Merged

Strift merged 2 commits into
meilisearch:mainfrom
soroush5:fix/tenant-token-unicode-search-rules

Conversation

@soroush5

@soroush5 soroush5 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

generateTenantToken threw InvalidCharacterError for any non-ASCII search rule (e.g. a filter value in Persian), because encodeToBase64 fed raw JSON to btoa, which only handles latin1. It now encodes to UTF-8 bytes first and emits base64url, matching what the JWT spec requires (and what the signature part already did). Adds tests/tenant-token-unicode.test.ts (no-crash, payload round-trip, HMAC signature verification).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed token generation for content containing non-ASCII characters.
    • Ensured generated tokens use URL-safe Base64 encoding without unnecessary padding.
    • Preserved Unicode search rules when encoded in and recovered from tokens.
  • Tests

    • Added coverage for Unicode token payloads, including signature validation.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: d8bdd541-a7b2-43b4-ae7e-1cc55b84841e

📥 Commits

Reviewing files that changed from the base of the PR and between bc60d68 and 7cb1a51.

📒 Files selected for processing (1)
  • tests/token.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The token encoder now converts input to UTF-8 before producing unpadded base64url output. Tests cover Unicode search rules, payload round trips, and JWT-compatible HMAC signatures.

Changes

Tenant token Unicode support

Layer / File(s) Summary
UTF-8 token encoding and validation
src/token.ts, tests/token.test.ts
encodeToBase64 encodes UTF-8 bytes and emits unpadded base64url data. Tests verify token creation, Unicode payload preservation, and signature generation.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 7cb1a

Tenant tokens can now safely include non-ASCII search rules while retaining JWT-compatible payload encoding and signatures. The change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing tenant token generation for non-ASCII search rules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

I’m a rabbit with tokens to byte,
Persian words hop through the night.
UTF-8 carries each sign,
HMAC keeps the line,
And base64url makes it right.

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (a4e0707) to head (7cb1a51).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2230      +/-   ##
==========================================
+ Coverage   98.11%   98.12%   +0.01%     
==========================================
  Files          14       14              
  Lines         688      693       +5     
  Branches      109      109              
==========================================
+ Hits          675      680       +5     
  Misses         12       12              
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Keep tests next to the source file they cover and drop the leftover TDD label.

@Strift Strift left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @soroush5 and thanks for your PR 🙌

@Strift
Strift enabled auto-merge September 9, 2026 04:39
@Strift
Strift added this pull request to the merge queue Sep 9, 2026
Merged via the queue into meilisearch:main with commit 10907d5 Sep 9, 2026
8 checks passed
@Strift Strift added the bug Something isn't working label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants