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.33k stars 128 forks source link

[ISSUE] Acra is not parsing inserts ending in 'RETURNING 0' #583

Closed Machado117 closed 1 year ago

Machado117 commented 1 year ago

Describe the bug When I run an INSERT query ending in RETURNING 0 with encryption turned on for one of the the fields, acra does not encrypt the field. The following message can be found on acra logs: time="2022-09-23T09:39:36Z" level=error msg="Error occurred on query handler" client_id=testfdz code=900 error="invalid returning format provided" proxy=client session_id=8 If I run the query as a JDBC batch the entry is not inserted at all.

To Reproduce Steps to reproduce the behavior:

public class AcraCrash {

public static void main(String[] args) throws Exception {
    Class.forName("org.postgresql.Driver");
    String url = "jdbc:postgresql://localhost:9393/testdb";
    Connection conn = DriverManager.getConnection(url, "postgres", "postgres");
    PreparedStatement st = conn.prepareStatement("INSERT INTO mytable (name, age) VALUES (?, ?) returning 0");
    conn.setAutoCommit(false);

    st.setCharacterStream(1, new StringReader("John"));
    st.setInt(2, 25);
    st.addBatch();

    st.executeBatch();

    conn.commit();

    st.close();
    conn.close();
}

}


**Expected behavior**
The query should be inserted with the value encrypted

**Acra configuration files**
    - [ ] `encryptor_config.yaml`

Environment (please complete the following information):

Lagovas commented 1 year ago

Thanks for the issue and found error case. I reproduced this case and will fix it it soon. Now, AcraServer handles returning clauses only with column names in the list and doesn't accept literals. We will change it to be more compatible with SQL syntax.

Machado117 commented 1 year ago

Ok, thanks!

Lagovas commented 1 year ago

Hi. We fixed this problem in recent PR #584. It is already in master.

Machado117 commented 1 year ago

Seems to be working. Thanks for the fix!