cossacklabs / acra

Database security suite. Database proxy with field-level encryption, search through encrypted data, SQL injections prevention, intrusion detection, honeypots. Supports client-side and proxy-side ("transparent") encryption. SQL, NoSQL.
https://www.cossacklabs.com/acra/
Apache License 2.0
1.34k stars 128 forks source link

Support for case (in)sensitive identifiers #532

Closed iamnotacake closed 2 years ago

iamnotacake commented 2 years ago

How table/column matching works now?

PostgreSQL

MySQL


This PR includes:

Checklist

iamnotacake commented 2 years ago

The problem with the failing test TestGeneralQueryParser_Parse was in encryptInsertQuery():

func (encryptor *QueryDataEncryptor) encryptInsertQuery(...) (bool, error) {
    tableName := insert.Table.Name
    schema := encryptor.schemaStore.GetTableSchema(tableName.String()) // schema was nil here

the .String() method of TableIdent included quotes and then, store.schemas[tableName] failed to find "TableWithoutColumnSchema" since it contained TableWithoutColumnSchema.

One option is to use .RawValue() instead, since it ignores quotes. This fixes test 27, but then 28 is failing, seems like similar replacement is needed somewhere else as well.

Lagovas commented 2 years ago

The problem with the failing test TestGeneralQueryParser_Parse was in encryptInsertQuery():

func (encryptor *QueryDataEncryptor) encryptInsertQuery(...) (bool, error) {
  tableName := insert.Table.Name
  schema := encryptor.schemaStore.GetTableSchema(tableName.String()) // schema was nil here

the .String() method of TableIdent included quotes and then, store.schemas[tableName] failed to find "TableWithoutColumnSchema" since it contained TableWithoutColumnSchema.

One option is to use .RawValue() instead, since it ignores quotes. This fixes test 27, but then 28 is failing, seems like similar replacement is needed somewhere else as well.

as I see, we have incorrect rule for column_id with SINGLE_QUOTE_STRING token. Because nor mysql, nor postgresql don't accept single-quoted identifiers. So, unit-tests incorrect too.

But if fix it, I don't understand why TableIdent has node.val with double-quotes and return it with RawValue() too... can you debug it by yourself?