primate 0.5.1 → 0.5.2
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/package.json +1 -1
- package/source/preset/primate.json +9 -1
- package/source/preset/{data/stores → stores}/default.js +0 -0
- package/source/server/App.js +1 -0
- package/source/server/Session.js +1 -1
- package/source/server/domain/Domain.js +1 -1
- package/source/server/servers/Static.js +6 -7
- package/source/server/store/Store.js +1 -1
- package/source/server/servers/content-security-policy.json +0 -7
package/package.json
CHANGED
|
@@ -13,7 +13,15 @@
|
|
|
13
13
|
"ssl": {
|
|
14
14
|
"key": "ssl/default.key",
|
|
15
15
|
"cert": "ssl/default.crt"
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"csp": {
|
|
18
|
+
"default-src": "'self'",
|
|
19
|
+
"object-src": "'none'",
|
|
20
|
+
"frame-ancestors": "'none'",
|
|
21
|
+
"form-action": "'self'",
|
|
22
|
+
"base-uri": "'self'"
|
|
23
|
+
},
|
|
24
|
+
"same-site": "Strict"
|
|
17
25
|
},
|
|
18
26
|
"paths": {
|
|
19
27
|
"client": "client",
|
|
File without changes
|
package/source/server/App.js
CHANGED
|
@@ -36,6 +36,7 @@ export default class App {
|
|
|
36
36
|
const conf = {index, hashes, router,
|
|
37
37
|
"serve_from": this.conf.paths.public,
|
|
38
38
|
"http": {
|
|
39
|
+
...this.conf.http,
|
|
39
40
|
"key": File.read_sync(resolve(this.conf.http.ssl.key)),
|
|
40
41
|
"cert": File.read_sync(resolve(this.conf.http.ssl.cert)),
|
|
41
42
|
},
|
package/source/server/Session.js
CHANGED
|
@@ -31,7 +31,7 @@ export default class Session extends Domain {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
get cookie() {
|
|
34
|
-
return `session_id=${this._id}; Secure;
|
|
34
|
+
return `session_id=${this._id}; Path=/; Secure; HttpOnly`;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async switch_context(context, data = {}) {
|
|
@@ -7,18 +7,13 @@ import Server from "./Server.js";
|
|
|
7
7
|
import Session from "../Session.js";
|
|
8
8
|
import File from "../File.js";
|
|
9
9
|
import {algorithm, hash} from "../crypto.js";
|
|
10
|
-
import {assert} from "../invariants.js";
|
|
11
10
|
import log from "../log.js";
|
|
12
11
|
import codes from "./http-codes.json" assert {"type": "json"};
|
|
13
12
|
import mimes from "./mimes.json" assert {"type": "json"};
|
|
14
|
-
import policy from "./content-security-policy.json" assert {"type": "json"};
|
|
15
13
|
|
|
16
14
|
const regex = /\.([a-z1-9]*)$/u;
|
|
17
15
|
const mime = filename => mimes[filename.match(regex)[1]] ?? mimes.binary;
|
|
18
16
|
|
|
19
|
-
const csp = Object.keys(policy)
|
|
20
|
-
.reduce((policy_string, key) => policy_string + `${key} ${policy[key]};`, "");
|
|
21
|
-
|
|
22
17
|
const stream = (from, response) => {
|
|
23
18
|
response.setHeader("Content-Encoding", "br");
|
|
24
19
|
response.writeHead(codes.OK);
|
|
@@ -30,11 +25,15 @@ const stream = (from, response) => {
|
|
|
30
25
|
export default class StaticServer extends Server {
|
|
31
26
|
async run() {
|
|
32
27
|
const {http, context} = this.conf;
|
|
28
|
+
const {csp, "same-site": same_site = "Strict"} = http;
|
|
29
|
+
this.csp = Object.keys(csp).reduce((policy_string, key) =>
|
|
30
|
+
policy_string + `${key} ${csp[key]};`, "");
|
|
33
31
|
|
|
34
32
|
this.server = await createServer(http, async (request, response) => {
|
|
35
33
|
const session = await Session.get(request.headers.cookie, context);
|
|
36
34
|
if (!session.has_cookie) {
|
|
37
|
-
|
|
35
|
+
const {cookie} = session;
|
|
36
|
+
response.setHeader("Set-Cookie", `${cookie}; SameSite=${same_site}`);
|
|
38
37
|
}
|
|
39
38
|
response.session = session;
|
|
40
39
|
request.on("end", () =>
|
|
@@ -90,7 +89,7 @@ export default class StaticServer extends Server {
|
|
|
90
89
|
.reduce((hash_string, next_hash) => hash_string + ` '${next_hash}'`, "");
|
|
91
90
|
|
|
92
91
|
response.setHeader("Content-Security-Policy",
|
|
93
|
-
csp + `script-src 'self'${script_src};`);
|
|
92
|
+
this.csp + `script-src 'self'${script_src};`);
|
|
94
93
|
response.setHeader("Content-Type", "text/html");
|
|
95
94
|
response.setHeader("Referrer-Policy", "same-origin");
|
|
96
95
|
return stream(Readable.from([file]), response);
|