项目作者: aron-666

项目描述 :
This is a firewall solution work from .Net Core 3.1, you can achieve the whitelist effect by setting policy for routing.
高级语言: C#
项目地址: git://github.com/aron-666/Aron.Web.WhiteList.git
创建时间: 2020-11-14T18:46:00Z
项目社区:https://github.com/aron-666/Aron.Web.WhiteList

开源协议:GNU Lesser General Public License v2.1

下载


Aron.Web.WhiteList

This is a firewall solution work from .Net Core 3.1, you can achieve the whitelist effect by setting policy for routing.

We use IPNetwork2 to handle address and cirb.

Installation

Nuget page

PM

  1. nuget install Aron.Web.WhiteList

Dotnet Cli

  1. dotnet add package Aron.Web.WhiteList

How To Use?

Startup.ConfigureServices

  1. inject IContentChecker

    1. services.AddSingleton<IContentChecker, ContentChecker>();
  1. inject IWhiteListService

    inject WhiteListService from database intro.Models.WhiteLists.WhiteListContext.

    1. services.AddSingleton<IWhiteListService, MyWhiteListService>();

    or inject WhiteListService from hard-coding.

    1. {
    2. var whitelists = new List<WhiteLists>()
    3. {
    4. new WhiteLists(){
    5. Id = 1,
    6. Name = "register",
    7. Route = "/Identity/Account/Register",
    8. WlContent = new List<WlContent>()
    9. }
    10. };
    11. var content = new List<WlContent>()
    12. {
    13. //Allow ::1 (localhost)
    14. new WlContent()
    15. {
    16. Id = 1,
    17. Wid = whitelists.First().Id,
    18. Policy = "Allow",
    19. Content = "::1",
    20. Source = whitelists.First()
    21. },
    22. //Allow 127.0.0.1
    23. new WlContent()
    24. {
    25. Id = 2,
    26. Wid = whitelists.First().Id,
    27. Policy = "Allow",
    28. Content = "127.0.0.1",
    29. Source = whitelists.First()
    30. },
    31. //Allow 192.168.64.129-254
    32. new WlContent()
    33. {
    34. Id = 3,
    35. Wid = whitelists.First().Id,
    36. Policy = "Allow",
    37. Content = "192.168.64.128/25",
    38. Source = whitelists.First()
    39. },
    40. //Deny 192.168.64.201
    41. new WlContent()
    42. {
    43. Id = 4,
    44. Wid = whitelists.First().Id,
    45. Policy = "Deny",
    46. Content = "192.168.64.201",
    47. Source = whitelists.First()
    48. },
    49. };
    50. whitelists[0].WlContent = content;
    51. services.AddSingleton<IEnumerable<WhiteLists>>(whitelists);
    52. }
    53. services.AddSingleton<IWhiteListService, WhiteListService>();
  1. inject options. if not need, you can not to inject.

    1. services.AddSingleton(whiteListOptions);

Startup.Configure

  1. UseDefaultWhiteListMiddleWare and configure onKill event.

    1. app.UseDefaultWhiteListMiddleWare(x =>
    2. x.Response.Redirect(Path.Combine(whiteListOptions.BasePath, "Home/Forbidden")));

    Examples

    See intro