Skip to content

Commit 6f9b1fa

Browse files
committed
Fixed dupe mitigate security section
1 parent 7fae625 commit 6f9b1fa

File tree

1 file changed

+0
-53
lines changed

1 file changed

+0
-53
lines changed

aspnetcore/web-api/jsonpatch/includes/jsonpatch9.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -532,57 +532,4 @@ To test the sample, run the app and send HTTP requests with the following settin
532532
* Body: Copy and paste one of the JSON patch document samples from the *JSON* project folder.
533533

534534
:::moniker-end
535-
## Mitigating security risks
536-
537-
When using the `Microsoft.AspNetCore.JsonPatch` package with the `Newtonsoft.Json`-based implementation, it's critical to understand and mitigate potential security risks. The following sections outline the identified security risks associated with JSON Patch and provide recommended mitigations to ensure secure usage of the package.
538-
539-
> [!IMPORTANT]
540-
> ***This is not an exhaustive list of threats.*** App developers must conduct their own threat model reviews to determine an app-specific comprehensive list and come up with appropriate mitigations as needed. For example, apps which expose collections to patch operations should consider the potential for algorithmic complexity attacks if those operations insert or remove elements at the beginning of the collection.
541-
542-
By running comprehensive threat models for their own apps and addressing identified threats while following the recommended mitigations below, consumers of these packages can integrate JSON Patch functionality into their apps while minimizing security risks.
543-
544-
### Denial of Service (DoS) via memory amplification
545-
546-
* **Scenario**: A malicious client submits a `copy` operation that duplicates large object graphs multiple times, leading to excessive memory consumption.
547-
* **Impact**: Potential Out-Of-Memory (OOM) conditions, causing service disruptions.
548-
* **Mitigation**:
549-
* Validate incoming JSON Patch documents for size and structure before calling `ApplyTo`.
550-
* The validation needs to be app specific, but an example validation can look similar to the following:
551-
552-
```csharp
553-
public void Validate(JsonPatchDocument patch)
554-
{
555-
// This is just an example. It's up to the developer to make sure that
556-
// this case is handled properly, based on the app needs.
557-
if (patch.Operations.Where(op => op.OperationType == OperationType.Copy).Count()
558-
> MaxCopyOperationsCount)
559-
{
560-
throw new InvalidOperationException();
561-
}
562-
}
563-
```
564-
565-
### Business Logic Subversion
566-
567-
* **Scenario**: Patch operations can manipulate fields with implicit invariants (for example, internal flags, IDs, or computed fields), violating business constraints.
568-
* **Impact**: Data integrity issues and unintended app behavior.
569-
* **Mitigation**:
570-
* Use POCO objects with explicitly defined properties that are safe to modify.
571-
* Avoid exposing sensitive or security-critical properties in the target object.
572-
* If no POCO object is used, validate the patched object after applying operations to ensure business rules and invariants aren't violated.
573-
574-
### Authentication and authorization
575-
576-
* **Scenario**: Unauthenticated or unauthorized clients send malicious JSON Patch requests.
577-
* **Impact**: Unauthorized access to modify sensitive data or disrupt app behavior.
578-
* **Mitigation**:
579-
* Protect endpoints accepting JSON Patch requests with proper authentication and authorization mechanisms.
580-
* Restrict access to trusted clients or users with appropriate permissions.
581-
582-
## Additional resources
583-
584-
* [IETF RFC 5789 PATCH method specification](https://tools.ietf.org/html/rfc5789)
585-
* [IETF RFC 6902 JSON Patch specification](https://tools.ietf.org/html/rfc6902)
586-
* [IETF RFC 6901 JSON Patch path format spec](https://tools.ietf.org/html/rfc6901)
587-
* [ASP.NET Core JSON Patch source code](https://github.com/dotnet/AspNetCore/tree/main/src/Features/JsonPatch/src)
588535

0 commit comments

Comments
 (0)