GeezerVison is showing github.com — HTTP-API: URL encoded question mark causes error with `query` endpoint · Issue #1028 · ArcadeData/arcadedb
HTTP-API: URL encoded question mark causes error with query endpoint #1028DescriptionArcadeDB Server v23.3.1 (build da609e4/1680693032550/main) is starting up...
Running on Mac OS X 12.6.4 - OpenJDK 64-Bit Server VM Homebrewv
If an URL-encoded question mark %3F appears in a query sent via the query endpoint causes an error. This maybe a similar security issue as in #802 , but this is more severe from the usability point of view since a question mark ? is used as filter wildcard, control character in regular expressions and may appear in any data string. It appears %3F is treated as EOF?
Expected behavior
? as result of SELECT '?'.
Actual behavior
Cannot execute command
Trace
Error on command execution (GetQueryHandler)
com.arcadedb.exception.CommandSQLParsingException: SELECT '
at com.arcadedb.query.sql.parser.StatementCache.throwParsingException(StatementCache.java:130)
at com.arcadedb.query.sql.parser.StatementCache.parse(StatementCache.java:118)
at com.arcadedb.query.sql.parser.StatementCache.get(StatementCache.java:70)
at com.arcadedb.query.sql.SQLQueryEngine.parse(SQLQueryEngine.java:202)
at com.arcadedb.query.sql.SQLQueryEngine.query(SQLQueryEngine.java:85)
at com.arcadedb.database.EmbeddedDatabase.query(EmbeddedDatabase.java:1287)
at com.arcadedb.server.ServerDatabase.query(ServerDatabase.java:438)
at com.arcadedb.server.http.handler.GetQueryHandler.execute(GetQueryHandler.java:63)
at com.arcadedb.server.http.handler.DatabaseAbstractHandler.execute(DatabaseAbstractHandler.java:92)
at com.arcadedb.server.http.handler.AbstractHandler.handleRequest(AbstractHandler.java:127)
at io.undertow.server.RoutingHandler.handleRequest(RoutingHandler.java:93)
at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:256)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136)
at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:162)
at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:100)
at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:57)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:291)
at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:286)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.nio.QueuedNioTcpServer2.acceptTask(QueuedNioTcpServer2.java:178)
at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:612)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:479)
Caused by: com.arcadedb.query.sql.parser.TokenMgrError: Lexical error at line 1, column 9. Encountered: <EOF> after : ""
at com.arcadedb.query.sql.parser.SqlParserTokenManager.getNextToken(SqlParserTokenManager.java:5758)
at com.arcadedb.query.sql.parser.SqlParser.jj_scan_token(SqlParser.java:26804)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_ProjectionItem_1775_4_313(SqlParser.java:25587)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_ProjectionItem_1775_3_141(SqlParser.java:25595)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_Projection_1758_5_516(SqlParser.java:25652)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_Projection_1757_3_416(SqlParser.java:25665)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_SelectStatement_1143_7_282(SqlParser.java:20415)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_SelectStatement_1141_3_128(SqlParser.java:20454)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_QueryStatement_1106_5_354(SqlParser.java:20705)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_QueryStatement_1105_3_172(SqlParser.java:20731)
at com.arcadedb.query.sql.parser.SqlParser.jj_3R_StatementInternal_974_9_96(SqlParser.java:21596)
at com.arcadedb.query.sql.parser.SqlParser.jj_3_35(SqlParser.java:21636)
at com.arcadedb.query.sql.parser.SqlParser.jj_2_35(SqlParser.java:17519)
at com.arcadedb.query.sql.parser.SqlParser.StatementInternal(SqlParser.java:1263)
at com.arcadedb.query.sql.parser.SqlParser.Statement(SqlParser.java:1038)
at com.arcadedb.query.sql.parser.SqlParser.Parse(SqlParser.java:244)
at com.arcadedb.query.sql.parser.StatementCache.parse(StatementCache.java:111)
... 23 more
Steps to reproduce
curl -X GET "http://localhost:2480/api/v1/query/test/sql/SELECT%20'%3F'" --user root:arcadedb -v Activitygramian commented on Apr 11, 2023 CollaboratorAuthor More actions If this is not a bug, but a (undertow) server issue, an idea could be to introduce an alias for ? for example ¿ (extended ASCII 0xBF). lvca commented on Apr 12, 2023 Or for such cases, a POST is recommended. gramian commented on Apr 12, 2023 CollaboratorAuthor More actions
Could you provide an example for a POST to the query endpoint? POST is not allowed for the query endpoint, did you mean the command endpoint?
- Do you have an idea why this happens?
Thanks. gramian commented on Apr 12, 2023 CollaboratorAuthor More actions @lvca The situation here is different to #802 though, since question marks only appear inside strings. Thus here is another workaround:
this is using the SQL format function to convert the integer value of the question mark ? being 63, to a character. The part format('%c',63) generates a question mark without using sensitive symbols. I know it is a bit hacky, but working, see this example:
SELECT str FROM doc WHERE str LIKE format('%cello',63)
BTW: Did I miss an easier way to convert a number to character, like a chr function? gramian commented on Apr 13, 2023 CollaboratorAuthor More actions @lvca I finally understood what you meant by studying the studio code. I will add an example to the docs. You may close this issue.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|