@@ -5,7 +5,6 @@ import SessionManager from './../session-manager';
55import { wrapListener } from '../utils/shimer' ;
66import { Logger } from '../logger' ;
77import Hook from 'require-in-the-middle' ;
8- import { wrap } from 'shimmer' ;
98import ActionsList from './../actions-list' ;
109import { clientIpFromRequest } from './../utils/utils' ;
1110import { SecureNativeOptions } from '../types/securenative-options' ;
@@ -14,9 +13,9 @@ import SetType from '../enums/set-type';
1413import { v4 } from 'uuid' ;
1514import ApiManager from '../api-manager' ;
1615
17- export default class HttpsServerInterceptor extends Interceptor implements IInterceptor {
16+ export default class HttpServerInterceptor extends Interceptor implements IInterceptor {
1817 private name = 'https-server' ;
19-
18+
2019 constructor ( private moduleManger : ModuleManager , private apiManager : ApiManager , private options : SecureNativeOptions ) {
2120 super ( ) ;
2221 }
@@ -39,62 +38,25 @@ export default class HttpsServerInterceptor extends Interceptor implements IInte
3938 wrapListener ( exports . Server . prototype , 'emit' , 'request' , ( event , req , res ) => {
4039 const snuid = v4 ( ) ;
4140 SessionManager . setSession ( snuid , { req, res } ) ;
42-
41+ if ( req . method === 'OPTIONS' ) {
42+ return true ;
43+ }
4344 const url = req . url ;
4445 const clientIp = clientIpFromRequest ( req ) ;
4546 const deviceFP = getDeviceFp ( req , this . options ) ;
4647
47- if ( ActionsList . whitelist . has ( SetType . IP , clientIp ) || ActionsList . whitelist . has ( SetType . USER , deviceFP ) || ActionsList . whitelist . has ( SetType . PATH , url ) ) {
48+ if (
49+ ActionsList . whitelist . has ( SetType . IP , clientIp ) ||
50+ ActionsList . whitelist . has ( SetType . USER , deviceFP ) ||
51+ ActionsList . whitelist . has ( SetType . PATH , url )
52+ ) {
4853 req . sn_whitelisted = true ;
4954 } else if ( ActionsList . blackList . has ( SetType . IP , clientIp ) || ActionsList . blackList . has ( SetType . USER , deviceFP ) ) {
50- req . sn_finished = true ;
51- super . intercept ( snuid , 'blockRequest' ) ;
52- return false ;
55+ super . intercept ( snuid , 'block' ) ;
5356 }
54-
5557 return true ;
5658 } ) ;
5759
58- wrap ( exports && exports . ServerResponse && exports . ServerResponse . prototype , 'setHeader' , function ( original ) {
59- return function ( ) {
60- if ( this . sn_finished ) {
61- return ;
62- }
63- return original . apply ( this , arguments ) ;
64- } ;
65- } ) ;
66-
67-
68- wrap ( exports && exports . ServerResponse && exports . ServerResponse . prototype , 'writeHead' , function ( original ) {
69- return function ( ) {
70- if ( this . sn_finished ) {
71- return ;
72- }
73- return original . apply ( this , arguments ) ;
74- } ;
75- } ) ;
76-
77- wrap ( exports && exports . ServerResponse && exports . ServerResponse . prototype , 'write' , ( original ) => {
78- const intercept = super . intercept . bind ( this ) ;
79- return function ( ) {
80- if ( this . sn_finished ) {
81- return ;
82- }
83- intercept ( this . sn_uid , 'write' ) ;
84- return original . apply ( this , arguments ) ;
85- } ;
86- } ) ;
87-
88- wrap ( exports && exports . ServerResponse && exports . ServerResponse . prototype , 'end' , function ( original ) {
89- return function ( ) {
90- SessionManager . cleanSession ( this . req . sn_uid ) ;
91- if ( this . sn_finished ) {
92- return ;
93- }
94- return original . apply ( this , arguments ) ;
95- }
96- } ) ;
97-
9860 return exports ;
9961 } ) ;
10062 }
0 commit comments