Owner decision 2026-10-04: fix the account privacy findings.
- Sign-in. Every failure answers "That username and password do not match." after the same work: an unknown login
is hashed against a decoy, and the comparison is constant-time. "Banned" is told only to someone who gave the right
password. This covers /clientapi/user/login, /invitation/login and /oauth/login.
- Recovery.
- Every request answers the same sentence and queues a SendRecovery job, whether or not the account exists or has an
email. The lookup, the code and SMTP move to RecoveryJob, so neither the answer nor its timing says anything.
- Codes are kept only as a SHA-256 hash, for one hour. Migration _011 drops the plaintext ones, which never expired.
- A recovered password ends every session of the root. RootSessions sets CredentialsChangedAt, which JwtEvents
checks against the JWT's issue time, now stamped as nbf, and revokes each persona's OAuth tokens and authorizations.
- Deleting a root (RootRemoval: the admin route, or the restored self-delete at /clientapi/user/delete, which asks for
the password).
- Its sessions end.
- Each persona and each group it owns sends Delete{Actor} to its followers, its members and the accounts it follows.
- The personas' posts are emptied.
- /peasants/{name} answers 410 with a Tombstone (formerType Person or Group), as do its inbox and WebFinger, through
LocalActorService.Gone. The names stay reserved.
- The root keeps only a unique `deleted-{id}` name; the second deletion on an instance used to collide on
"Deleted user".
Also, from phase 2's pasture: GoToSocial files a circle post like a DM and shows it only to accounts it mentions. Each
member's copy, and a member's refetch, now also mentions that member silently. The GoToSocial scenario checks circle
posts in conversations, like DMs, and they pass there now, as on Mastodon.
657 tests pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
129 lines
4.8 KiB
C#
129 lines
4.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using MongoDB.Entities;
|
|
|
|
using PrivaPub.Models.Federation;
|
|
using PrivaPub.Models.Post;
|
|
using PrivaPub.Models.User;
|
|
using PrivaPub.StaticServices;
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
using PostEntity = PrivaPub.Models.Post.Post;
|
|
using PrivaPub.Domain.Privacy;
|
|
using PrivaPub.Federation.Actors;
|
|
using PrivaPub.Infrastructure;
|
|
|
|
namespace PrivaPub.Federation.Controllers
|
|
{
|
|
[ApiController]
|
|
public class WellKnownController : ControllerBase
|
|
{
|
|
readonly ILocalActorService _localActors;
|
|
readonly DbEntities _dbEntities;
|
|
readonly IOptionsMonitor<RegistrationOptions> _registrations;
|
|
|
|
public WellKnownController(ILocalActorService localActors, DbEntities dbEntities, IOptionsMonitor<RegistrationOptions> registrations)
|
|
{
|
|
_registrations = registrations;
|
|
_localActors = localActors;
|
|
_dbEntities = dbEntities;
|
|
}
|
|
|
|
[HttpGet, Route("/.well-known/webfinger")]
|
|
public async Task<IActionResult> WebFinger([FromQuery] string resource, CancellationToken token)
|
|
{
|
|
if (string.IsNullOrEmpty(resource))
|
|
return BadRequest();
|
|
|
|
LocalActor actor;
|
|
// Mastodon, GoToSocial and Pleroma also take a bare user@domain or @user@domain, so we do too.
|
|
var acct = resource.StartsWith("acct:", StringComparison.OrdinalIgnoreCase) ? resource[5..]
|
|
: !resource.Contains("://", StringComparison.Ordinal) && resource.Contains('@') ? resource
|
|
: default;
|
|
if (acct != default)
|
|
{
|
|
var parts = acct.TrimStart('@').Split('@');
|
|
var domain = new Uri(_localActors.BaseAddress).Authority;
|
|
if (parts.Length != 2 || !parts[1].Equals(domain, StringComparison.OrdinalIgnoreCase))
|
|
return NotFound();
|
|
actor = await _localActors.FindByUserName(parts[0], token);
|
|
if (actor == default && await _localActors.Gone(parts[0], token) != default)
|
|
return StatusCode(StatusCodes.Status410Gone);
|
|
}
|
|
else
|
|
actor = await _localActors.FindByUri(resource, token);
|
|
|
|
if (actor is not { IsFederated: true })
|
|
return NotFound();
|
|
|
|
var document = new JsonObject
|
|
{
|
|
["subject"] = $"acct:{actor.Handle}",
|
|
["aliases"] = actor.Kind == LocalActorKind.Application ? new JsonArray(actor.Uri) : new JsonArray(actor.HtmlUrl, actor.Uri),
|
|
["links"] = actor.Kind == LocalActorKind.Application
|
|
? new JsonArray(new JsonObject { ["rel"] = "self", ["type"] = "application/activity+json", ["href"] = actor.Uri })
|
|
: new JsonArray(
|
|
new JsonObject { ["rel"] = "http://webfinger.net/rel/profile-page", ["type"] = "text/html", ["href"] = actor.HtmlUrl },
|
|
new JsonObject { ["rel"] = "self", ["type"] = "application/activity+json", ["href"] = actor.Uri })
|
|
};
|
|
return Content(document.ToJsonString(), "application/jrd+json; charset=utf-8");
|
|
}
|
|
|
|
[HttpGet, Route("/.well-known/nodeinfo")]
|
|
public IActionResult NodeInfoLinks()
|
|
{
|
|
var document = new JsonObject
|
|
{
|
|
["links"] = new JsonArray(
|
|
new JsonObject
|
|
{
|
|
["rel"] = "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
|
["href"] = $"{_localActors.BaseAddress}/nodeinfo/2.1"
|
|
},
|
|
new JsonObject
|
|
{
|
|
["rel"] = "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
|
["href"] = $"{_localActors.BaseAddress}/nodeinfo/2.0"
|
|
})
|
|
};
|
|
return Content(document.ToJsonString(), "application/json; charset=utf-8");
|
|
}
|
|
|
|
[HttpGet, Route("/nodeinfo/{version:regex(^2\\.[[01]]$)}")]
|
|
public async Task<IActionResult> NodeInfo(string version, CancellationToken token)
|
|
{
|
|
var users = await DB.Default.CountAsync<Avatar>(a => !a.DeletionAt.HasValue, token);
|
|
var posts = await DB.Default.CountAsync<PostEntity>(f => f.Where(p => !p.IsFederatedCopy && p.ReblogOfPostId == null) & f.Where(VisibilityPolicy.IsPublic), token);
|
|
var software = new JsonObject { ["name"] = "privapub", ["version"] = BuildInfo.Ref };
|
|
if (version == "2.1")
|
|
{
|
|
software["repository"] = "https://git.thepra.dev/thepra/SocialPub";
|
|
software["homepage"] = "https://git.thepra.dev/thepra/SocialPub";
|
|
}
|
|
var document = new JsonObject
|
|
{
|
|
["version"] = version,
|
|
["software"] = software,
|
|
["protocols"] = new JsonArray("activitypub"),
|
|
["services"] = new JsonObject { ["inbound"] = new JsonArray(), ["outbound"] = new JsonArray() },
|
|
["openRegistrations"] = _registrations.CurrentValue.IsOpen,
|
|
["usage"] = new JsonObject
|
|
{
|
|
["users"] = new JsonObject { ["total"] = users },
|
|
["localPosts"] = posts
|
|
},
|
|
["metadata"] = new JsonObject
|
|
{
|
|
["nodeName"] = "PrivaPub",
|
|
["nodeDescription"] = "A small ActivityPub server where one private login keeps several unlinkable public personas.",
|
|
["federation"] = new JsonObject { ["document"] = "https://git.thepra.dev/thepra/SocialPub/src/branch/master/FEDERATION.md" }
|
|
}
|
|
};
|
|
return Content(document.ToJsonString(),
|
|
$"application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/{version}#\"; charset=utf-8");
|
|
}
|
|
}
|
|
}
|