{"id":19991517,"url":"https://github.com/stulzq/UrlFirewall","last_synced_at":"2025-05-04T10:31:58.350Z","repository":{"id":56250402,"uuid":"131976570","full_name":"stulzq/UrlFirewall","owner":"stulzq","description":"UrlFirewall is a lightweight, fast filtering middleware for http request urls.It supports blacklist, whitelist mode.Supports persisting filter rules to any media.You can use it in webapi, gateway, etc.","archived":false,"fork":false,"pushed_at":"2020-11-18T14:06:36.000Z","size":21,"stargazers_count":66,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-04-15T08:08:57.286Z","etag":null,"topics":["url-filter","url-firewall","webapi"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stulzq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-03T10:02:57.000Z","updated_at":"2024-08-25T22:48:06.000Z","dependencies_parsed_at":"2022-08-15T15:30:50.177Z","dependency_job_id":null,"html_url":"https://github.com/stulzq/UrlFirewall","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FUrlFirewall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FUrlFirewall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FUrlFirewall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FUrlFirewall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stulzq","download_url":"https://codeload.github.com/stulzq/UrlFirewall/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252320406,"owners_count":21729122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["url-filter","url-firewall","webapi"],"created_at":"2024-11-13T04:51:47.637Z","updated_at":"2025-05-04T10:31:53.423Z","avatar_url":"https://github.com/stulzq.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"﻿[![Latest version](https://img.shields.io/nuget/v/UrlFirewall.AspNetCore.svg)](https://www.nuget.org/packages/UrlFirewall.AspNetCore/) \n[![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/stulzq/UrlFirewall/blob/master/LICENSE) ![support-netstandard2.0](https://img.shields.io/badge/support-.NET%20Standard%202.0-green.svg) ![support-netcore2.0](https://img.shields.io/badge/support-.NET%20Core%202.0-green.svg) ![build status](https://img.shields.io/jenkins/s/https/ci2.xcmaster.com/job/UrlFirewall.svg)\n# UrlFirewall\n\nUrlFirewall is a lightweight, fast filtering middleware for http request urls.It supports blacklist, whitelist mode.Supports persisting filter rules to any media.You can use it in webapi, gateway, etc.\n\n## Language\n\nEnglish(Current) | [中文](http://www.cnblogs.com/stulzq/p/8987632.html)\n\n## Get start\n\n### 1.Install from Nuget to your Asp.Net Core project:\n\n````shell\nInstall-Package UrlFirewall.AspNetCore\n````\n\n### 2.Configure DI\n\n````csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddUrlFirewall(options =\u003e\n    {\n        options.RuleType = UrlFirewallRuleType.Black;\n        options.SetRuleList(Configuration.GetSection(\"UrlBlackList\"));\n        options.StatusCode = HttpStatusCode.NotFound;\n    });\n    services.AddMvc();\n    //...\n}\n````\n\n### 3.Configure url firewall middleware. \n\n\u003eThe order of middleware must be at the top most.\n\n````csharp\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env)\n{\n    //Configure url firewall middleware. Top most.\n    app.UseUrlFirewall();\n\n    if (env.IsDevelopment())\n    {\n        app.UseDeveloperExceptionPage();\n    }\n\n    app.UseMvc();\n}\n````\n\n### 4.Configure rule\n\nIn appsettings.json/appsettings.Devolopment.json create a section.\n\n````json\n{\n  \"Logging\": {\n    \"IncludeScopes\": false,\n    \"LogLevel\": {\n      \"Default\": \"Debug\",\n      \"System\": \"Information\",\n      \"Microsoft\": \"Information\"\n    }\n  },\n  \"UrlBlackList\": [\n    {\n      \"Url\": \"/api/cart/add\",\n      \"Method\": \"All\"\n    },\n    {\n      \"Url\": \"/api/cart/del\",\n      \"Method\": \"Post\"\n    },\n    {\n      \"Url\": \"/api/cart/list\",\n      \"Method\": \"Get\"\n    },\n    {\n      \"Url\": \"/api/product/*\",\n      \"Method\": \"All\"\n    }\n  ]\n}\n````\nThe url field is the http request path we need to match.It supports wildcard `*` and `?`.The `*` represents an arbitrary number of arbitrary characters. The `?` representative matches any one arbitrary character\n\n### 5.End\n\nNow,you access `/api/cart/add` etc.Will be get 404.Enjoy yourself.\n\n## Extensibility\n\nIf you want to implement validation logic yourself, or You want to verify by getting data from the database, redis etc.You can implement the `IUrlFirewallValidator` interface.Then you can replace the default implementation with the `AddUrlFirewallValidator` method.\n\ne.g:\n\n````csharp\nservices.AddUrlFirewall(options =\u003e\n{\n    options.RuleType = UrlFirewallRuleType.Black;\n    options.SetRuleList(Configuration.GetSection(\"UrlBlackList\"));\n    options.StatusCode = HttpStatusCode.NotFound;\n}).AddUrlFirewallValidator\u003cCustomValidator\u003e();\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2FUrlFirewall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstulzq%2FUrlFirewall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2FUrlFirewall/lists"}