@blaasvaer/frmwrk 0.3.3 → 0.3.6
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 +1 -1
- 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
|
@@ -130,7 +130,7 @@ console.log("Authorize - check credentials:", credentials);
|
|
|
130
130
|
* Create and start the server
|
|
131
131
|
* @return {function} Server instance
|
|
132
132
|
*/
|
|
133
|
-
http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
133
|
+
const server = http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
134
134
|
console.log(`Server running at http://${hostname}:${port}`);
|
|
135
135
|
});
|
|
136
136
|
|