@brydio/manifest 0.1.0-alpha.0 → 0.1.0-alpha.11
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/README.md +24 -0
- package/package.json +2 -2
- package/src/base.d.ts +17 -1
- package/src/base.js +13 -1
- package/src/bundle.d.ts +8 -1
- package/src/bundle.js +28 -3
- package/src/grants.d.ts +1 -1
- package/src/grants.js +1 -1
- package/src/index.d.ts +5 -4
- package/src/index.js +5 -4
- package/src/requirements.d.ts +122 -0
- package/src/requirements.js +692 -0
- package/src/schema.d.ts +243 -2
- package/src/schema.js +188 -8
- package/src/secrets.d.ts +14 -0
- package/src/secrets.js +27 -5
package/src/secrets.js
CHANGED
|
@@ -35,21 +35,21 @@ const isRealValue = (value) => {
|
|
|
35
35
|
return false;
|
|
36
36
|
return true;
|
|
37
37
|
};
|
|
38
|
-
function walk(node, at, found) {
|
|
38
|
+
function walk(node, at, found, publicValue = () => false) {
|
|
39
39
|
if (Array.isArray(node)) {
|
|
40
|
-
node.forEach((one, index) => walk(one, `${at}[${index}]`, found));
|
|
40
|
+
node.forEach((one, index) => walk(one, `${at}[${index}]`, found, publicValue));
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
if (!node || typeof node !== 'object')
|
|
44
44
|
return;
|
|
45
45
|
for (const [key, value] of Object.entries(node)) {
|
|
46
46
|
const path = at ? `${at}.${key}` : key;
|
|
47
|
-
if (VALUE_KEYS.has(key) && isRealValue(value)) {
|
|
47
|
+
if (VALUE_KEYS.has(key) && isRealValue(value) && !publicValue(path)) {
|
|
48
48
|
// Never quoted back: a report that repeated the secret would copy it somewhere else.
|
|
49
49
|
found.push({ code: 'secret_in_bundle', message: SECRET_MESSAGE, path });
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
|
-
walk(value, path, found);
|
|
52
|
+
walk(value, path, found, publicValue);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -59,7 +59,7 @@ function walk(node, at, found) {
|
|
|
59
59
|
*/
|
|
60
60
|
export function secretsInJson(document, at) {
|
|
61
61
|
const found = [];
|
|
62
|
-
walk(document, at, found);
|
|
62
|
+
walk(document, at, found, path => /(?:^|\.)placements\[\d+\]\.key$/.test(path));
|
|
63
63
|
return found;
|
|
64
64
|
}
|
|
65
65
|
/** Every secret declared in a bundle's files, as the server finds them. */
|
|
@@ -79,3 +79,25 @@ export function findSecrets(files, root = '') {
|
|
|
79
79
|
}
|
|
80
80
|
return found;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The server's sentence for `developer_key_in_bundle` (ADR-A22), word for
|
|
84
|
+
* word: `DEVELOPER_KEY_IN_BUNDLE` in Brydio's `app-publish.service.ts`.
|
|
85
|
+
*/
|
|
86
|
+
export const DEVELOPER_KEY_MESSAGE = 'That package contains a Brydio developer API key. A key belongs on your own server, never in an app: revoke it in Settings › Developer, and call Brydio’s model from a handler with the model grant instead.';
|
|
87
|
+
/** A developer API key's exact shape, anywhere in a text. */
|
|
88
|
+
const DEVELOPER_KEY = /bry_live_[0-9a-f]{12}_[A-Za-z0-9_-]{43}/;
|
|
89
|
+
/** Whether a text holds a Brydio developer API key. */
|
|
90
|
+
export const holdsDeveloperKey = (text) => DEVELOPER_KEY.test(text);
|
|
91
|
+
/**
|
|
92
|
+
* The first file holding a developer API key, by path, as Brydio's publish
|
|
93
|
+
* route finds it (`developerKeyIn`). Unlike the declaration scan, every file
|
|
94
|
+
* is read, scripts included: the key's shape is exact enough that a match is
|
|
95
|
+
* a key, not a guess, and no part of an app may hold one (ADR-A24).
|
|
96
|
+
*/
|
|
97
|
+
export function developerKeyIn(files) {
|
|
98
|
+
for (const [path, bytes] of files) {
|
|
99
|
+
if (holdsDeveloperKey(new TextDecoder('latin1').decode(bytes)))
|
|
100
|
+
return path;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|