Feature API accepts whitespace and control characters as user_id, and has no length limit

オープン 初心者向け
#40 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
66/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
fastapi, python, redis
領域
api, backend

調査の方向性

GET /features/{user_id} ハンドラーと、min_length=1 を宣言する POST /features/batch リクエストモデルから始め、次に id を user_key() まで追ってください。issue 内の curl コマンドで whitespace のケースを再現してください。完了とは、whitespace のみの id が両方のルートで同じように扱われ(strip and reject または strip and accept、maintainer の判断による)、255 文字を超える id が上限処理され、#39 のテストがそれに合わせて更新されていることです。

索引モデルが issue の本文から書いたものです。

説明

Follow-up from #39 (the new tests pin current behaviour; this is the part that looks like a bug).

What happens

GET /features/{user_id} declares the parameter as str and passes it straight to user_key() → HGETALL. Nothing trims or validates it, so:

request result
GET /features/%20 404, no features for user ' ' — a space is treated as a real key
GET /features/%09 404, tab is a real key
GET /features/%0A 404, newline is a real key
GET /features/<1024 chars> 404 — no length limit anywhere
POST /features/batch with "" 422 (min_length=1)
POST /features/batch with " " 200, then a normal miss

So the two endpoints disagree about what an empty id is, and on the path route a caller can create distinct Redis keys such as eddy:user: and eddy:user:\t simply by requesting them with a write-side call later (or by any producer that copies the id through).

Why it matters

  • Two users, or one user and one script, can be split across keys that differ only by invisible characters — silent cache misses and duplicated features.
  • No upper bound on the id length means one request can write an arbitrarily long key.

Reproduction

# after the service is up
curl -s -o /dev/null -w '%{http_code}\n' 'http://localhost:8000/features/%20'
curl -s -o /dev/null -w '%{http_code}\n' -X POST 'http://localhost:8000/features/batch' \
  -H 'content-type: application/json' -d '{"user_ids": ["   "]}'

Expected instead: strip or reject ids that are empty after .strip(), and cap the length (e.g. 255) consistently on both routes.

The tests added in #39 assert today's behaviour deliberately, so they will need updating once this is fixed.

主要言語
Python
スター
2
フォーク
4
平均マージ
6時間 43分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

midhunsomu/Feature_Store のほかの issue

midhunsomu/Feature_Store の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。