MagicStack / MagicStack/asyncpg

Can't add schema name to query in fetch function

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

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
8.1k
Fork
468
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

  • asyncpg version: 0.18.3
  • PostgreSQL version: 11.4 +
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : No
  • Python version: Python 3.7.3
  • Platform: MacOS, Sanic
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: No
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : No

I had try to up to 0.20.1 but I have an other error in your code, so I only test on version 0.18.3

I got a problem when I try to add schema name to the query. My code:

dbpool = app.config["pool"]
async with dbpool.acquire() as conn:
    sql = """
        SELECT _id, name, address
        FROM "{schema}".account
        WHERE _id IN (
            SELECT account_id
            FROM "{schema}"."account-message"
            WHERE message_id IN (
                SELECT _id
                FROM "{schema}".message
                WHERE sender = $1
            )
        );
    """.format(
        schema=config.SCHEMA
    )
    resp = await conn.fetch(sql, address)

and it work very well, except for the lint:security give me a security issue:

Issue: [B608:hardcoded_sql_expressions] Possible SQL injection vector through string-based query construction.

And when I try to pass my schema name to conn.fetch() function but it didn't work. Can you help me?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

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.

Direzione di ricerca

Inizia con la chiamata conn.fetch() e la query PostgreSQL mostrata nell’issue, quindi verifica come vengono passati i nomi degli schemi alle query e come il binding dei parametri tratta gli identificatori. Il lavoro è completato quando è stato determinato se è supportato un approccio sicuro ai nomi degli schemi e la segnalazione relativa a lint/sicurezza è stata documentata o risolta.

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

Valutazione

Stack tecnologico
postgresql, python
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.