@molecule/api-git-provider-gitea 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.
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +23 -1
- package/package.json +3 -3
package/dist/provider.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AA0DnC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,WA4DtB,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -23,6 +23,27 @@ const normalize = (repo) => repo.full_name && repo.clone_url
|
|
|
23
23
|
description: repo.description ?? null,
|
|
24
24
|
}
|
|
25
25
|
: null;
|
|
26
|
+
/**
|
|
27
|
+
* Validates a (possibly user-supplied) host before it is interpolated into
|
|
28
|
+
* an API base URL. Fails closed: anything carrying URL structure — path
|
|
29
|
+
* separators, query strings, fragments, userinfo (`token@host`), scheme
|
|
30
|
+
* separators — is rejected, so the bearer-token-bearing request can never
|
|
31
|
+
* be reshaped to an attacker-chosen path or credential-prefixed URL.
|
|
32
|
+
* Allowed: hostname letters/digits/dots/hyphens plus an optional port.
|
|
33
|
+
*/
|
|
34
|
+
const assertValidHost = (host) => {
|
|
35
|
+
if (!/^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::\d{1,5})?$/.test(host)) {
|
|
36
|
+
throw new Error(`Invalid git provider host: ${JSON.stringify(host)}`);
|
|
37
|
+
}
|
|
38
|
+
return host;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* URL-encodes each `/`-separated segment of an `owner/name`-style repo
|
|
42
|
+
* path, preserving the separators: a path containing spaces, `?`, `#`, or
|
|
43
|
+
* other URL-meaningful bytes must not be able to alter the request target
|
|
44
|
+
* the token is sent to.
|
|
45
|
+
*/
|
|
46
|
+
const encodeRepoPath = (path) => path.split('/').map(encodeURIComponent).join('/');
|
|
26
47
|
/**
|
|
27
48
|
* The Gitea provider.
|
|
28
49
|
*
|
|
@@ -47,6 +68,7 @@ export const provider = {
|
|
|
47
68
|
},
|
|
48
69
|
basicAuthUsername: 'x-access-token',
|
|
49
70
|
apiBaseForHost(host) {
|
|
71
|
+
assertValidHost(host);
|
|
50
72
|
return `https://${host}/api/v1`;
|
|
51
73
|
},
|
|
52
74
|
apiHeaders(token) {
|
|
@@ -71,7 +93,7 @@ export const provider = {
|
|
|
71
93
|
const { get } = await import('@molecule/api-http');
|
|
72
94
|
const base = this.apiBaseForHost(input.host);
|
|
73
95
|
try {
|
|
74
|
-
const response = await get(`${base}/repos/${input.path}`, {
|
|
96
|
+
const response = await get(`${base}/repos/${encodeRepoPath(input.path)}`, {
|
|
75
97
|
headers: this.apiHeaders(input.token),
|
|
76
98
|
timeout: 15_000,
|
|
77
99
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-git-provider-gitea",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Git hosting provider for Gitea (gitea.com) — 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/gitea"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/api-git-provider": "1.0.
|
|
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.
|
|
40
|
+
"vitest": "4.1.11"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@molecule/api-git-provider": "^1.0.2",
|