@molecule/api-git-provider-smolforge 1.0.3 → 1.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,WAAW,EAGZ,MAAM,4BAA4B,CAAA;AAqDnC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,WA8DtB,CAAA"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,WAAW,EAGZ,MAAM,4BAA4B,CAAA;AA4EnC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,WAkEtB,CAAA"}
package/dist/provider.js CHANGED
@@ -37,6 +37,27 @@ const normalize = (repo, host) => {
37
37
  description: repo.description ?? null,
38
38
  };
39
39
  };
40
+ /**
41
+ * Validates a (possibly user-supplied) host before it is interpolated into
42
+ * an API base URL. Fails closed: anything carrying URL structure — path
43
+ * separators, query strings, fragments, userinfo (`token@host`), scheme
44
+ * separators — is rejected, so the bearer-token-bearing request can never
45
+ * be reshaped to an attacker-chosen path or credential-prefixed URL.
46
+ * Allowed: hostname letters/digits/dots/hyphens plus an optional port.
47
+ */
48
+ const assertValidHost = (host) => {
49
+ if (!/^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::\d{1,5})?$/.test(host)) {
50
+ throw new Error(`Invalid git provider host: ${JSON.stringify(host)}`);
51
+ }
52
+ return host;
53
+ };
54
+ /**
55
+ * URL-encodes each `/`-separated segment of an `owner/name`-style repo
56
+ * path, preserving the separators: a path containing spaces, `?`, `#`, or
57
+ * other URL-meaningful bytes must not be able to alter the request target
58
+ * the token is sent to.
59
+ */
60
+ const encodeRepoPath = (path) => path.split('/').map(encodeURIComponent).join('/');
40
61
  /**
41
62
  * The SmolForge provider.
42
63
  *
@@ -58,6 +79,7 @@ export const provider = {
58
79
  // substitute the connected account's username here.
59
80
  basicAuthUsername: null,
60
81
  apiBaseForHost(host) {
82
+ assertValidHost(host);
61
83
  return `https://${host}/api`;
62
84
  },
63
85
  apiHeaders(token) {
@@ -85,7 +107,7 @@ export const provider = {
85
107
  const { get } = await import('@molecule/api-http');
86
108
  const base = this.apiBaseForHost(input.host);
87
109
  try {
88
- const response = await get(`${base}/repos/${input.path}`, {
110
+ const response = await get(`${base}/repos/${encodeRepoPath(input.path)}`, {
89
111
  headers: this.apiHeaders(input.token),
90
112
  timeout: 15_000,
91
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-git-provider-smolforge",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Git hosting provider for SmolForge (forge.smol.ai) — OAuth endpoints, token auth shape, repository listing and lookup.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,11 +33,11 @@
33
33
  "directory": "packages/api/bonds/git-provider/smolforge"
34
34
  },
35
35
  "devDependencies": {
36
- "@molecule/api-git-provider": "1.0.3",
36
+ "@molecule/api-git-provider": "1.0.4",
37
37
  "@molecule/api-http": "1.0.1",
38
38
  "@types/node": "26.1.2",
39
39
  "typescript": "6.0.3",
40
- "vitest": "4.1.10"
40
+ "vitest": "4.1.11"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@molecule/api-git-provider": "^1.0.2",