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

bug(node): filtering doesn't work, no errors thrown #1081

Closed
flaviut opened this issue Mar 8, 2024 · 1 comment · Fixed by #1092
Closed

bug(node): filtering doesn't work, no errors thrown #1081

flaviut opened this issue Mar 8, 2024 · 1 comment · Fixed by #1092
Assignees
Labels
bug Something isn't working typescript Typescript / javascript

Comments

@flaviut
Copy link

flaviut commented Mar 8, 2024

LanceDB version

0.4.12

What happened?

import * as lancedb from 'vectordb'
import { Field, Schema as ArrowSchema } from 'apache-arrow'
import * as types from 'apache-arrow/type'
import { WriteMode } from 'vectordb'

const db = await lancedb.connect({
  // work around https://github.com/lancedb/lancedb/issues/1078
  awsCredentials: undefined,
  awsRegion: undefined,
  uri: './scratch',
})

const table = await db.createTable({
  name: 'table',
  schema: new ArrowSchema([
    new Field(
      'vector',
      new types.FixedSizeList(4, new Field('item', new types.Float32()))
    ),
    new Field('allowedGroups', new types.Utf8()),
  ]),
  writeOptions: {
    writeMode: WriteMode.Overwrite,
  }
})

await table.add([
  {
    vector: [1, 2, 3, 4],
    allowedGroups: '[[admin]]\t[[user]]'
  },
  {
    vector: [5, 6, 7, 8],
    allowedGroups: '[[user]]',
  },
])

console.log(await table.filter("allowedGroups = 'none'").execute())
console.log(await table.filter("allowedGroups LIKE '%[[admin]]%'").execute())
console.log(await table.filter("'123t3").execute())
[
  { vector: [ 1, 2, 3, 4 ], allowedGroups: '[[admin]]\t[[user]]' },
  { vector: [ 5, 6, 7, 8 ], allowedGroups: '[[user]]' }
]
[
  { vector: [ 1, 2, 3, 4 ], allowedGroups: '[[admin]]\t[[user]]' },
  { vector: [ 5, 6, 7, 8 ], allowedGroups: '[[user]]' }
]
[
  { vector: [ 1, 2, 3, 4 ], allowedGroups: '[[admin]]\t[[user]]' },
  { vector: [ 5, 6, 7, 8 ], allowedGroups: '[[user]]' }
]

I would expect this to have instead returned:

[ ]
[
  { vector: [ 1, 2, 3, 4 ], allowedGroups: '[[admin]]\t[[user]]' }
]
Error: Invalid filter expression
    at file:///...

this issue is particularly concerning, because this filtering may be used for access control. Applications that depend on that behavior may leak data to unauthorized users.

Are there known steps to reproduce?

No response

@flaviut flaviut added bug Something isn't working typescript Typescript / javascript labels Mar 8, 2024
@wjones127
Copy link
Contributor

wjones127 commented Mar 11, 2024

Okay this was a weird one. The bug turns out to be we are silently ignoring filter expressions that have wrong capitalization that have any syntax errors. In your case, the syntax error was about the case sensitivity of your column names.

In SQL, the column references are not case sensitive. To make them case sensitive, you need to wrap in a backtick ("`"):

console.log(await table.filter("`allowedGroups` LIKE '%[[admin]]%'").execute())

Or you can use lower-case column names.

I'll see if I can make this return a proper error, as it is indeed not good that it would let data through.

@wjones127 wjones127 self-assigned this Mar 11, 2024
wjones127 added a commit that referenced this issue Mar 11, 2024
In Rust and Node, we have been swallowing filter validation errors. If
there was an error in parsing the filter, then the filter was silently
ignored, returning unfiltered results.

Fixes #1081
raghavdixit99 pushed a commit to raghavdixit99/lancedb that referenced this issue Apr 5, 2024
In Rust and Node, we have been swallowing filter validation errors. If
there was an error in parsing the filter, then the filter was silently
ignored, returning unfiltered results.

Fixes lancedb#1081
raghavdixit99 pushed a commit to raghavdixit99/lancedb that referenced this issue Apr 5, 2024
In Rust and Node, we have been swallowing filter validation errors. If
there was an error in parsing the filter, then the filter was silently
ignored, returning unfiltered results.

Fixes lancedb#1081
westonpace pushed a commit that referenced this issue Apr 5, 2024
In Rust and Node, we have been swallowing filter validation errors. If
there was an error in parsing the filter, then the filter was silently
ignored, returning unfiltered results.

Fixes #1081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript Typescript / javascript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants