Quais são os limites da PCRE?

11

No ModSecurity, há PCRE limits exceeded erros.

Eu sei que posso consertar isso definindo regras como:

SecPcreMatchLimit 150000
SecPcreMatchLimitRecursion 150000

Mas o que essas regras estão realmente fazendo? O que o limite de recursão PCRE definido como 150.000 significa? Quais buracos de segurança estou permitindo, definindo-os tão alto? O que significa recursion e limit ?

Eu sei que há documentação, mas a documentação não me diz o que está acontecendo, simplesmente me diz como trabalhar com as diretivas.

    
por user1529891 16.07.2012 / 21:36

1 resposta

13

Estas parecem ser configurações internas do mecanismo PCRE para limitar a quantidade máxima de memória / tempo gasto na tentativa de combinar algum texto com um padrão. A% man_de% página de manual faz pouco para explicar em termos leigos:

The match_limit field provides a means of preventing PCRE from using up a vast amount of resources when running patterns that are not going to match, but which have a very large number of possibilities in their search trees. The classic example is the use of nested unlimited repeats.

Internally, PCRE uses a function called match() which it calls repeatedly (sometimes recursively). The limit set by match_limit is imposed on the number of times this function is called during a match, which has the effect of limiting the amount of backtracking that can take place. For patterns that are not anchored, the count restarts from zero for each position in the subject string.

The default value for the limit can be set when PCRE is built; the default default is 10 million, which handles all but the most extreme cases. You can override the default by suppling pcre_exec() with a pcre_extra block in which match_limit is set, and PCRE_EXTRA_MATCH_LIMIT is set in the flags field. If the limit is exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.

The match_limit_recursion field is similar to match_limit, but instead of limiting the total number of times that match() is called, it limits the depth of recursion. The recursion depth is a smaller number than the total number of calls, because not all calls to match() are recursive. This limit is of use only if it is set smaller than match_limit.

Como o padrão padrão da biblioteca PCRE é 10000000, meu palpite é que a configuração mais baixa seja sugerida para o mod_security, a fim de evitar que as solicitações sejam retidas por um longo tempo.

    
por 16.07.2012 / 22:11