username sanitization is case sensitive; column is citext

Aperta
#284 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@hydrandt ci sta già lavorando.

Dal 10/12/2021.

  • #285 di @hydrandt — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
postgresql, sql
Ambito
databases

Direzione di ricerca

La modifica segnalata si trova in @app/db/migrations/committed/000001.sql, all’interno di app_private.register_user; inizia leggendo la query di unicità del nome utente e la migration circostante. Riproduci il caso di registrazione OAuth con un nome utente esistente scritto con maiuscole e minuscole diverse, quindi verifica che la sanitizzazione selezioni un nome utente non in conflitto sotto il vincolo citext.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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;
Lingua principale
TypeScript
Stelle
1.8k
Fork
226
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di graphile/starter

Tutte le issue di graphile/starter

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.