secan
v0.1.9
Published
A frontend security checklist
Maintainers
Readme
secan
Tools for protecting your javascript code in browser.
Installation
$ npm i -P secanUsage
import secan from 'secan';
secan({
debuggerLoop: true
});
window.addEventListener('devtoolsopen', () => {
console.log('What are you doing now?');
// when you open devtools, this event will be emitted and you will get a debugger and a debugger...
});Options
interval(number) By default, secan will perform a check every 3 seconds, this option can specify another valuedebug(booleanorstring) 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.topto 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 hookevalconsolealert, 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 behttpnothttpsand secan can detect then emit a eventwindow.addEventListener('sslstrip')allowInlineScript(boolean) Defaulttrue, secan will check all<script>, ifsrcof<script>not inscriptDomain, secan will emit a eventwindow.addEventListener('invalidscript'), ifallowInlineScriptistrue, secan will also emit this eventscriptDomain(stringorstring[]) 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')IfhookFnistrue, this event will be emitted whenevalcalled, and theevent.detail.argscan get the arguments of this callwindow.addEventListener('console')IfhookFnistrue, this event will be emitted whenconsole[<method>]called, and theevent.detail.argscan get the arguments of this callwindow.addEventListener('alert')IfhookFnistrue, this event will be emitted whenalertcalled, and theevent.detail.argscan get the arguments of this callwindow.addEventListener('invaliddomain')IfpageDomainset, and domain of current page is notpageDomain, this event will be emitted, and theevent.detail.urlcan 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>, ifsrcof<script>not inscriptDomain, this event will be emittedwindow.addEventListener('devtoolsopen')If secan detected that devtools is open, this event will be emitted
