Bound profile and wallet object fields (#7693)
What changed, and why it matters
This commit adds input-length and type checks for user profile fields (name and avatar URL) and for transaction comments on wallet objects. Before the change, an attacker could supply oversized names or image URLs, or store very large or wrongly-typed transaction comments, through the Greenfield API. The patch rejects values that exceed set limits and ensures transaction comments are strings, which reduces the risk of database bloat, denial-of-service, and unexpected behavior when the data is later displayed.
Treat as a security-hardening fix and include in the next release. Review whether other profile or wallet object fields need similar bounds. No immediate incident response is indicated unless abnormal oversized user or wallet-object data is observed in existing records.
Security signals we found
Input length limits added to user profile fields (Name <= 50, ImageUrl <= 2048)
Type and length validation added to wallet transaction comment data
Server-side ModelState validation added to Greenfield API endpoints
Unit tests added to assert validation errors for oversized or wrongly-typed inputs
Password-validation branch now also checks ModelState.IsValid before running
Evidence from the diff
The change enforces server-side validation in two Greenfield API controllers. GreenfieldUsersController now caps Name at 50 characters and ImageUrl at 2048 characters for both user creation and current-user update. GreenfieldStoreOnChainWalletsController now validates that a transaction object’s ‘comment’ field, if present, is a string and does not exceed WalletRepository.MaxCommentSize. Tests were added to confirm the validation errors are returned. The patch is defensive hardening; it does not by itself show an active exploit, but it closes clear input-validation gaps.
Changed components
BTCPayServer/Controllers/GreenField/GreenfieldUsersController.csBTCPayServer/Plugins/Wallets/Controllers/GreenfieldStoreOnChainWalletsController.csGreenfield API user creation and update endpointsGreenfield API on-chain wallet object add/update endpointInspect captured patch +51 / −1
### BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -1311,6 +1311,15 @@ public async Task CanUpdateUsersViaAPI()
await tester.StartAsync();
var unauthClient = new BTCPayServerClient(tester.PayTester.ServerUri);
+ await AssertValidationError(["Name", "ImageUrl"], () =>
+ unauthClient.CreateUser(new CreateApplicationUserRequest
+ {
+ Email = "oversized-profile@gmail.com",
+ Password = "abceudhqw",
+ Name = new string('A', 51),
+ ImageUrl = new string('B', 2049)
+ }));
+
// We have no admin, so it should work
var user = await unauthClient.CreateUser(
new CreateApplicationUserRequest { Email = "test@gmail.com", Password = "abceudhqw" });
@@ -1358,6 +1367,12 @@ await AssertValidationError(["CurrentPassword"],
Assert.Equal("administrator@gmail.com", changed.Email);
Assert.Equal("Changed Admin", changed.Name);
Assert.Equal("avatar.jpg", changed.ImageUrl);
+ await AssertValidationError(["Name", "ImageUrl"], () =>
+ adminClient.UpdateCurrentUser(new UpdateApplicationUserRequest
+ {
+ Name = new string('A', 51),
+ ImageUrl = new string('B', 2049)
+ }));
}
[Fact(Timeout = TestTimeout)]
@@ -4367,6 +4382,26 @@ public async Task CanUseWalletObjectsAPI()
var client = await admin.CreateClient(Policies.Unrestricted);
Assert.Empty(await client.GetOnChainWalletObjects(admin.StoreId, "BTC"));
+ await AssertValidationError([nameof(AddOnChainWalletObjectRequest.Data)], () =>
+ client.AddOrUpdateOnChainWalletObject(admin.StoreId, "BTC",
+ new AddOnChainWalletObjectRequest(WalletObjectData.Types.Tx,
+ "0000000000000000000000000000000000000000000000000000000000000005")
+ {
+ Data = new JObject
+ {
+ ["comment"] = new string('x', WalletRepository.MaxCommentSize + 1)
+ }
+ }));
+ await AssertValidationError([nameof(AddOnChainWalletObjectRequest.Data)], () =>
+ client.AddOrUpdateOnChainWalletObject(admin.StoreId, "BTC",
+ new AddOnChainWalletObjectRequest(WalletObjectData.Types.Tx,
+ "0000000000000000000000000000000000000000000000000000000000000006")
+ {
+ Data = new JObject
+ {
+ ["comment"] = new JObject()
+ }
+ }));
var test = new OnChainWalletObjectId("test", "test");
Assert.NotNull(await client.AddOrUpdateOnChainWalletObject(admin.StoreId, "BTC", new AddOnChainWalletObjectRequest(test.Type, test.Id)));
### BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs
@@ -164,6 +164,10 @@ public async Task<IActionResult> UpdateCurrentUser(UpdateApplicationUserRequest
{
ModelState.AddModelError(nameof(request.Email), "Invalid email");
}
+ if (request.Name?.Length > 50)
+ ModelState.AddModelError(nameof(request.Name), "Name is too long");
+ if (request.ImageUrl?.Length > 2048)
+ ModelState.AddModelError(nameof(request.ImageUrl), "ImageUrl is too long");
bool needUpdate = false;
var setNewPassword = !string.IsNullOrEmpty(request.NewPassword);
@@ -177,7 +181,7 @@ public async Task<IActionResult> UpdateCurrentUser(UpdateApplicationUserRequest
ModelState.AddModelError(nameof(request.CurrentPassword), "The current password is not correct.");
}
- if (setNewPassword && currentPasswordValid)
+ if (setNewPassword && currentPasswordValid && ModelState.IsValid)
{
var passwordValidation = await _passwordValidator.ValidateAsync(_userManager, user, request.NewPassword);
if (passwordValidation.Succeeded)
@@ -327,6 +331,10 @@ public async Task<IActionResult> CreateUser(CreateApplicationUserRequest request
ModelState.AddModelError(nameof(request.Email), "Email is missing");
if (!MailboxAddressValidator.IsMailboxAddress(request.Email))
ModelState.AddModelError(nameof(request.Email), "Invalid email");
+ if (request.Name?.Length > 50)
+ ModelState.AddModelError(nameof(request.Name), "Name is too long");
+ if (request.ImageUrl?.Length > 2048)
+ ModelState.AddModelError(nameof(request.ImageUrl), "ImageUrl is too long");
if (!ModelState.IsValid)
return this.CreateValidationError(ModelState);
### BTCPayServer/Plugins/Wallets/Controllers/GreenfieldStoreOnChainWalletsController.cs
@@ -784,6 +784,13 @@ public async Task<IActionResult> AddOrUpdateOnChainWalletObject(string storeId,
ModelState.AddModelError(nameof(request.Type), "Type is required");
if (request?.Id is null)
ModelState.AddModelError(nameof(request.Id), "Id is required");
+ if (request?.Type == WalletObjectData.Types.Tx && request.Data?["comment"] is { } comment)
+ {
+ if (comment.Type != JTokenType.String)
+ ModelState.AddModelError(nameof(request.Data), "The transaction comment must be a string");
+ else if (comment.Value<string>()?.Length > WalletRepository.MaxCommentSize)
+ ModelState.AddModelError(nameof(request.Data), "The transaction comment is too long");
+ }
if (!ModelState.IsValid)
return this.CreateValidationError(ModelState);
Why this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.