Skip to content

extra ignored test which can output the sql query for a set of scala …#433

Draft
andrew-nowak wants to merge 1 commit into
mainfrom
an/query-parameter-inserter
Draft

extra ignored test which can output the sql query for a set of scala …#433
andrew-nowak wants to merge 1 commit into
mainfrom
an/query-parameter-inserter

Conversation

@andrew-nowak

Copy link
Copy Markdown
Member

…params

What does this change?

How to test

How can we measure success?

Have we considered potential risks?

Images

Accessibility


// Replace the parameter placeholders with the corresponding values
// WARNING
// This is a textbook example of how to get hit by a SQL injection attack - this should be used

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@bryophyta bryophyta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, super useful and very good to have the injection warning documentation too! 🤩

val matcher = "\\?(?![|?])"
param match {
case p: Int => statement.replaceFirst(matcher, s"$p ")
case p: String => statement.replaceFirst(matcher, s"'$p' ")

@bryophyta bryophyta Aug 22, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just spotted that this will fail if the param is the name of a column, because that doesn't want to be placed inside 's.

we are currently doing that in some queries (I think here?):

case Some(SearchTerm.Simple(query, field)) =>
val tsvectorColumn = field match {
case SearchField.Headline => "headline_tsv_simple"
case SearchField.BodyText => "body_text_tsv_simple"
}
.

not sure if it's worth trying to account for this edge case in the code, but thought i'd flag it as something to be aware of for future travellers :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants