@blaasvaer/frmwrk 0.3.4 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handle-request.js +13 -1
- package/index.js +26 -3
- package/package.json +1 -1
package/handle-request.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const crypto = require('crypto');
|
|
4
5
|
const path = require('path');
|
|
5
6
|
const statics = require('serve-handler');
|
|
6
7
|
const { findRoute } = require('./router');
|
|
@@ -11,6 +12,15 @@ const content_types = {
|
|
|
11
12
|
"json" : 'application/json; charset=utf-8'
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Generate a secure session id
|
|
17
|
+
* @returns string
|
|
18
|
+
*/
|
|
19
|
+
function generateSecureSessionID () {
|
|
20
|
+
// Use 32 bytes (64 hex characters) for high security
|
|
21
|
+
return crypto.randomBytes(32).toString('hex');
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
/**
|
|
15
25
|
* Handle incoming request
|
|
16
26
|
* @param {Object} req The incoming request object
|
|
@@ -127,7 +137,9 @@ async function handleRequest( req, res ) {
|
|
|
127
137
|
// res.setHeader( 'Content-Security-Policy', "default-src 'self'; img-src 'self';");
|
|
128
138
|
|
|
129
139
|
// Cookies
|
|
130
|
-
|
|
140
|
+
const secureSessionId = generateSecureSessionID();
|
|
141
|
+
// res.setHeader('Set-Cookie','uuid=1234-1324-1234-1234-1234; Max-Age=3000; SameSite=lax; Secure');
|
|
142
|
+
res.setHeader('Set-Cookie',`SESSIONID=${secureSessionId}; Max-Age=3000; SameSite=lax; Secure`);
|
|
131
143
|
// Set a same-site cookie for first-party contexts
|
|
132
144
|
// res.cookie('cookie1', 'value1', { sameSite: 'lax' });
|
|
133
145
|
// Set a cross-site cookie for third-party contexts
|
package/index.js
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Native modules
|
|
11
11
|
*/
|
|
12
|
+
const fs = require('fs');
|
|
12
13
|
const http = require('http');
|
|
14
|
+
const https = require('https');
|
|
13
15
|
const { Server } = require('socket.io');
|
|
14
16
|
|
|
15
17
|
let port;
|
|
@@ -122,6 +124,8 @@ console.log("Authorize - check credentials:", credentials);
|
|
|
122
124
|
*/
|
|
123
125
|
Install( config )
|
|
124
126
|
.then(( result ) => {
|
|
127
|
+
let server;
|
|
128
|
+
|
|
125
129
|
/**
|
|
126
130
|
* Run optional post install processes here …
|
|
127
131
|
*/
|
|
@@ -130,9 +134,28 @@ console.log("Authorize - check credentials:", credentials);
|
|
|
130
134
|
* Create and start the server
|
|
131
135
|
* @return {function} Server instance
|
|
132
136
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
if ( config.protocol === 'https' ) {
|
|
138
|
+
/**
|
|
139
|
+
* SSL Configurations options
|
|
140
|
+
* These paths should be provided in your framework's config object
|
|
141
|
+
*/
|
|
142
|
+
const sslOptions = {
|
|
143
|
+
key: fs.readFileSync(config.sslKeyPath || './certs/key.pem'),
|
|
144
|
+
cert: fs.readFileSync(config.sslCertPath || './certs/cert.pem')
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create and start the secure server
|
|
149
|
+
* @return {function} Server instance
|
|
150
|
+
*/
|
|
151
|
+
server = https.createServer( sslOptions, handleRequest ).listen(port, hostname, () => {
|
|
152
|
+
console.log(`Server running at https://${hostname}:${port}`);
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
server = http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
156
|
+
console.log(`Server running at http://${hostname}:${port}`);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
136
159
|
|
|
137
160
|
if ( config.enable_socket_io ) {
|
|
138
161
|
_io = new Server( server );
|