Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to flag user-defined functions as "direct-only" or "innocuous" #592

Open
spazmodius opened this issue Apr 6, 2021 · 3 comments
Open

Comments

@spazmodius
Copy link

I'd like to be able to define custom functions or aggregates and mark them as SQLITE_DIRECTONLY or SQLITE_INNOCUOUS.

@JoshuaWise
Copy link
Member

What's your use case for SQLITE_INNOCUOUS?

According to the SQLite3 docs:

Developers are advised to avoid using the SQLITE_INNOCUOUS flag for application-defined functions unless the function has been carefully audited and found to be free of potentially security-adverse side-effects and information-leaks.

@JoshuaWise
Copy link
Member

SQLITE_DIRECTONLY is now available in better-sqlite3 version 7.3.0 via the directOnly: true option. I'm hesitant on adding SQLITE_INNOCUOUS until I understand a good use-case.

@spazmodius
Copy link
Author

Here's a simplified example of what I'd like to do:

const Database = require('better-sqlite3')
const fnv = require('@sindresorhus/fnv1a')

const db = Database(':memory:')
db.pragma('trusted_schema=off')
db.function('fnv', { deterministic: true, /* innocuous: true */ }, fnv)

db.prepare(`
	create table Strings(
		id integer primary key not null,
		string text not null,
		hash int not null as (fnv(string)) stored
	)
`).run()

db.prepare(`insert into Strings(string) values(?)`).run('Hello, world')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants