cornfield 0.33.0 → 0.33.1
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/core/config.js +19 -2
- package/package.json +1 -1
- package/server/forge.js +2 -1
package/core/config.js
CHANGED
|
@@ -190,6 +190,20 @@ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
|
190
190
|
const isText = (v) => typeof v === 'string' && v.trim() !== '';
|
|
191
191
|
/** A path inside the repo: relative, forward slashes, no `..` segment */
|
|
192
192
|
const inRepo = (p) => isText(p) && !path.isAbsolute(p) && !p.split(/[\\/]/).includes('..');
|
|
193
|
+
/** A forge's origin: http(s), a host name or a bracketed IPv6 address, and a port; no user name, path, query, fragment or backslash */
|
|
194
|
+
const FORGE_ORIGIN = /^https?:\/\/([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?\/?$/;
|
|
195
|
+
/**
|
|
196
|
+
* Whether `url` is a forge's origin, and one the URL parser keeps as written: a host it would rewrite to another
|
|
197
|
+
* (`https://2130706433` and `https://0x7f.1` are 127.0.0.1), an IPv6 address it cannot read, or a port past 65535 is not one
|
|
198
|
+
*/
|
|
199
|
+
const isForgeOrigin = (url) => {
|
|
200
|
+
const m = typeof url === 'string' ? FORGE_ORIGIN.exec(url) : null;
|
|
201
|
+
if (!m) return false;
|
|
202
|
+
try {
|
|
203
|
+
const u = new URL(url);
|
|
204
|
+
return m[1].startsWith('[') || u.hostname === m[1].toLowerCase();
|
|
205
|
+
} catch { return false; }
|
|
206
|
+
};
|
|
193
207
|
|
|
194
208
|
/**
|
|
195
209
|
* What is wrong with a config object (as the file exports it, before defaults).
|
|
@@ -238,8 +252,11 @@ export function configProblems(c) {
|
|
|
238
252
|
if (!isObject(c.forge)) out.push('"forge" is { type, url, repo }.');
|
|
239
253
|
else {
|
|
240
254
|
if (!FORGE_TYPES.includes(c.forge.type)) out.push(`forge.type is one of ${FORGE_TYPES.join(', ')}.`);
|
|
241
|
-
if (c.forge.url !== undefined &&
|
|
242
|
-
|
|
255
|
+
if (c.forge.url !== undefined && !isForgeOrigin(c.forge.url)) out.push('forge.url is the forge\'s origin, like https://github.com.');
|
|
256
|
+
// GitHub and GitHub Enterprise only speak https; a token over http would travel in the clear
|
|
257
|
+
else if (c.forge.url !== undefined && c.forge.type === 'github' && !/^https:/i.test(String(c.forge.url)) && !/^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/?$/i.test(String(c.forge.url))) out.push('forge.url for GitHub is https (http only for localhost): the token would otherwise travel in the clear.');
|
|
258
|
+
const repoParts = String(c.forge.repo || '').split('/');
|
|
259
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(String(c.forge.repo || '')) || repoParts.some((p) => /^\.+$/.test(p))) out.push('forge.repo is "owner/name".');
|
|
243
260
|
if (c.forge.mergeMethod !== undefined && !MERGE_METHODS.includes(c.forge.mergeMethod)) out.push(`forge.mergeMethod is one of ${MERGE_METHODS.join(', ')}.`);
|
|
244
261
|
if (c.forge.baseBranch !== undefined && !(typeof c.forge.baseBranch === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/.test(c.forge.baseBranch) && !c.forge.baseBranch.includes('..'))) out.push('forge.baseBranch is the branch spec pull requests go into, like "main".');
|
|
245
262
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/forge.js
CHANGED
|
@@ -141,7 +141,8 @@ const MAX_LABELS = 5;
|
|
|
141
141
|
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
142
142
|
const MERGE_METHODS = ['merge', 'squash', 'rebase'];
|
|
143
143
|
const STATES = ['open', 'closed', 'all'];
|
|
144
|
-
|
|
144
|
+
/** owner/name, neither made only of dots (`..` would walk out of `repos/` in the API's path) */
|
|
145
|
+
const REPO = /^(?!\.+\/)[\w.-]+\/(?!\.+$)[\w.-]+$/;
|
|
145
146
|
/** A tag name a release draft may carry: no spaces, no `..`, no leading dash, at most 100 characters */
|
|
146
147
|
const TAG_NAME = /^[\w][\w./+-]{0,99}$/;
|
|
147
148
|
/** The most a release's body may hold (GitHub's own limit) */
|