Regex: Wrong token

Expected Behaviour:

I have several regexes in my rules like

(^|\.)2o7\.net$

or

(^|\.)302br\.net$

So I expected that adding 51yes.com as wildcard or regex would also be accepted. But not so.

Actual Behaviour:

I tried to add 51yes.com as wildcard to my blacklist in the Pi-hole Admin Console but got:

Failure! Something went wrong.
Wrong token

Then I tried to add

(^|\.)51yes\.com$

as regex but I got the same error message.

Debug Token:

My debug token is: v0wm43nzp9

Btw: I also tried to add it on the console by executing:

pihole -b -wild 51yes.com

Result: I got 2 entries in the Blacklist/Exact blocking, namely

-wild

and

51yes.com

Not, it was not in the list. I tried it again on the console and got:

root@DietPi:~# pihole -b -wild 51yes.com
  [i] Adding -wild to blacklist...
  [i] -wild does not exist in whitelist, no need to remove!
  [i] Adding 51yes.com to blacklist...
  [i] 51yes.com does not exist in whitelist, no need to remove!

The funny thing is: Now I have two entries -wild in Exact blocking and can't get rid of them. Whenever I delete them and reload that page they are back :face_with_raised_eyebrow:

This is going more and more strange!

I executed

root@DietPi:~# pihole -b --wild 51yes.com
  [i] Adding (^|\.)51yes\.com$ to regex list...
  [i] 51yes.com does not exist in whitelist, no need to remove!

i.e. this time I used a double hyphen for the wild switch now. And now I'm finding the following entry in Regex & Wildcard blocking:

(^|\.)2o7\.net$(^|\.)51yes\.com$

So it was added to another entry - weird :open_mouth:

Okay, I manually deleted those entries in /etc/pihole/blacklist.txt. That fixed the problem but it's still strange ...

As you already found, you need --wild for wildcard entries.

However, wildcard and regex entries are not the same as "wildcard" entries will be added to the regex.list prepended with (^|\.) to ensure to get regex that are compatible with what we previously (i.e., pre-v4.0) called wildcards.

For adding regex entries, you need to run

$ pihole -b --regex "51yes.com"
  [i] Adding 51yes.com to regex list...
  [i] 51yes.com does not exist in whitelist, no need to remove!

This means that this line had no trailing newline character (\n). If you haven't edited the file manually, it is unclear how this could come about. I tried a few things you mentioned here but still wasn't able to trigger such a thing.

This simply means that your web session has expired. If you would have gone to any other page (or reloaded the page by pressing F5), you'd have seen that you need to re-login.

1 Like

@DL6ER: Thanks for your detailed answer - see my notes below!

Okay, but I had added, e.g., 2o7.net or 302br.net before in the admin console by clicking "Add (wildcard)" and they had been added as regexes as mentioned in my first post. So I still don't understand why it didn't work with 51yes.com.

This exactly happened again when I executed above command: 51yes.com was attached to (^|\.)2o7\.net$: it looked like(^|\.)2o7\.net$51yes.com. After deleting this modified entry, it finally worked. Then I removed (^|\.)51yes\.com$ again, entered 51yes.com and clicked "Add (wildcard)" - and surprise, surprise: Now it was accepted! I'm not sure why this inconsistent behaviour happened. Could it be that clicking "Add (wildcard)" does not (always) add a trailing newline character?

Hm, no. There was no need to re-login.

You misunderstood me. There was a need to re-login but there was also a bug that didn't show this to you. I'm working on an improvement for this.

Hmm, it should, but I will also again look at this.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.