AlphaQuantum.WebFilteringDatabase
1.0.1
dotnet add package AlphaQuantum.WebFilteringDatabase --version 1.0.1
NuGet\Install-Package AlphaQuantum.WebFilteringDatabase -Version 1.0.1
<PackageReference Include="AlphaQuantum.WebFilteringDatabase" Version="1.0.1" />
<PackageVersion Include="AlphaQuantum.WebFilteringDatabase" Version="1.0.1" />
<PackageReference Include="AlphaQuantum.WebFilteringDatabase" />
paket add AlphaQuantum.WebFilteringDatabase --version 1.0.1
#r "nuget: AlphaQuantum.WebFilteringDatabase, 1.0.1"
#:package AlphaQuantum.WebFilteringDatabase@1.0.1
#addin nuget:?package=AlphaQuantum.WebFilteringDatabase&version=1.0.1
#tool nuget:?package=AlphaQuantum.WebFilteringDatabase&version=1.0.1
AlphaQuantum.WebFilteringDatabase
Classify a domain into a web filtering category from C#. Filtering proxies, DNS services, parental-control apps and MSP portals built on .NET use this client to label domains their local lists do not cover, with a domain category lookup service.
dotnet add package AlphaQuantum.WebFilteringDatabase
Basic use
using AlphaQuantum.WebFilteringDatabase;
var wf = new WebFilteringDatabaseClient(Environment.GetEnvironmentVariable("AQ_API_KEY")!);
var r = await wf.ClassifyAsync("some-new-domain.example");
The result is a Dictionary<string, JsonElement> holding the service's reply unchanged. Its main value is the filtering category and a confidence score. The full list of fields is in the API reference on the product site.
The file and the API work together
The licensed database is a download you load into memory: fast, local, and fixed until the next release. This client covers what arrives in between. In practice, the file answers the vast majority of lookups and the API handles a small, steady trickle of new hosts. Build for that shape: local first, API for misses, and remember every answer.
Middleware for an ASP.NET Core filtering proxy
If your proxy runs on ASP.NET Core (for example with YARP), a middleware can decide before a request is forwarded. The expensive classification must never hold up the request itself:
public sealed class CategoryFilter(RequestDelegate next, CategoryStore store, PolicyTable policy)
{
public async Task InvokeAsync(HttpContext ctx)
{
var host = ctx.Request.Host.Host.ToLowerInvariant();
var category = store.Get(host); // file, then learned cache
if (category is null)
{
store.QueueForClassification(host); // background worker calls ClassifyAsync
category = "unclassified";
}
if (policy.Action(ctx.User, category) == "block")
{
ctx.Response.StatusCode = StatusCodes.Status403Forbidden;
await ctx.Response.WriteAsync($"Blocked by policy: {category}");
return;
}
await next(ctx);
}
}
A BackgroundService reads the queue through a Channel<string>, calls ClassifyAsync a few hosts at a time, and writes results into the store. The first visit to an unknown host follows your unclassified policy. Every later visit uses the real category.
What should "unclassified" do?
Choose per network, and write the choice down:
| Network | Common choice |
|---|---|
| K-12 school | Block until classified |
| Office | Allow, log, review weekly |
| Public Wi-Fi | Allow, except known high-risk categories |
| Kiosk | Block |
Very new domains appear disproportionately in phishing and fraud, so strict networks lose almost nothing by holding them for the short time classification takes.
Policies per tenant
MSPs and multi-site operators should separate two things that change at different speeds:
- Facts: which category a domain has. Store these once and share them across all tenants.
- Choices: what each tenant does with each category. Keep these in a small table per tenant.
A new customer then starts with every domain the platform has already learned, and a change in one customer's rules never affects another.
Exceptions and resilience
ArgumentException: empty key (constructor) or empty input (call).ApiException: any non-success response, withStatusCodeandBody. A 429 means pause the background worker. A 401 or 403 means a key or quota problem, so alert someone.TaskCanceledException: timeout (30 seconds unless your ownHttpClientsays otherwise) or cancellation.
Because classification runs in the background, failures cost nothing visible: the host stays unclassified and is queued again on its next visit.
Privacy
The client sends the domain or URL you pass, your key, and nothing else. No client IPs, user names or request headers leave your proxy. When you classify full URLs, strip query strings first. They can contain session tokens or email addresses, and the host alone determines the category.
Schools and CIPA
In the United States, schools and libraries that receive E-rate support must filter under the Children's Internet Protection Act. Categories for adult content, weapons, gambling and anonymising proxies map directly onto those duties. Many districts now also want a separate decision for generative AI, allowing it in some classes and blocking it during exams. A school district AI policy needs that decision, so add the AI register next to the main database.
Visibility before enforcement
Before tightening rules, see what people actually do. The log audit shows shadow AI examples from firewall logs you already keep. For hosts your file and cache have never seen, web content classification with IAB topics complements the filtering categories.
Testing your middleware
Build the client on an HttpClient with a stub handler that returns a fixed category, then assert that your middleware blocks or allows as the policy table says. The package's own tests use the same technique to confirm the key and query travel in the POST body.
Other ecosystems
For resolvers written in Go, use webfilteringdatabase-go. Flutter parental-control apps can call the pub.dev client. Rust appliances can use the crate.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.