Skip to content

Commit b4e6607

Browse files
authored
fix: false positives when editing global styles in gutenberg (#50)
* fix: false positives when editing global styles in gutenberg * fix: case sensitive content type header in tests
1 parent ab0ee24 commit b4e6607

File tree

6 files changed

+66
-8
lines changed

6 files changed

+66
-8
lines changed

Diff for: plugins/wordpress-rule-exclusions-before.conf

+15-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ SecRule REQUEST_FILENAME "@endsWith /wp-admin/admin-ajax.php" \
130130
# Used when a user (auto)saves a post/page with Gutenberg.
131131
#
132132

133+
# Editing global styles for a theme (colors, fonts, etc)
134+
SecRule REQUEST_FILENAME "@rx /wp-json/wp/v[0-9]/global-styles/[0-9]+$" \
135+
"id:9507139,\
136+
phase:1,\
137+
pass,\
138+
t:none,\
139+
nolog,\
140+
ctl:ruleRemoveTargetById=942100;ARGS,\
141+
ctl:ruleRemoveTargetById=942430;ARGS,\
142+
ctl:ruleRemoveTargetById=942431;ARGS,\
143+
ctl:ruleRemoveTargetById=942432;ARGS,\
144+
ctl:ruleRemoveTargetById=942440;ARGS,\
145+
ver:'wordpress-rule-exclusions-plugin/1.0.1'"
146+
133147
# Gutenberg
134148
SecRule REQUEST_FILENAME "@rx /wp-json/wp/v[0-9]+/(?:navigation|pages|posts|template-parts|templates)" \
135149
"id:9507140,\
@@ -230,7 +244,7 @@ SecRule REQUEST_FILENAME "@endsWith /index.php" \
230244
ctl:ruleRemoveTargetById=942100;ARGS"
231245

232246
# Cannot update page|post in WordPress due to `x-http-method-override` header.
233-
SecRule REQUEST_FILENAME "@rx /wp-json/wp/v[0-9]+/(?:navigation|pages|posts|template-parts|templates|users)" \
247+
SecRule REQUEST_FILENAME "@rx /wp-json/wp/v[0-9]+/(?:global-styles|navigation|pages|posts|template-parts|templates|users)" \
234248
"id:9507146,\
235249
phase:1,\
236250
pass,\
@@ -348,8 +362,6 @@ SecRule ARGS:wp_customize "@streq on" \
348362
ctl:ruleRemoveTargetById=942431;ARGS:partials,\
349363
ctl:ruleRemoveTargetById=942460;ARGS:partials"
350364

351-
352-
353365
# Self calls to wp-cron.php?doing_wp_cron=[timestamp]
354366
# These requests may be missing Accept, Content-Length headers.
355367
# This rule must run in phase:1.

Diff for: tests/regression/wordpress-rule-exclusions-plugin/9507100.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tests:
2121
uri: /post/wp-login.php?pwd=<script>
2222
output:
2323
no_log_contains: |
24-
id "932236" | id "941110"
24+
id "932236"|id "941110"
2525
- test_title: 9507100-2
2626
desc: ARGS:redirect_to tends to contain multiple special characters since it'll include the redirect URL
2727
stages:
@@ -38,4 +38,4 @@ tests:
3838
uri: /post/wp-login.php?redirect_to=;;;;;;;;;;;;
3939
output:
4040
no_log_contains: |
41-
id "942430" | id "942431" | id "942432"
41+
id "942430"|id "942431"|id "942432"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
meta:
3+
author: "Esad Cetiner"
4+
description: "Wordpress Rule Exclusions Plugin"
5+
enabled: true
6+
name: 9507139.yaml
7+
tests:
8+
- test_title: 9507139-1
9+
desc: Editing global styles for a theme
10+
stages:
11+
- stage:
12+
input:
13+
dest_addr: 127.0.0.1
14+
headers:
15+
Host: localhost
16+
User-Agent: OWASP CRS test agent
17+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
18+
Content-Type: application/json
19+
x-http-method-override: PUT
20+
port: 80
21+
method: POST
22+
version: "HTTP/1.1"
23+
uri: /post/wp-json/wp/v2/global-styles/1?wp_theme_preview=twentytwentyfour&_locale=user
24+
data: |
25+
{"id":2934,"styles":{"blocks":{"core/site-title":{"typography":{"fontWeight":"400"}},"core/pullquote":{"typography":{"fontSize":"var(--wp--preset--font-size--large)","fontStyle":"normal","fontWeight":"normal","lineHeight":"1.2"}},"core/quote":{"variations":{"plain":{"typography":{"fontStyle":"normal","fontWeight":"400"}}},"typography":{"fontFamily":"var(--wp--preset--font-family--heading)","fontSize":"var(--wp--preset--font-size--large)","fontStyle":"normal"}},"core/navigation":{"typography":{"fontWeight":"400"}}},"elements":{"button":{"typography":{"fontFamily":"var(--wp--preset--font-family--heading)","fontSize":"var(--wp--preset--font-size--small)","fontStyle":"normal"}},"heading":{"color":{"background":"#ab5a5a"}}},"css":""}}
26+
no_log_contains: |
27+
id "942100|id "942440"

Diff for: tests/regression/wordpress-rule-exclusions-plugin/9507140.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ tests:
2727
{"id":"twentytwentyfour//header","content":"<!-- wp:group{\"align\":\"wide\",\"style\":{\"spacing\":{\"padding\":{\"top\":\"20px\",\"bottom\":\"20px\"}}},\"backgroundColor\":\"base\",\"layout\":{\"type\":\"constrained\"}} -->\n<div class=\"wp-block-groupalignwide has-base-background-color has-background\" style=\"padding-top:20px;padding-bottom:20px\"><!-- wp:group{\"align\":\"wide\",\"layout\":{\"type\":\"flex\",\"justifyContent\":\"space-between\",\"flexWrap\":\"wrap\"}} -->\n<div class=\"wp-block-group alignwide\"><!-- wp:group{\"style\":{\"spacing\":{\"blockGap\":\"var:preset|spacing|20\"},\"layout\":{\"selfStretch\":\"fit\",\"flexSize\":null}},\"layout\":{\"type\":\"flex\"}} -->\n<div class=\"wp-block-group\">
2828
<!-- wp:site-logo{\"width\":60,\"shouldSyncIcon\":false} /-->\n\n<!-- wp:group {\"style\":{\"spacing\":{\"blockGap\":\"0px\"}}} -->\n<div class=\"wp-block-group\"><!-- wp:site-title {\"level\":0} /--></div>\n<!-- /wp:group--></div>\n<!-- /wp:group -->\n\n<!-- wp:navigation{\"ref\":2180,\"icon\":\"menu\",\"layout\":{\"type\":\"flex\",\"justifyContent\":\"right\",\"orientation\":\"horizontal\",\"flexWrap\":\"wrap\"},\"style\":{\"spacing\":{\"margin\":{\"top\":\"0\"},\"blockGap\":\"va>/--></div>\n<!-- /wp:group -->\n\n<!-- wp:paragraph -->\n<p></p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:group -->"}
2929
no_log_contains: |
30-
id "932240" | id "932236" | id "941100" | id "941150" | id "941160" | id "941180" | id "941181" | id "941320" | id "942210" | id "942330" | id "942340" | id "942370" | id "942430" | id "942431" | id "942432" | id "942440" | id "942520"
30+
id "932240"|id "932236"|id "941100"|id "941150"|id "941160"|id "941180"|id "941181"|id "941320"|id "942210"|id "942330"|id "942340"|id "942370"|id "942430"|id "942431"|id "942432"|id "942440"|id "942520"

Diff for: tests/regression/wordpress-rule-exclusions-plugin/9507146.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,22 @@ tests:
2727
{"id":"twentytwentyfour//header","content":"<!-- wp:group{\"align\":\"wide\",\"style\":{\"spacing\":{\"padding\":{\"top\":\"20px\",\"bottom\":\"20px\"}}},\"backgroundColor\":\"base\",\"layout\":{\"type\":\"constrained\"}} -->\n<div class=\"wp-block-groupalignwide has-base-background-color has-background\" style=\"padding-top:20px;padding-bottom:20px\"><!-- wp:group{\"align\":\"wide\",\"layout\":{\"type\":\"flex\",\"justifyContent\":\"space-between\",\"flexWrap\":\"wrap\"}} -->\n<div class=\"wp-block-group alignwide\"><!-- wp:group{\"style\":{\"spacing\":{\"blockGap\":\"var:preset|spacing|20\"},\"layout\":{\"selfStretch\":\"fit\",\"flexSize\":null}},\"layout\":{\"type\":\"flex\"}} -->\n<div class=\"wp-block-group\">
2828
<!-- wp:site-logo{\"width\":60,\"shouldSyncIcon\":false} /-->\n\n<!-- wp:group {\"style\":{\"spacing\":{\"blockGap\":\"0px\"}}} -->\n<div class=\"wp-block-group\"><!-- wp:site-title {\"level\":0} /--></div>\n<!-- /wp:group--></div>\n<!-- /wp:group -->\n\n<!-- wp:navigation{\"ref\":2180,\"icon\":\"menu\",\"layout\":{\"type\":\"flex\",\"justifyContent\":\"right\",\"orientation\":\"horizontal\",\"flexWrap\":\"wrap\"},\"style\":{\"spacing\":{\"margin\":{\"top\":\"0\"},\"blockGap\":\"va>/--></div>\n<!-- /wp:group -->\n\n<!-- wp:paragraph -->\n<p></p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:group -->"}
2929
no_log_contains: id "920450"
30+
- test_title: 9507146-2
31+
desc: Editing global styles for a theme
32+
stages:
33+
- stage:
34+
input:
35+
dest_addr: 127.0.0.1
36+
headers:
37+
Host: localhost
38+
User-Agent: OWASP CRS test agent
39+
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
40+
Content-Type: application/json
41+
x-http-method-override: PUT
42+
port: 80
43+
method: POST
44+
version: "HTTP/1.1"
45+
uri: /post/wp-json/wp/v2/global-styles/1?wp_theme_preview=twentytwentyfour&_locale=user
46+
data: |
47+
{"id":2934,"styles":{"blocks":{"core/site-title":{"typography":{"fontWeight":"400"}},"core/pullquote":{"typography":{"fontSize":"var(--wp--preset--font-size--large)","fontStyle":"normal","fontWeight":"normal","lineHeight":"1.2"}},"core/quote":{"variations":{"plain":{"typography":{"fontStyle":"normal","fontWeight":"400"}}},"typography":{"fontFamily":"var(--wp--preset--font-family--heading)","fontSize":"var(--wp--preset--font-size--large)","fontStyle":"normal"}},"core/navigation":{"typography":{"fontWeight":"400"}}},"elements":{"button":{"typography":{"fontFamily":"var(--wp--preset--font-family--heading)","fontSize":"var(--wp--preset--font-size--small)","fontStyle":"normal"}},"heading":{"color":{"background":"#ab5a5a"}}},"css":""}}
48+
no_log_contains: id "920450"

Diff for: tests/regression/wordpress-rule-exclusions-plugin/9507350.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ tests:
3131
Host: localhost
3232
User-Agent: OWASP CRS test agent
3333
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
34-
content-type: application/x-www-form-urlencoded
34+
Content-Type: application/x-www-form-urlencoded
3535
port: 80
3636
method: POST
3737
version: "HTTP/1.1"
3838
uri: /post/wp-admin/users.php?s=&_wpnonce=random&_wp_http_referer=%2Fwp-admin%2Fusers.php&action=delete&new_role=&paged=1&users%5B0%5D=9&action2=delete&new_role2=
3939
output:
4040
no_log_contains: |
41-
id "920230" | id "942430" | id "942431" | id "942432"
41+
id "920230"|id "942430"|id "942431"|id "942432"
4242
- test_title: 9507350-3
4343
desc: Disable 932236 for randomly generated nonce
4444
stages:

0 commit comments

Comments
 (0)