cloudflare / cloudflare/developer-platform

🐛 BUG: D1 Database triggers bypass D1 data type validation

Open
#42 0 comments 1 reaction 0 assignees View on GitHub
product:d1
Dominant language
No language data
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.