MagicStack / MagicStack/asyncpg
Can't add schema name to query in fetch function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 468
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
- 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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem conn.fetch()-Aufruf und der im Issue gezeigten PostgreSQL-Abfrage. Prüfe anschließend, wie Schemanamen an Abfragen übergeben werden und wie die Parameterbindung Bezeichner behandelt. Als abgeschlossen gilt die Aufgabe, wenn festgestellt wurde, ob ein sicherer Ansatz für Schemanamen unterstützt wird, und wenn das gemeldete Lint-/Sicherheitsproblem dokumentiert oder behoben wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, python
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100