Public concept tally export with one-origin CORS

GET /public/concepts/{collection}/tallies returns per-live-subject up, down and
member counts only, anonymous, Cache-Control public max-age=60. CORS policy
ConceptTallies is built from ConceptVotes:AllowedOrigins, GET only, no
credentials, required on this route alone. Production startup refuses an
allowed origin that is not an exact https origin.

Not yet built or tested when committed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-10 19:59:51 +02:00
commit d13b808471
5 changed files with 391 additions and 2 deletions

View file

@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.HttpLogging;
@ -205,6 +206,17 @@ builder.Services.AddAuthorization(options =>
});
});
// The one cross-origin surface: the public tally export, read by browsers on the configured origins only.
// No credentials, GET only; every other route carries no CORS metadata and gets no CORS headers.
const string ConceptTalliesCorsPolicy = "ConceptTallies";
builder.Services.AddCors();
builder.Services
.AddOptions<CorsOptions>()
.Configure<IOptions<ConceptVoteOptions>>((cors, conceptVotes) =>
cors.AddPolicy(
ConceptTalliesCorsPolicy,
policy => policy.WithOrigins(conceptVotes.Value.AllowedOrigins).WithMethods("GET")));
var app = builder.Build();
var appJsonSerializerOptions = CreateAppJsonSerializerOptions();
@ -228,6 +240,7 @@ app.UseHttpLogging();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseMiddleware<GitHubMembershipSynchronizationMiddleware>();
app.UseAuthorization();
@ -244,6 +257,23 @@ app.MapGet("/readyz", async (ReadinessService readinessService, CancellationToke
statusCode: StatusCodes.Status503ServiceUnavailable);
}).AllowAnonymous();
// Counts only, per live subject: ConceptTally carries no voter key, account id or network tag.
app.MapGet("/public/concepts/{collection}/tallies", async (
string collection,
ConceptAppraisalService appraisals,
HttpResponse response,
CancellationToken cancellationToken) =>
{
var tallies = await appraisals.GetTalliesAsync(collection, cancellationToken);
if (tallies.Count == 0)
{
return Results.NotFound();
}
response.Headers.CacheControl = "public, max-age=60";
return Results.Json(tallies);
}).AllowAnonymous().RequireCors(ConceptTalliesCorsPolicy);
app.MapPost("/github/webhooks", async (
HttpRequest request,
GitHubWebhookService gitHubWebhookService,