username sanitization is case sensitive; column is citext

オープン
#284 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@hydrandt がすでに取り組んでいます。

2021年12月10日 から。

  • #285 @hydrandt による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
postgresql, sql
領域
databases

調査の方向性

報告された変更は @app/db/migrations/committed/000001.sql の app_private.register_user 内にあります。まず、ユーザー名の一意性を確認するクエリと周辺の migration を読みます。大文字と小文字が異なる既存のユーザー名を使った OAuth 登録のケースを再現し、その後、citext 制約の下でサニタイズ処理が競合しないユーザー名を選択することを確認します。

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

説明

Summary

Creating a new user using oauth fails in case there is already the same username with different case (ie. existing: peter, newly registering: Peter)

Steps to reproduce
  1. create an account with same username as your github username, but in different case (in my case, HYDRANDT would do)
  2. sign out
  3. attempt to sign in using github
  4. enjoy blue screen "An unknown error occurred"
Expected results

Username sanitization should be case insensitive and username should be sanitized to hydrandt1

Actual results

HYDRANDT and hydrandt are deemed non identical, number is not appended, and inserting a new user fails, as username column on app_public.users is type citext.

Additional context
-- Sanitise the username, and make it unique if necessary.
...
  select (
    case
    when i = 0 then v_username
    else v_username || i::text
    end
  ) into v_username from generate_series(0, 1000) i
  where not exists(
    select 1
    from app_public.users
    where users.username = (
      case
      when i = 0 then v_username
      else v_username || i::text
      end
    )
  )
  limit 1;
Possible Solution

Convert username using lower() while checking for uniqueness:

  select (
    case
    when i = 0 then v_username
    else v_username || i::text
    end
  ) into v_username from generate_series(0, 1000) i
  where not exists(
    select 1
    from app_public.users
    -- comparing using lowercase to make sure the username is unique (username column is citext -> constraint is not case sensitive)
    where lower(users.username) = (
      case
      when i = 0 then lower(v_username)
      else lower(v_username) || i::text
      end
    )
  )
  limit 1;
主要言語
TypeScript
スター
1.8k
フォーク
226
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

graphile/starter のほかの issue

graphile/starter の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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