cloudflare / cloudflare/developer-platform

🐛 BUG: D1 Database triggers bypass D1 data type validation

Aperta
#42 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
product:d1
Lingua principale
Nessun dato sulla lingua
Stelle
1
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Which Cloudflare product(s) does this pertain to?

D1

### What version(s) of the tool(s) are you using?

3.53.1 [Wrangler]

### What version of Node are you using?

_No response_

### What operating system and version are you using?

Mac Ventura 13.5.2

### Describe the Bug

### Observed behavior
Triggers can bypass column data type validation when updating a row

### Expected behavior
Triggers should be restricted by a column's data type when performing updates

### Steps to reproduce
- Setup:
```sql
CREATE TABLE IF NOT EXISTS test (
id TEXT PRIMARY KEY NOT NULL,
val INTEGER NOT NULL
);

CREATE TRIGGER update_on_change AFTER
UPDATE OF val ON test FOR EACH ROW
BEGIN
UPDATE test
SET
val = 'not_an_integer'
WHERE
id = NEW.id;

END;

INSERT INTO test (id, val) VALUES ('test', 1);
```
- Trigger the trigger:
```sql
UPDATE test SET val=2 WHERE id='test'
```
- the `val` column of the `test` row (`val` is defined as an Integer) now contains Text

### Please provide a link to a minimal reproduction

_No response_

### Please provide any relevant error logs

_No response_

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the SQL reproduction in this issue using D1 and Wrangler 3.53.1, and verify whether the trigger stores text in the INTEGER column. Trace D1's trigger update path and its data type validation, then confirm that the same update rejects 'not_an_integer' and preserves the column type.

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

Valutazione

Stack tecnologico
sql
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.