Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Add urlDecodeUni() operation to ARG/ARGS_NAMES #578

Merged
merged 1 commit into from
Sep 19, 2016

Conversation

csjperon
Copy link
Contributor

@csjperon csjperon commented Sep 15, 2016

  • Add the urlDecodeUni transform operation to rules which inspect the
    ARGS/ARGS_NAMES collections, which do not currently call urlDecodeUni
  • This operation should be here. Some rules were written under the assumption
    that Apache/Nginx will automatically decode these collections prior to
    entering Modsecurity.
  • This change shouldn't impact the rule quality, but will introduce additional decoding overhead

I am creating this PR to start the discussion

Thoughts?

- Add the urlDecodeUni transform operation to rules which inspect the
  ARGS/ARGS_NAMES collections, which do not currently call urlDecodeUni
- This operation should be here.  Some rules were written under the assumption
  that Apache/Nginx will automatically decode these collections prior to
  entering Modsecurity.
- This change should be a NO-OP for Apache/Nginx
@csanders-git
Copy link
Contributor

it isn't a NOP but is an extra transformation which is additional overhead - but saying as others use these rules it might be advisable.

@dune73
Copy link
Contributor

dune73 commented Sep 16, 2016

This is a welcome fix.

I do not see it applied everywhere, though. How about the following rules?

  • 913120
  • 920230
  • 921170
  • 931100
  • 931120
  • 931130
  • 932100
  • 932110
  • 932150
  • 933140
  • 933150
  • 933160
  • 933170
  • 933180
  • 933151
  • 933161

Am I missing something?

@csjperon
Copy link
Contributor Author

@dune73 No, I was missing something :) I will update the PR shortly

@csjperon
Copy link
Contributor Author

So after running the tests, this change will create a regression in 920230:

SecRule ARGS "\%((?!$|\W)|[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})" \
  "phase:request,\
   rev:'2',\
   ver:'OWASP_CRS/3.0.0',\
   maturity:'6',\
   accuracy:'8',\
   t:none,\
   block,\
   msg:'Multiple URL Encoding Detected',\
   id:920230,\
   tag:'application-multi',\
   tag:'language-multi',\
   tag:'platform-multi',\
   tag:'attack-protocol',\
   tag:'OWASP_CRS/PROTOCOL_VIOLATION/EVASION',\
   tag:'paranoia-level/2',\
   severity:'WARNING',\
   setvar:'tx.msg=%{rule.msg}',\
   setvar:tx.anomaly_score=+%{tx.warning_anomaly_score},\
   setvar:tx.%{rule.id}-OWASP_CRS/PROTOCOL_VIOLATION/EVASION-%{matched_var_name}=%{matched_var}"

So perhaps we shouldn't enable it here? The rest of the tests were not impacted.

Thoughts?

@dune73
Copy link
Contributor

dune73 commented Sep 16, 2016

Thank you for the update. Are you positive, that all necessary rules have the transformation now? My comment was written after a quick glance over the ruleset.

I see why there would be a regression with this rule. It's an encoding check, after all. Maybe the regex needs to be adopted.

Are you understanding the regex and can you try and fix it?

If that is not possible, we need a comment next to the rule why the transformation is not being applied.

@csjperon
Copy link
Contributor Author

csjperon commented Sep 16, 2016

Yes, I think this rule requires utftounicode() actually, since the rule is looking for the same pattern that would be returned as a result of that transform function [u[0-9a-fA-F]{4}] (basically implying that raw unicode characters were present in the ARGS strings. I will look into it in more detail though. There are a few issues reported with that function too:

https://github.com/SpiderLabs/ModSecurity/issues/created_by/katef

@dune73 dune73 merged commit 73805dc into SpiderLabs:v3.0.0-rc2 Sep 19, 2016
@csjperon csjperon deleted the v3.0.0-rc2 branch September 22, 2016 21:18
fgsch added a commit to fgsch/coreruleset-old that referenced this pull request Oct 31, 2019
Stop decoding things twice. See SpiderLabs#590 for details.
fgsch added a commit to fgsch/coreruleset-old that referenced this pull request Dec 3, 2019
Stop decoding things twice. See SpiderLabs#590 for details.
fgsch added a commit to fgsch/coreruleset-old that referenced this pull request Dec 4, 2019
Stop decoding things twice. See SpiderLabs#590 for details.
fgsch added a commit to fgsch/coreruleset-old that referenced this pull request Dec 12, 2019
Stop decoding things twice. See SpiderLabs#590 for details.
fgsch added a commit to fgsch/coreruleset-old that referenced this pull request Jan 6, 2020
Stop decoding things twice. See SpiderLabs#590 for details.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants