summaryrefslogtreecommitdiff
path: root/xss-nginx-module-0.06/src/ngx_http_xss_util.rl
blob: 27def77511f1177654ae1fe981adf44ad5906fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright (C) agentzh
 */


#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"

#include "ngx_http_xss_util.h"


%% machine javascript;
%% write data;

ngx_int_t ngx_http_xss_test_callback(u_char *data, size_t len)
{
    signed char *p = (signed char *) data;
    signed char *pe;
    int cs;

    pe = p + len;

    %%{
        identifier = [$A-Za-z_] [$A-Za-z0-9_]*;

        index = [0-9]* '.' [0-9]+
              | [0-9]+
              ;

        main := identifier ( '.' identifier )*
                  ('[' index ']')? ;

        write init;
        write exec;
    }%%

    if (cs < %%{ write first_final; }%% || p != pe) {
        return NGX_DECLINED;
    }

    return NGX_OK;
}