openresty / openresty/lua-nginx-module

Time based deprecate for ngx.shared.DICT

Open
#649 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

Hi,

ngx.shared.DICT can usually be used for ip block lists. A cool feature that is available on modsecurity is deprecatevar which works as follow:

You define a variable which acts as a counter (for instance number of failed login attempts by a particular ip). Then in their rules they define deprecatevar 1/180 on that counter which reduces the counter by 1 in 180 seconds. In other words the counter only has the count of failed attempts in the last 180 seconds.

This would be an extremely useful function to help us write webserver firewall rules and even translate modsecuirty rules to native lua and just use lua for nginx.

My suggestion is to have ngx.shared.DICT:deprecate(key, amount,time) which will deprecate the value of "key" by the value of "amount" parameter only once in the next "time" seconds.
This function then usually should get called right after a ngx.shared.DICT:incr(key, value) to effectively expire result of the last increment after a set amount of time.

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.

Research direction

Start by reviewing the ngx.shared.DICT:incr API and the proposed ngx.shared.DICT:deprecate(key, amount, time) entry point, then compare their intended behavior with ModSecurity's deprecatevar. Done means the counter decreases by the requested amount only once during the specified interval and supports the described firewall-rule use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, nginx
Domain
backend, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.