Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions engine/src/main/java/com/arcadedb/engine/PageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.arcadedb.database.DatabaseInternal;
import com.arcadedb.exception.ConcurrentModificationException;
import com.arcadedb.exception.ConfigurationException;
import com.arcadedb.exception.DatabaseIsClosedException;
import com.arcadedb.exception.DatabaseMetadataException;
import com.arcadedb.log.LogManager;
import com.arcadedb.utility.CallableNoReturn;
Expand Down Expand Up @@ -372,13 +373,19 @@ protected void flushPage(final MutablePage page) throws IOException {
totalPagesWrittenSize.addAndGet(written);
});

final PaginatedComponent component = (PaginatedComponent) database.getSchema().getFileByIdIfExists(fileId);
if (component != null)
component.updatePageCount(page.pageId.getPageNumber() + 1);
try {
final PaginatedComponent component = (PaginatedComponent) database.getSchema().getFileByIdIfExists(fileId);
if (component != null)
component.updatePageCount(page.pageId.getPageNumber() + 1);

totalPagesWritten.incrementAndGet();
totalPagesWritten.incrementAndGet();

database.getTransactionManager().notifyPageFlushed(page);
database.getTransactionManager().notifyPageFlushed(page);
} catch (final DatabaseIsClosedException e) {
// The database was closed concurrently after the isOpen() check above.
// The page data has already been written to disk, so we can safely skip
// the metadata updates.
}

} else
LogManager.instance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ public AnalyzedQuery analyze(final String query) {

@Override
public ResultSet query(final String query, final ContextConfiguration configuration, final Map<String, Object> parameters) {
if (!analyze(query).isIdempotent())
final ArcadeCypher arcadeCypher = arcadeGraph.cypher(query);
arcadeCypher.setParameters(parameters);
if (!arcadeCypher.parse().isIdempotent())
throw new QueryNotIdempotentException("Query '" + query + "' is not idempotent");
return command(query, configuration, parameters);
}

@Override
public ResultSet query(final String query, final ContextConfiguration configuration, final Object... parameters) {
if (!analyze(query).isIdempotent())
throw new QueryNotIdempotentException("Query '" + query + "' is not idempotent");
return command(query, null, parameters);
if (parameters.length % 2 != 0)
throw new IllegalArgumentException("Command parameters must be as pairs `<key>, <value>`");

final Map<String, Object> map = new LinkedHashMap<>(parameters.length / 2);
for (int i = 0; i < parameters.length; i += 2)
map.put((String) parameters[i], parameters[i + 1]);
return query(query, configuration, map);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ public String getLanguage() {

@Override
public ResultSet query(final String query, ContextConfiguration configuration, final Map<String, Object> parameters) {
if (!analyze(query).isIdempotent())
final ArcadeGremlin arcadeGremlin = arcadeGraph.gremlin(query);
arcadeGremlin.setParameters(parameters);
if (!arcadeGremlin.parse().isIdempotent())
throw new QueryNotIdempotentException("Query '" + query + "' is not idempotent");
return command(query, null, parameters);
}

@Override
public ResultSet query(final String query, ContextConfiguration configuration, final Object... parameters) {
if (!analyze(query).isIdempotent())
throw new QueryNotIdempotentException("Query '" + query + "' is not idempotent");
return command(query, null, parameters);
if (parameters.length % 2 != 0)
throw new IllegalArgumentException("Command parameters must be as pairs `<key>, <value>`");

final Map<String, Object> map = new HashMap<>(parameters.length / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with CypherQueryEngine and to prevent potential issues related to parameter ordering, it would be better to use LinkedHashMap here instead of HashMap. LinkedHashMap preserves the insertion order of parameters, which can be important in some scenarios.

Suggested change
final Map<String, Object> map = new HashMap<>(parameters.length / 2);
final Map<String, Object> map = new LinkedHashMap<>(parameters.length / 2);

for (int i = 0; i < parameters.length; i += 2)
map.put((String) parameters[i], parameters[i + 1]);
return query(query, configuration, map);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static Set<OperationType> detectMongoOperationTypes(final String query)
|| upper.contains("\"REMOVE\""))
return CollectionUtils.singletonSet(OperationType.DELETE);
if (upper.contains("\"FIND\"") || upper.contains("\"AGGREGATE\"") || upper.contains("\"COUNT\"")
|| upper.contains("\"DISTINCT\""))
|| upper.contains("\"DISTINCT\"")
|| upper.contains("COLLECTION"))
return CollectionUtils.singletonSet(OperationType.READ);
Comment on lines 81 to 84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

A high-severity bypass vulnerability exists in the detectMongoOperationTypes idempotency check. The use of upper.contains("COLLECTION") is too broad and is checked before more specific SCHEMA operations. This allows an attacker to misclassify destructive commands like CREATECOLLECTION or DROP as READ operations by including "COLLECTION" in the command, enabling their execution via the query() method which is intended for idempotent operations only. To fix this, the order of checks should be swapped, prioritizing specific SCHEMA commands before the general READ check.

if (upper.contains("\"CREATEINDEX\"") || upper.contains("\"CREATECOLLECTION\"") || upper.contains("\"DROP\"")
|| upper.contains("\"DROPCOLLECTION\"") || upper.contains("\"DROPINDEX\""))
Expand Down
Loading