Home  >  Q&A  >  body text

Ask about a filtering rule for nginx

Need to filter out some illegal characters in the server url:

For example | ; $ @ ' " < > ( ) document LF

Because all locations are required, they are written under the server:

if ($request_uri ~* "##这里怎么写##"){
    return 403;
}

I am a novice, please give me some guidance. . . .

大家讲道理大家讲道理2713 days ago583

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-16 17:23:23

    It is recommended to write the single-character blacklist and multi-character blacklist in two sections
    Single-character blacklist:

    if ( $request_uri ~ [|;$@'"<>()] ) {
        return 403;
        }
    

    Multiple characters:

    if ( $request_uri ~ (document|LF) {
        return 403;
        }

    reply
    0
  • 迷茫

    迷茫2017-05-16 17:23:23

    The question should be written more clearly

    reply
    0
  • Cancelreply