Allow a regex whitelist

Open
#9 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Start at ServeHTTP and trace how the configured blocklist regular expressions are loaded and matched against req.URL.EscapedPath(). Add the proposed regexWhitelist behavior so matching whitelist expressions override a block, then verify that blocked paths remain forbidden while explicitly whitelisted paths are passed to the next handler.

Written by the indexing model from the issue text.

Description

Would we consider allowing a whitelist to work against the blocklist in this plugin? My use case is that I wish to block all paths beginning with, e.g. /wp-admin (the wordpress admin backend), but allow access to /wp-admin/admin-ajax.php specifically.

As Golang/RE2 expressions do not allow lookaheads, this is a difficult express to write (or impossible depending on the functionality required). I suspect this may be a common request (something that is fairly trivial with, say, .htaccess files).

One option would be to add a second configuration to the plugin, regexWhitelist, with ServeHTTP looking something along the lines of:

	currentPath := req.URL.EscapedPath()
	blocked := false

	for _, re := range b.regexps {
		if re.MatchString(currentPath) {
			blocked = true
			break
		}
	}

	for _, re := range b.regexpsWhitelist {
		if re.MatchString(currentPath) {
			blocked = false
			break
		}
	}

	if (blocked) {
		rw.WriteHeader(http.StatusForbidden)
		return
	}

	b.next.ServeHTTP(rw, req)

(may not be perfect, been a while since I wrote some Golang)

Thoughts?

Dominant language
Go
Stars
28
Forks
18
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from traefik/plugin-blockpath

All issues in traefik/plugin-blockpath

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.