Added nonce generator for CSP header

This commit is contained in:
斟酌 鵬兄 2022-04-09 20:41:30 +08:00
parent 7111ecd32c
commit ce1b9b3a0e

7
api.js
View File

@ -10,6 +10,7 @@ var conf = cl.load( "config.all" ).botanjs;
var Session = cl.load( "botansx.modular.session" ); var Session = cl.load( "botansx.modular.session" );
var hash = cl.load( "botansx.utils.hash" ); var hash = cl.load( "botansx.utils.hash" );
var rand = cl.load( "botansx.utils.random" );
var BotanJS = function() var BotanJS = function()
{ {
@ -17,6 +18,7 @@ var BotanJS = function()
this.sv = {}; this.sv = {};
this.kv = {}; this.kv = {};
this.embed = {}; this.embed = {};
this._nonce = {};
}; };
util.inherits( BotanJS, events.EventEmitter ); util.inherits( BotanJS, events.EventEmitter );
@ -66,6 +68,11 @@ BotanJS.prototype.storeForRender = function( rainet, type, ch )
} }
}; };
BotanJS.prototype.nonce = function( type )
{
return ( this._nonce[ type ] ||= rand.randstr( 8 ) );
};
BotanJS.prototype.compile = function( type ) BotanJS.prototype.compile = function( type )
{ {
var _self = this; var _self = this;