secan
Tools for protecting your javascript code in browser.
Installation
$ npm i -P secan
Usage
;;window;
Options
interval
(number
) By default, secan will perform a check every 3 seconds, this option can specify another valuedebug
(boolean
orstring
) Iftrue
, secan will not perform check, it is useful in development environment. If a string, for example,debug: '__debug__'
when the URL of current page has a query string such as?__debug__=1
, secan will not perform check, it's a backdoor in production environment...breakIframe
(boolean
) Iftrue
, when current page in a<iframe>
, secan will redirectwindow.top
to current page, defaulttrue
. But you still need to set a headerX-Frame-Options
, see MDN, this is the right waydebuggerLoop
(boolean
) When secan detected the devtools open, secan will start a debugger loop to interfere debugginghookFn
(boolean
) Iftrue
, secan will hookeval
console
alert
, and when these method called, secan will emitwindow.addEventListener('eval')
,window.addEventListener('console')
andwindow.addEventListener('alert')
, if someone perform a XSS test, this may be usefulbaitURL
(string
) Must be a URL start withhttps
, when sslstrip occurred, this URL will behttp
nothttps
and secan can detect then emit a eventwindow.addEventListener('sslstrip')
allowInlineScript
(boolean
) Defaulttrue
, secan will check all<script>
, ifsrc
of<script>
not inscriptDomain
, secan will emit a eventwindow.addEventListener('invalidscript')
, ifallowInlineScript
istrue
, secan will also emit this eventscriptDomain
(string
orstring[]
) A domain whitelist of<script>
src, if a src of<script>
not inscriptDomain
, secan will emit a eventwindow.addEventListener('invalidscript')
pageDomain
(string
) If current domain is notpageDomain
, secan will emit a eventwindow.addEventListener('invaliddomain')
Events
window.addEventListener('eval')
IfhookFn
istrue
, this event will be emitted wheneval
called, and theevent.detail.args
can get the arguments of this callwindow.addEventListener('console')
IfhookFn
istrue
, this event will be emitted whenconsole[<method>]
called, and theevent.detail.args
can get the arguments of this callwindow.addEventListener('alert')
IfhookFn
istrue
, this event will be emitted whenalert
called, and theevent.detail.args
can get the arguments of this callwindow.addEventListener('invaliddomain')
IfpageDomain
set, and domain of current page is notpageDomain
, this event will be emitted, and theevent.detail.url
can get the URL of current pagewindow.addEventListener('sslbreak')
If the URL of current page is not HTTPS, this event will be emittedwindow.addEventListener('sslstrip')
If secan detected sslstrip, this event will be emittedwindow.addEventListener('iniframe')
If secan detected that current page is in a<iframe>
, this event will be emittedwindow.addEventListener('headlessbrowser')
If secan detected that current page is in a headless browser, such as puppeteer or phantomJS, this event will be emittedwindow.addEventListener('invalidscript')
Secan will check all<script>
, ifsrc
of<script>
not inscriptDomain
, this event will be emittedwindow.addEventListener('devtoolsopen')
If secan detected that devtools is open, this event will be emitted