Skip to content

Commit 3a464c8

Browse files
authored
Merge pull request #335 from PerimeterX/release/v7.3.3
Release/v7.3.3
2 parents 766ea85 + 8872edb commit 3a464c8

File tree

8 files changed

+67
-40
lines changed

8 files changed

+67
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [7.3.3] - 2024-07-19
10+
### Fixed
11+
- Fix rate_limit code for JSON responses
12+
13+
914
## [7.3.2] - 2024-07-17
1015
### Fixed
1116
- Fix rate_limit code
@@ -23,7 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2328
### Added
2429
- CORS support
2530
- Set X-PX-COOKIES as the default custom cookie name
26-
- _M.px_login_creds_settings configuration, to allow specify CI settings in Lua configuration file
31+
- `_M.px_login_creds_settings` configuration, to allow specify CI settings in Lua configuration file
2732

2833
### Changed
2934
- rename "px_graphql_paths" to "px_graphql_routes"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# [PerimeterX](http://www.perimeterx.com) NGINX Lua Plugin
44

5-
> Latest stable version: [v7.3.2](https://luarocks.org/modules/bendpx/perimeterx-nginx-plugin/7.3.2-1)
5+
> Latest stable version: [v7.3.3](https://luarocks.org/modules/bendpx/perimeterx-nginx-plugin/7.3.3-1)
66
77
## [Introduction](#introduction)
88

examples/Dockerfile.centos9

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ RUN luarocks install --lua-version 5.1 luasocket
1616
RUN luarocks install --lua-version 5.1 lua-resty-http
1717
RUN luarocks install --lua-version 5.1 luacheck
1818
RUN luarocks install --lua-version 5.1 lua-resty-nettle
19-
RUN luarocks install --lua-version 5.1 perimeterx-nginx-plugin
19+
#RUN luarocks install --lua-version 5.1 perimeterx-nginx-plugin
20+
21+
RUN mkdir -p /tmp/px
22+
COPY Makefile /tmp/px/
23+
COPY lib /tmp/px/lib
24+
COPY t /tmp/t
25+
RUN make -C /tmp/px install
26+
2027

2128
COPY examples/nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
2229
COPY examples/creds.json /tmp/creds.json

lib/px/block/pxblock.lua

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,26 @@ function M.load(px_config)
145145
local block_action = parse_action(ngx.ctx.px_action)
146146
px_logger.debug("Enforcing action: " .. block_action .. " page is served")
147147

148-
local html = px_template.get_template(ngx.ctx.px_action, details.block_uuid, vid)
149-
local collectorUrl = 'https://collector-' .. string.lower(px_config.px_appId) .. '.perimeterx.net'
150-
local result = {
151-
action = block_action,
152-
uuid = details.block_uuid,
153-
vid = vid,
154-
appId = px_config.px_appId,
155-
page = ngx.encode_base64(html),
156-
collectorUrl = collectorUrl
157-
}
148+
local status = ngx_HTTP_FORBIDDEN
149+
local result = {}
150+
if ngx.ctx.px_action == px_constants.RATE_LIMIT_ACTION then
151+
status = ngx_HTTP_TOO_MANY_REQUESTS
152+
else
153+
local html = px_template.get_template(ngx.ctx.px_action, details.block_uuid, vid)
154+
local collectorUrl = 'https://collector-' .. string.lower(px_config.px_appId) .. '.perimeterx.net'
155+
result = {
156+
action = block_action,
157+
uuid = details.block_uuid,
158+
vid = vid,
159+
appId = px_config.px_appId,
160+
page = ngx.encode_base64(html),
161+
collectorUrl = collectorUrl
162+
}
163+
164+
end
158165
append_cors_headers()
159166
ngx.header["Content-Type"] = 'application/json'
160-
ngx.status = ngx_HTTP_FORBIDDEN
167+
ngx.status = status
161168
ngx.say(cjson.encode(result))
162169
ngx_exit(ngx.OK)
163170
return
@@ -167,21 +174,27 @@ function M.load(px_config)
167174
local accept_header = px_common_utils.get_headers_single("accept") or px_common_utils.get_headers_single("content-type")
168175
local is_json_response = px_config.advanced_blocking_response and accept_header and is_accept_header_json(accept_header) and not ngx.ctx.px_is_mobile
169176
if is_json_response then
170-
local props = px_template.get_props(px_config, details.block_uuid, vid, parse_action(ngx.ctx.px_action))
171-
local result = {
172-
appId = props.appId,
173-
jsClientSrc = props.jsClientSrc,
174-
firstPartyEnabled = props.firstPartyEnabled,
175-
vid = props.vid,
176-
uuid = props.uuid,
177-
hostUrl = props.hostUrl,
178-
blockScript = props.blockScript,
179-
customLogo = px_config.customLogo,
180-
altBlockScript = props.altBlockScript
181-
}
177+
local status = ngx_HTTP_FORBIDDEN
178+
local result = {}
179+
if ngx.ctx.px_action == px_constants.RATE_LIMIT_ACTION then
180+
status = ngx_HTTP_TOO_MANY_REQUESTS
181+
else
182+
local props = px_template.get_props(px_config, details.block_uuid, vid, parse_action(ngx.ctx.px_action))
183+
result = {
184+
appId = props.appId,
185+
jsClientSrc = props.jsClientSrc,
186+
firstPartyEnabled = props.firstPartyEnabled,
187+
vid = props.vid,
188+
uuid = props.uuid,
189+
hostUrl = props.hostUrl,
190+
blockScript = props.blockScript,
191+
customLogo = px_config.customLogo,
192+
altBlockScript = props.altBlockScript
193+
}
194+
end
182195
append_cors_headers()
183196
ngx.header["Content-Type"] = 'application/json'
184-
ngx.status = ngx_HTTP_FORBIDDEN
197+
ngx.status = status
185198
ngx.say(cjson.encode(result))
186199
ngx_exit(ngx.OK)
187200
end
@@ -192,17 +205,14 @@ function M.load(px_config)
192205

193206
-- render advanced actions (js challange/rate limit)
194207
if ngx.ctx.px_action ~= 'c' and ngx.ctx.px_action ~= 'b' then
195-
-- default status code
196-
ngx.status = ngx_HTTP_FORBIDDEN
197208
local action_name = parse_action(ngx.ctx.px_action)
198-
local body = ngx.ctx.px_action_data or px_template.get_template(action_name, uuid, vid)
209+
local body = ngx.ctx.px_action_data or px_template.get_template(ngx.ctx.px_action, uuid, vid)
199210
px_logger.debug("Enforcing action: " .. action_name .. " page is served")
200-
201-
-- additional handling for actions (status codes, headers, etc)
202-
if ngx.ctx.px_action == 'r' then
203-
ngx.status = ngx_HTTP_TOO_MANY_REQUESTS
211+
local status = ngx_HTTP_FORBIDDEN
212+
if ngx.ctx.px_action == px_constants.RATE_LIMIT_ACTION then
213+
status = ngx_HTTP_TOO_MANY_REQUESTS
204214
end
205-
215+
ngx.status = status
206216
ngx_say(body)
207217
ngx_exit(ngx.OK)
208218
return

lib/px/block/pxtemplate.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,16 @@ function M.load(px_config)
102102

103103
local function get_content(action)
104104
local __dirname = get_path()
105+
106+
-- for Captcha Action
105107
local path = 'block_template'
106-
if action == 'ratelimit' then
108+
109+
if action == px_constants.RATE_LIMIT_ACTION then
107110
path = 'ratelimit'
108111
elseif action == px_constants.HSC_BLOCK_ACTION then
109112
path = 'hypesale_template'
110113
end
114+
111115
local template_path = string.format("%stemplates/%s.mustache", __dirname, path)
112116

113117
px_logger.debug("fetching template from: " .. template_path)

lib/px/utils/pxconstants.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
----------------------------------------------
44

55
local _M = {
6-
MODULE_VERSION = "NGINX Module v7.3.2",
6+
MODULE_VERSION = "NGINX Module v7.3.3",
77
RISK_PATH = "/api/v3/risk",
88
CAPTCHA_PATH = "/api/v2/risk/captcha",
99
ACTIVITIES_PATH = "/api/v1/collector/s2s",
@@ -20,6 +20,7 @@ local _M = {
2020
HSC_BLOCK_ACTION = 'hsc',
2121
HSC_DRC_PROPERTY = 7190,
2222
HSC_BLOCK_TYPE = 'pxHypeSaleChallenge',
23+
RATE_LIMIT_ACTION = 'r',
2324
GRAPHQL_PATH = "/graphql",
2425
GRAPHQL_QUERY = "query",
2526
GRAPHQL_MUTATION = "mutation",

perimeterx-nginx-plugin-7.3.2-1.rockspec renamed to perimeterx-nginx-plugin-7.3.3-1.rockspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package = "perimeterx-nginx-plugin"
2-
version = "7.3.2-1"
2+
version = "7.3.3-1"
33
source = {
44
url = "git+https://github.com/PerimeterX/perimeterx-nginx-plugin.git",
5-
tag = "v7.3.2",
5+
tag = "v7.3.3",
66
}
77
description = {
88
summary = "PerimeterX NGINX Lua Middleware.",

px_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"module_name" : "NGINX Module",
3-
"version": "7.3.2",
3+
"version": "7.3.3",
44
"spec_version" : "1.0.0",
55
"supported_features": [
66
"advanced_blocking_response",

0 commit comments

Comments
 (0)