Amazon DynamoDB · Delete
Catch an injection attempt
A "remove my order" endpoint attacked two ways: a match column named with expression syntax, and a value written to widen the delete to every order; then the honest request.
Set up for this page
The scenarios build on the sample application: SampleContext.cs (the dbContext every sample is given); SampleOutput.cs (Step and Show, which print); SampleContext.Application.cs (dbContext.Service, the application's ARX service); SampleModel.cs (the DynamoDB layout and the schema catalog); SampleContext.Direct.cs (dbContext.Direct); DynamoDirectHelper.cs (the checks behind dbContext.Direct).
dbContext.Direct is the samples' own checking code on the plain driver, not part of ARX: leave it out of your application.
Before scenario 1 the sample runs this, so the service and the rows the scenarios use are there:
foreach (var (customerId, number) in new[] { ("C-D321", "SO-D321"), ("C-D322", "SO-D322") })
{
var order = new ArxEntity("sales_order");
order["customer_id"] = customerId;
order["order_number"] = number;
order["status"] = "OPEN";
order["ordered_on"] = "2026-11-05";
await service.CreateAsync(order);
}1 Expression syntax in the match
The match names "order_number OR attribute_exists(PK)": ARX1017.
Already in scope: service (ArxDynamoDbService)
var match = new ArxEntity("sales_order");
match["customer_id"] = "C-D321";
match["order_number OR attribute_exists(PK)"] = "x";
try
{
await service.DeleteAsync(match, new ArxDeleteOptions { Match = ArxMatch.Columns("customer_id", "order_number OR attribute_exists(PK)") });
}
catch (ArxValidationException exception) when (exception.Code == ArxErrorCode.SuspectedInjection)
{
Console.WriteLine(exception.Message);
}Check it in the database
A PartiQL statement: run it in NoSQL Workbench, or with aws dynamodb execute-statement --statement, after the code has run.
SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D321'Expect: 1 item, ORDER#SO-D321.
2 A value that widens the delete
A customer id of "C-D321' OR '1'='1": only a value, it names no item, so nothing goes.
Already in scope: service (ArxDynamoDbService)
var match = new ArxEntity("sales_order") { RecordId = ArxRecordId.Of("order_number", "SO-D322") };
match["customer_id"] = "C-D321' OR '1'='1";
int deleted = await service.DeleteAsync(match);
Console.WriteLine($"{deleted} items deleted");Check it in the database
A PartiQL statement: run it in NoSQL Workbench, or with aws dynamodb execute-statement --statement, after the code has run.
SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D322'Expect: 1 item, ORDER#SO-D322.
3 The honest request
The customer removes its own order.
Already in scope: service (ArxDynamoDbService)
var match = new ArxEntity("sales_order") { RecordId = ArxRecordId.Of("order_number", "SO-D321") };
match["customer_id"] = "C-D321";
int deleted = await service.DeleteAsync(match);
Console.WriteLine($"{deleted} item deleted");Check it in the database
A PartiQL statement: run it in NoSQL Workbench, or with aws dynamodb execute-statement --statement, after the code has run.
SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D321'Expect: no items.
Good to know
A name with expression or SQL syntax is ARX1017. Values are never part of an expression: ARX sends no PartiQL, and a value only ever names one key.
See also
Run the complete sample
The code above comes from one program, built in a fresh project and run against the database. To run it yourself, here is every file and step.
The program, its files and how to run it
Run it locally
- .NET SDK: .NET SDK 10.0.100 or later 10.0.x (target
net10.0). - Create the project:
Terminal dotnet new console -n ArxSample -f net10.0 cd ArxSample - Install the packages:
Terminal dotnet add package ARX.SDK.DynamoDb --version 1.0.0-rc.1 - Database: a Amazon DynamoDB, or DynamoDB Local for development (tested with DynamoDB Local 2.5.2) database with the sample schema.
- Configuration: set
ARX_SAMPLES_DYNAMODBto its connection string. Nothing is hard-coded. - Source code: add the files of the sample application this sample uses (
SampleContext.cs,SampleOutput.cs,SampleContext.Application.cs,SampleModel.cs,SampleContext.Direct.cs,DynamoDirectHelper.cs), then replaceProgram.csand add the other file below, with the file names shown. - Run it:
Terminal dotnet run - Expected output: below.
The files
Runs the sample. Generated for this page; it reads the connection string from the environment and first remakes the sample database from sample-schema.json.
using ArxSamples.DynamoDb;
using ArxSamples.DynamoDb.Operations.Delete.RealCases;
// The connection string comes from the environment, never from the code (see "Configure the connection").
var connectionString = Environment.GetEnvironmentVariable("ARX_SAMPLES_DYNAMODB")
?? throw new InvalidOperationException("Set the ARX_SAMPLES_DYNAMODB environment variable to your Amazon DynamoDB connection string.");
var dbContext = new SampleContext(connectionString);
// Every run starts from the sample data: this deletes and makes again what sample-schema.json lists
// (save the file in the project folder, see Get started).
await dbContext.Direct.ResetAsync();
await new RealCase1_CatchAnInjectionAttempt().RunAsync(dbContext);
The sample, as it is in the repository.
using ARX.SDK;
using ARX.SDK.DynamoDb.Services;
using ARX.SDK.Services;
using static ArxSamples.DynamoDb.SampleOutput;
namespace ArxSamples.DynamoDb.Operations.Delete.RealCases;
/// <summary>
/// A "remove my order" endpoint attacked two ways: a match column named with expression syntax, and a value written to
/// widen the delete to every order; then the honest request.
/// </summary>
/// <remarks>
/// A name with expression or SQL syntax is ARX1017. Values are never part of an expression: ARX sends no PartiQL, and a value
/// only ever names one key.
/// </remarks>
public sealed class RealCase1_CatchAnInjectionAttempt : ISample
{
public string Name => "delete-real-1-catch-an-injection-attempt";
public string Title => "Catch an injection attempt";
public async Task RunAsync(SampleContext dbContext)
{
foreach (var (customerId, number) in new[] { ("C-D321", "SO-D321"), ("C-D322", "SO-D322") })
{
var order = new ArxEntity("sales_order");
order["customer_id"] = customerId;
order["order_number"] = number;
order["status"] = "OPEN";
order["ordered_on"] = "2026-11-05";
await dbContext.Service.CreateAsync(order);
}
await Scenario1_ExpressionSyntaxInTheMatchAsync(dbContext.Service);
await Scenario2_AValueThatWidensTheDeleteAsync(dbContext.Service);
await Scenario3_TheHonestRequestAsync(dbContext.Service);
}
/// <summary>1. The match names "order_number OR attribute_exists(PK)": ARX1017.</summary>
private static async Task Scenario1_ExpressionSyntaxInTheMatchAsync(ArxDynamoDbService service)
{
Step("1. Expression syntax in the match");
var match = new ArxEntity("sales_order");
match["customer_id"] = "C-D321";
match["order_number OR attribute_exists(PK)"] = "x";
try
{
await service.DeleteAsync(match, new ArxDeleteOptions { Match = ArxMatch.Columns("customer_id", "order_number OR attribute_exists(PK)") });
}
catch (ArxValidationException exception) when (exception.Code == ArxErrorCode.SuspectedInjection)
{
ShowError(exception);
}
/* ===========================================================
* [DIRECT QUERY CHECK]
* -----------------------------------------------------------
* SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D321'
* -- Expect: 1 item, ORDER#SO-D321.
* ===========================================================
*/
}
/// <summary>2. A customer id of "C-D321' OR '1'='1": only a value, it names no item, so nothing goes.</summary>
private static async Task Scenario2_AValueThatWidensTheDeleteAsync(ArxDynamoDbService service)
{
Step("2. A value that widens the delete");
var match = new ArxEntity("sales_order") { RecordId = ArxRecordId.Of("order_number", "SO-D322") };
match["customer_id"] = "C-D321' OR '1'='1";
int deleted = await service.DeleteAsync(match);
Show($"{deleted} items deleted");
/* ===========================================================
* [DIRECT QUERY CHECK]
* -----------------------------------------------------------
* SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D322'
* -- Expect: 1 item, ORDER#SO-D322.
* ===========================================================
*/
}
/// <summary>3. The customer removes its own order.</summary>
private static async Task Scenario3_TheHonestRequestAsync(ArxDynamoDbService service)
{
Step("3. The honest request");
var match = new ArxEntity("sales_order") { RecordId = ArxRecordId.Of("order_number", "SO-D321") };
match["customer_id"] = "C-D321";
int deleted = await service.DeleteAsync(match);
Show($"{deleted} item deleted");
/* ===========================================================
* [DIRECT QUERY CHECK]
* -----------------------------------------------------------
* SELECT "SK" FROM "crm" WHERE "PK" = 'CUSTOMER#C-D321'
* -- Expect: no items.
* ===========================================================
*/
}
}
Expected output
What dotnet run printed when the sample was verified, on a freshly created sample schema. Ids differ when the tables already hold rows.
> 1. Expression syntax in the match
caught ArxValidationException: ARX1017 SuspectedInjection: Attribute name 'order_number OR attribute_exists(PK)' looks like an SQL injection attempt (contains '('). ARX refused it before sending anything to the database. Names must come from your code or a fixed list, never from user input.
> 2. A value that widens the delete
0 items deleted
> 3. The honest request
1 item deleted