Skip to content

Commit 0df3c58

Browse files
rustyrussellendothermicdev
authored andcommitted
plugins/sql: allow deprecated field access if wildcards are used.
Otherwise, deprecating a field causes SELECT * to fail: ``` > l1.rpc.sql(f"SELECT * FROM peerchannels;") ... > raise RpcError(method, payload, resp['error']) E pyln.client.lightning.RpcError: RPC call failed: method: sql, payload: ('SELECT * FROM peerchannels;',), error: {'code': -1, 'message': 'query failed with access to peerchannels.max_total_htlc_in_msat is prohibited (Deprecated column table peerchannels.max_total_htlc_in_msat)'} ``` So if they use a wildcard, allow access: though "SELECT *" is fraught, "COUNT(*)" is perfectly legit. Signed-off-by: Rusty Russell <[email protected]>
1 parent 37828b5 commit 0df3c58

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

plugins/sql.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct db_query {
9393
sqlite3_stmt *stmt;
9494
struct table_desc **tables;
9595
const char *authfail;
96+
bool has_wildcard;
9697
};
9798

9899
struct table_desc {
@@ -292,11 +293,14 @@ static int sqlite_authorize(void *dbq_, int code,
292293
if (!col->depr_start)
293294
return SQLITE_OK;
294295

295-
/* Can this command see this? */
296+
/* Can this command see this? We have to allow this
297+
* (as null) with "SELECT *" though! */
296298
if (!command_deprecated_in_named_ok(dbq->cmd, td->cmdname,
297299
col->jsonname,
298300
col->depr_start,
299301
col->depr_end)) {
302+
if (dbq->has_wildcard)
303+
return SQLITE_IGNORE;
300304
dbq->authfail = tal_fmt(dbq, "Deprecated column table %s.%s", a, b);
301305
return SQLITE_DENY;
302306
}
@@ -1051,6 +1055,10 @@ static struct command_result *json_sql(struct command *cmd,
10511055
dbq->tables = tal_arr(dbq, struct table_desc *, 0);
10521056
dbq->authfail = NULL;
10531057
dbq->cmd = cmd;
1058+
/* We might want to warn on SELECT *, since that is not really
1059+
* recommended as fields change, but SELECT COUNT(*) is totally
1060+
* legitimate. So we suppress deprecation errors in this case */
1061+
dbq->has_wildcard = (strchr(query, '*') != NULL);
10541062

10551063
/* This both checks we're not altering, *and* tells us what
10561064
* tables to refresh. */

0 commit comments

Comments
 (0)