Skip to content

Commit 2848c37

Browse files
committed
The | is the new delimiter for Whitelist and Blacklist
For delimiting timestamp and notes in Whitelist and Blacklist entries, ? was used, but this made query string urls problematic. | is used now, while ? is still supported for backwards compatibility.
1 parent 014cb5f commit 2848c37

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

IPBanCore/Core/IPBan/IPBanFilter.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ namespace DigitalRuby.IPBanCore
3737
/// </summary>
3838
public class IPBanFilter : IIPBanFilter
3939
{
40+
/// <summary>
41+
/// Delimiter for each item in a filter string
42+
/// </summary>
43+
public const char ItemDelimiter = ',';
44+
45+
/// <summary>
46+
/// Item pieces delimiters including the legacy ? and the current |
47+
/// </summary>
48+
public static readonly char[] ItemPiecesDelimitersLegacy = ['?', '|'];
49+
50+
/// <summary>
51+
/// Item pieces delimiter |
52+
/// </summary>
53+
public const char ItemPiecesDelimiter = '|';
54+
55+
/// <summary>
56+
/// Used if multiple ips in one entry (rare)
57+
/// </summary>
58+
public const char SubEntryDelimiter = ';';
59+
4060
private static readonly HashSet<string> ignoreListEntries =
4161
[
4262
"0.0.0.0",
@@ -123,18 +143,19 @@ public IPBanFilter(string value, string regexValue, IHttpRequestMaker httpReques
123143
List<string> entries = [];
124144

125145
// primary entries (entry?timestamp?notes) are delimited by comma
126-
foreach (string entry in value.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
146+
// | can be used as a sub delimiter instead of ? mark
147+
foreach (string entry in value.Split(ItemDelimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
127148
{
128149
string entryWithoutComment = entry;
129-
int pos = entryWithoutComment.IndexOf('?');
150+
int pos = entryWithoutComment.IndexOfAny(ItemPiecesDelimitersLegacy);
130151
if (pos >= 0)
131152
{
132153
entryWithoutComment = entryWithoutComment[..pos];
133154
}
134155
entryWithoutComment = entryWithoutComment.Trim();
135156

136157
// sub entries (multiple ip addresses) are delimited by semi-colon
137-
foreach (string subEntry in entryWithoutComment.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
158+
foreach (string subEntry in entryWithoutComment.Split(SubEntryDelimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
138159
{
139160
entries.Add(subEntry);
140161
}

IPBanCore/ipban.config

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@
10071007
<!--
10081008
Comma separated list of ip addresses, cidr masks, urls or dns names that are never banned. Whitelist takes precedence over blacklist.
10091009
If you use a url, the response should be text and newline delimited, example: https://uptimerobot.com/inc/files/ips/IPv4andIPv6.txt.
1010-
For urls, ? char is not allowed, so if you need a query string, you must create a non ? url and have it 302 redirect to the new url with a ? in it.
1010+
For urls, | char is not allowed. If you need a url with this char, create a redirect without the |
10111011
Ips in this list are added to a whitelist firewall rule and will always be allowed.
10121012
-->
10131013
<add key="Whitelist" value=""/>
@@ -1021,8 +1021,7 @@
10211021
<add key="WhitelistRegex" value=""/>
10221022

10231023
<!--
1024-
Comma separated list of ip addresses, cidr masks, urls or dns names or user names to always ban and never unban
1025-
For urls, ? char is not allowed, so if you need a query string, you must create a non ? url and have it 302 redirect to the new url with a ? in it.
1024+
Same format as Whitelist, but for entries that are always banned. Whitelist takes precedence over blacklist.
10261025
-->
10271026
<add key="Blacklist" value=""/>
10281027

0 commit comments

Comments
 (0)