@dominevo/series-scraper-core 0.0.90 → 0.0.92
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/controllers/notifications.controller.d.ts +4 -11
- package/dist/controllers/notifications.controller.js +7 -5
- package/dist/controllers/settings.controller.d.ts +3 -3
- package/dist/controllers/settings.controller.js +6 -4
- package/dist/controllers/sites.controller.d.ts +5 -53
- package/dist/controllers/sites.controller.js +47 -14
- package/dist/controllers/table.controller.js +2 -1
- package/dist/controllers/vpn.controller.d.ts +5 -0
- package/dist/controllers/vpn.controller.js +35 -3
- package/dist/docker-layout/secret-layout.js +19 -7
- package/dist/ports/secret-store.d.ts +2 -0
- package/dist/ports/secret-store.js +2 -0
- package/dist/repositories/settings.repository.d.ts +5 -0
- package/dist/repositories/settings.repository.js +15 -1
- package/dist/repositories/sites.repository.d.ts +6 -1
- package/dist/repositories/sites.repository.js +34 -5
- package/dist/repositories/webhook.repository.d.ts +3 -0
- package/dist/repositories/webhook.repository.js +13 -4
- package/dist/scraper.module.js +2 -0
- package/dist/services/captcha.service.js +1 -1
- package/dist/services/download.service.js +1 -1
- package/dist/services/egress/egress-context.d.ts +4 -0
- package/dist/services/egress/egress-input.d.ts +15 -2
- package/dist/services/egress/egress-input.js +32 -3
- package/dist/services/egress/leak-guard.d.ts +5 -1
- package/dist/services/plugin-settings.service.d.ts +2 -0
- package/dist/services/plugin-settings.service.js +16 -3
- package/dist/services/secret-migration.service.d.ts +22 -0
- package/dist/services/secret-migration.service.js +48 -0
- package/dist/services/secret-views.d.ts +56 -0
- package/dist/services/secret-views.js +120 -0
- package/dist/services/vpn.service.d.ts +9 -2
- package/dist/services/vpn.service.js +38 -9
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.WebhookRepository = void 0;
|
|
16
|
+
exports.parseHeaders = parseHeaders;
|
|
16
17
|
const common_1 = require("@nestjs/common");
|
|
17
18
|
const tokens_1 = require("../ports/tokens");
|
|
18
19
|
const secret_store_1 = require("../ports/secret-store");
|
|
@@ -30,6 +31,11 @@ let WebhookRepository = class WebhookRepository {
|
|
|
30
31
|
}
|
|
31
32
|
save(webhook) {
|
|
32
33
|
const { headers, ...stored } = webhook;
|
|
34
|
+
// Secret first, state after (see SettingsRepository.save): a crash between the two never loses the headers.
|
|
35
|
+
const text = JSON.stringify(headers ?? {});
|
|
36
|
+
const name = secret_store_1.secretNames.webhookHeaders(webhook.id);
|
|
37
|
+
if (this.secrets.get(name) !== text)
|
|
38
|
+
this.secrets.set(name, text);
|
|
33
39
|
const store = this.repo.read();
|
|
34
40
|
const idx = store.webhooks.findIndex((w) => w.id === webhook.id);
|
|
35
41
|
if (idx >= 0) {
|
|
@@ -39,10 +45,6 @@ let WebhookRepository = class WebhookRepository {
|
|
|
39
45
|
store.webhooks.push(stored);
|
|
40
46
|
}
|
|
41
47
|
this.repo.write(store);
|
|
42
|
-
const text = JSON.stringify(headers ?? {});
|
|
43
|
-
const name = secret_store_1.secretNames.webhookHeaders(webhook.id);
|
|
44
|
-
if (this.secrets.get(name) !== text)
|
|
45
|
-
this.secrets.set(name, text);
|
|
46
48
|
}
|
|
47
49
|
delete(id) {
|
|
48
50
|
const store = this.repo.read();
|
|
@@ -55,6 +57,13 @@ let WebhookRepository = class WebhookRepository {
|
|
|
55
57
|
}
|
|
56
58
|
return false;
|
|
57
59
|
}
|
|
60
|
+
/** Moves headers an older state file still holds into the secret store. Returns how many webhooks it moved; a second run finds none. */
|
|
61
|
+
migratePlaintext() {
|
|
62
|
+
const legacy = this.repo.read().webhooks.filter((w) => w.headers !== undefined);
|
|
63
|
+
for (const stored of legacy)
|
|
64
|
+
this.save(this.hydrate(stored));
|
|
65
|
+
return legacy.filter((w) => Object.keys(w.headers ?? {}).length > 0).length;
|
|
66
|
+
}
|
|
58
67
|
hydrate(stored) {
|
|
59
68
|
const text = this.secrets.get(secret_store_1.secretNames.webhookHeaders(stored.id));
|
|
60
69
|
return { ...stored, headers: text === undefined ? stored.headers ?? {} : parseHeaders(text) };
|
package/dist/scraper.module.js
CHANGED
|
@@ -65,6 +65,7 @@ const captcha_controller_1 = require("./controllers/captcha.controller");
|
|
|
65
65
|
const plex_controller_1 = require("./controllers/plex.controller");
|
|
66
66
|
const plex_service_1 = require("./services/plex.service");
|
|
67
67
|
const captcha_service_1 = require("./services/captcha.service");
|
|
68
|
+
const secret_migration_service_1 = require("./services/secret-migration.service");
|
|
68
69
|
const captcha_challenges_repository_1 = require("./repositories/captcha-challenges.repository");
|
|
69
70
|
const CONTROLLERS = [
|
|
70
71
|
core_controller_1.CoreController,
|
|
@@ -121,6 +122,7 @@ const PROVIDERS = [
|
|
|
121
122
|
vpn_service_1.VpnService,
|
|
122
123
|
captcha_service_1.CaptchaService,
|
|
123
124
|
book_adapter_registry_service_1.BookAdapterRegistryService,
|
|
125
|
+
secret_migration_service_1.SecretMigrationService,
|
|
124
126
|
];
|
|
125
127
|
let ScraperModule = class ScraperModule {
|
|
126
128
|
};
|
|
@@ -236,7 +236,7 @@ let CaptchaService = CaptchaService_1 = class CaptchaService {
|
|
|
236
236
|
async exchange(challenge, url, init) {
|
|
237
237
|
const host = (0, captcha_fallback_1.hostOf)(url);
|
|
238
238
|
try {
|
|
239
|
-
const dispatcher = challenge.egressId ? this.vpn.getDispatcherForExit(challenge.egressId) : undefined;
|
|
239
|
+
const dispatcher = challenge.egressId ? this.vpn.getDispatcherForExit(challenge.egressId, 'hoster-resolution') : undefined;
|
|
240
240
|
const res = await fetch(url, dispatcher ? { ...init, dispatcher } : init);
|
|
241
241
|
if (!res.ok) {
|
|
242
242
|
this.logger.warn(`Captcha ${challenge.id}: ${host} answered HTTP ${res.status}`);
|
|
@@ -1895,7 +1895,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
1895
1895
|
const title = (current?.entryId ? this.tableRepo.getById(current.entryId)?.title : undefined) ?? 'unknown entry';
|
|
1896
1896
|
const exitName = this.vpn.getExitName(egressId) ?? egressId;
|
|
1897
1897
|
this.logger.log(`Fallback exit "${exitName}" used for the hoster page of "${title}" (host ${(0, captcha_fallback_1.hostOf)(link.url)})`);
|
|
1898
|
-
const resolved = await egress_context_1.egressContext.run({ ...(current?.entryId ? { entryId: current.entryId } : {}), egressId }, () => this.resolveLinkRouted(link));
|
|
1898
|
+
const resolved = await egress_context_1.egressContext.run({ ...(current?.entryId ? { entryId: current.entryId } : {}), egressId, purpose: 'hoster-resolution' }, () => this.resolveLinkRouted(link));
|
|
1899
1899
|
return resolved.egressId === egressId ? { ...resolved, egressId: undefined } : resolved;
|
|
1900
1900
|
}
|
|
1901
1901
|
async resolveMaxstreamPage(url, followedContinue = false, viaFallback = false) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
/** Why a request is made. Named by the caller, never inferred from a host. */
|
|
2
|
+
export type ExitPurpose = 'hoster-resolution';
|
|
1
3
|
/** What the work running right now belongs to: a watched entry, and the exit it insists on. */
|
|
2
4
|
export interface EgressContextValue {
|
|
3
5
|
entryId?: string;
|
|
6
|
+
/** What the work is for, stated by its call site. `hoster-resolution` (hoster pages, link decoders, headless player, captcha) is the only purpose a home-IP exit serves; media downloads never carry it. */
|
|
7
|
+
purpose?: ExitPurpose;
|
|
4
8
|
/** Present = a chain of exactly this exit. Absent = rules and default as usual. */
|
|
5
9
|
egressId?: string;
|
|
6
10
|
}
|
|
@@ -21,6 +21,19 @@ export type EntryEgressPatch = {
|
|
|
21
21
|
egressId: string | undefined;
|
|
22
22
|
};
|
|
23
23
|
/** The `egressId` of a watched-entry PATCH: absent leaves it, null or empty clears it, otherwise it must be a known exit. */
|
|
24
|
-
export declare function parseEntryEgressPatch(body: unknown, known: ReadonlySet<string>): EntryEgressPatch;
|
|
24
|
+
export declare function parseEntryEgressPatch(body: unknown, known: ReadonlySet<string>, homeOnly?: ReadonlySet<string>): EntryEgressPatch;
|
|
25
25
|
/** Validate a settings patch against the known exit ids and return the new settings. */
|
|
26
|
-
export declare function parseSettingsPatch(body: unknown, current: VpnSettings, knownEgressIds: ReadonlySet<string>): VpnSettings;
|
|
26
|
+
export declare function parseSettingsPatch(body: unknown, current: VpnSettings, knownEgressIds: ReadonlySet<string>, homeOnly?: ReadonlySet<string>): VpnSettings;
|
|
27
|
+
/** What a home-connection exit would be used for besides hoster link resolution and captcha, to name it in a refusal. */
|
|
28
|
+
export interface HomeIpUsage {
|
|
29
|
+
defaultEgressId?: string;
|
|
30
|
+
ruleExitIds: readonly string[];
|
|
31
|
+
/** Watched entries that pin their traffic to an exit. */
|
|
32
|
+
entryEgressIds: readonly string[];
|
|
33
|
+
captchaFallbackEgressId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The flag is allowed only on an exit whose single role is captcha solving: it is the captcha fallback
|
|
37
|
+
* exit, and it is not the default, in a rule, or pinned by a watched item. Throws with the reason.
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertHomeIpAllowed(egressId: string, name: string, usage: HomeIpUsage): void;
|
|
@@ -6,6 +6,7 @@ exports.parseNewEgress = parseNewEgress;
|
|
|
6
6
|
exports.applyEgressPatch = applyEgressPatch;
|
|
7
7
|
exports.parseEntryEgressPatch = parseEntryEgressPatch;
|
|
8
8
|
exports.parseSettingsPatch = parseSettingsPatch;
|
|
9
|
+
exports.assertHomeIpAllowed = assertHomeIpAllowed;
|
|
9
10
|
const wireproxy_config_1 = require("./wireproxy-config");
|
|
10
11
|
const NORD_DNS = '103.86.96.100';
|
|
11
12
|
const DEFAULT_DNS = '1.1.1.1';
|
|
@@ -81,6 +82,9 @@ function buildEgress(fields, resolved) {
|
|
|
81
82
|
const presetId = optionalText(fields.presetId);
|
|
82
83
|
const type = fields.type;
|
|
83
84
|
const base = presetId ? { name, presetId } : { name };
|
|
85
|
+
if (fields.homeIpByDesign === true && type !== 'socks5' && type !== 'http') {
|
|
86
|
+
throw new EgressInputError('Only a SOCKS5 or HTTP exit can use the home connection on purpose');
|
|
87
|
+
}
|
|
84
88
|
if (type === 'direct')
|
|
85
89
|
return { ...base, type };
|
|
86
90
|
if (type === 'wireguard')
|
|
@@ -89,6 +93,8 @@ function buildEgress(fields, resolved) {
|
|
|
89
93
|
throw new EgressInputError('type must be one of direct, socks5, http, wireguard');
|
|
90
94
|
const username = optionalText(fields.username);
|
|
91
95
|
const password = typeof fields.password === 'string' && fields.password ? fields.password : undefined;
|
|
96
|
+
if (fields.homeIpByDesign !== undefined && typeof fields.homeIpByDesign !== 'boolean')
|
|
97
|
+
throw new EgressInputError('homeIpByDesign must be a boolean');
|
|
92
98
|
return {
|
|
93
99
|
...base,
|
|
94
100
|
type,
|
|
@@ -96,6 +102,7 @@ function buildEgress(fields, resolved) {
|
|
|
96
102
|
port: port(fields.port),
|
|
97
103
|
...(username ? { username } : {}),
|
|
98
104
|
...(password ? { password } : {}),
|
|
105
|
+
...(fields.homeIpByDesign === true ? { homeIpByDesign: true } : {}),
|
|
99
106
|
};
|
|
100
107
|
}
|
|
101
108
|
function parseNewEgress(body, resolved) {
|
|
@@ -113,7 +120,7 @@ function applyEgressPatch(existing, patch, resolved) {
|
|
|
113
120
|
if (!isRecord(patch))
|
|
114
121
|
throw new EgressInputError('A JSON object is required');
|
|
115
122
|
const merged = { ...existing };
|
|
116
|
-
for (const key of ['name', 'presetId', 'type', 'host', 'port', 'username', 'address', 'publicKey', 'endpoint', 'dns', 'mtu', 'nord']) {
|
|
123
|
+
for (const key of ['name', 'presetId', 'type', 'host', 'port', 'username', 'address', 'publicKey', 'endpoint', 'dns', 'mtu', 'nord', 'homeIpByDesign']) {
|
|
117
124
|
if (key in patch)
|
|
118
125
|
merged[key] = patch[key];
|
|
119
126
|
}
|
|
@@ -149,7 +156,7 @@ function parseRules(value, known) {
|
|
|
149
156
|
});
|
|
150
157
|
}
|
|
151
158
|
/** The `egressId` of a watched-entry PATCH: absent leaves it, null or empty clears it, otherwise it must be a known exit. */
|
|
152
|
-
function parseEntryEgressPatch(body, known) {
|
|
159
|
+
function parseEntryEgressPatch(body, known, homeOnly = new Set()) {
|
|
153
160
|
if (!isRecord(body) || !('egressId' in body))
|
|
154
161
|
return { change: false };
|
|
155
162
|
const id = body.egressId;
|
|
@@ -159,10 +166,12 @@ function parseEntryEgressPatch(body, known) {
|
|
|
159
166
|
throw new EgressInputError('egressId must be an exit id or null');
|
|
160
167
|
if (!known.has(id))
|
|
161
168
|
throw new EgressInputError('egressId names an unknown exit');
|
|
169
|
+
if (homeOnly.has(id))
|
|
170
|
+
throw new EgressInputError('That exit uses the home connection on purpose and serves hoster link resolution and captcha only');
|
|
162
171
|
return { change: true, egressId: id };
|
|
163
172
|
}
|
|
164
173
|
/** Validate a settings patch against the known exit ids and return the new settings. */
|
|
165
|
-
function parseSettingsPatch(body, current, knownEgressIds) {
|
|
174
|
+
function parseSettingsPatch(body, current, knownEgressIds, homeOnly = new Set()) {
|
|
166
175
|
if (!isRecord(body))
|
|
167
176
|
throw new EgressInputError('A JSON object is required');
|
|
168
177
|
let strictMode = current.strictMode;
|
|
@@ -176,6 +185,8 @@ function parseSettingsPatch(body, current, knownEgressIds) {
|
|
|
176
185
|
const id = body.defaultEgressId;
|
|
177
186
|
if (id === null || id === '')
|
|
178
187
|
defaultEgressId = undefined;
|
|
188
|
+
else if (typeof id === 'string' && homeOnly.has(id))
|
|
189
|
+
throw new EgressInputError('That exit uses the home connection on purpose and serves hoster link resolution and captcha only: it cannot be the default');
|
|
179
190
|
else if (typeof id === 'string' && knownEgressIds.has(id))
|
|
180
191
|
defaultEgressId = id;
|
|
181
192
|
else
|
|
@@ -192,5 +203,23 @@ function parseSettingsPatch(body, current, knownEgressIds) {
|
|
|
192
203
|
throw new EgressInputError('captchaFallbackEgressId names an unknown exit');
|
|
193
204
|
}
|
|
194
205
|
const rules = 'rules' in body ? parseRules(body.rules, knownEgressIds) : current.rules;
|
|
206
|
+
if ('rules' in body && rules.some((r) => r.egressIds.some((id) => homeOnly.has(id)))) {
|
|
207
|
+
throw new EgressInputError('A rule names an exit that uses the home connection on purpose and serves hoster link resolution and captcha only');
|
|
208
|
+
}
|
|
195
209
|
return { version: 2, defaultEgressId, strictMode, rules, captchaFallbackEgressId };
|
|
196
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* The flag is allowed only on an exit whose single role is captcha solving: it is the captcha fallback
|
|
213
|
+
* exit, and it is not the default, in a rule, or pinned by a watched item. Throws with the reason.
|
|
214
|
+
*/
|
|
215
|
+
function assertHomeIpAllowed(egressId, name, usage) {
|
|
216
|
+
if (usage.captchaFallbackEgressId !== egressId) {
|
|
217
|
+
throw new EgressInputError(`"${name}" must be the captcha fallback exit before it can use the home connection on purpose`);
|
|
218
|
+
}
|
|
219
|
+
if (usage.defaultEgressId === egressId)
|
|
220
|
+
throw new EgressInputError(`"${name}" is the default exit: it cannot use the home connection on purpose`);
|
|
221
|
+
if (usage.ruleExitIds.includes(egressId))
|
|
222
|
+
throw new EgressInputError(`"${name}" is used by a host rule: it cannot use the home connection on purpose`);
|
|
223
|
+
if (usage.entryEgressIds.includes(egressId))
|
|
224
|
+
throw new EgressInputError(`"${name}" is pinned by a watched item: it cannot use the home connection on purpose`);
|
|
225
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `home`: the exit reports the direct IP and is flagged `homeIpByDesign`. That is the expected state of
|
|
3
|
+
* the captcha exit the operator chose to run on the home connection, informational, never a fault.
|
|
4
|
+
*/
|
|
5
|
+
export type LeakVerdict = 'leak' | 'ok' | 'unknown' | 'home';
|
|
2
6
|
/**
|
|
3
7
|
* Compare an exit's egress IP with the direct one. Equal means the traffic
|
|
4
8
|
* is not leaving through the exit. A failed lookup is `unknown`, never a
|
|
@@ -6,6 +6,8 @@ export { PluginSettingsError };
|
|
|
6
6
|
export interface PluginSettingsView {
|
|
7
7
|
fields: PluginSettingField[];
|
|
8
8
|
values: PluginSettingValues;
|
|
9
|
+
/** Text settings whose name reads like a credential: their value is never shown (`''`), and an empty one on a write keeps the stored value. */
|
|
10
|
+
secretKeys: string[];
|
|
9
11
|
}
|
|
10
12
|
export declare class PluginSettingsService {
|
|
11
13
|
private readonly loader;
|
|
@@ -11,10 +11,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PluginSettingsService = exports.PluginSettingsError = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
+
const secret_views_1 = require("./secret-views");
|
|
14
15
|
const plugin_settings_repository_1 = require("../repositories/plugin-settings.repository");
|
|
15
16
|
const plugin_loader_service_1 = require("./plugin-loader.service");
|
|
16
17
|
const plugin_settings_1 = require("./plugin-settings");
|
|
17
18
|
Object.defineProperty(exports, "PluginSettingsError", { enumerable: true, get: function () { return plugin_settings_1.PluginSettingsError; } });
|
|
19
|
+
/** The text settings of a plugin that hold a credential, by the name heuristic (a schema flag may replace it). */
|
|
20
|
+
function secretKeysOf(fields) {
|
|
21
|
+
return fields.filter((f) => f.type === 'string' && (0, secret_views_1.isCredentialName)(f.key)).map((f) => f.key);
|
|
22
|
+
}
|
|
23
|
+
function viewOf(fields, values) {
|
|
24
|
+
const secretKeys = secretKeysOf(fields);
|
|
25
|
+
return { fields, values: { ...values, ...Object.fromEntries(secretKeys.map((k) => [k, ''])) }, secretKeys };
|
|
26
|
+
}
|
|
18
27
|
let PluginSettingsService = class PluginSettingsService {
|
|
19
28
|
constructor(loader, repo) {
|
|
20
29
|
this.loader = loader;
|
|
@@ -25,7 +34,7 @@ let PluginSettingsService = class PluginSettingsService {
|
|
|
25
34
|
const handle = this.loader.getSettingsHandle(pluginName);
|
|
26
35
|
if (!handle)
|
|
27
36
|
return null;
|
|
28
|
-
return
|
|
37
|
+
return viewOf(handle.fields, (0, plugin_settings_1.resolveSettingValues)(handle.fields, this.repo.getFor(pluginName)));
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
40
|
* Validates, applies live through the plugin's `configure`, and persists only
|
|
@@ -35,7 +44,11 @@ let PluginSettingsService = class PluginSettingsService {
|
|
|
35
44
|
const handle = this.loader.getSettingsHandle(pluginName);
|
|
36
45
|
if (!handle)
|
|
37
46
|
throw new plugin_settings_1.PluginSettingsError(`Plugin "${pluginName}" has no settings`);
|
|
38
|
-
const
|
|
47
|
+
const secretKeys = secretKeysOf(handle.fields);
|
|
48
|
+
const typed = typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
49
|
+
? Object.fromEntries(Object.entries(input).filter(([k, v]) => !(secretKeys.includes(k) && (v === '' || v === undefined || v === null))))
|
|
50
|
+
: input;
|
|
51
|
+
const changes = (0, plugin_settings_1.validateSettingValues)(handle.fields, typed);
|
|
39
52
|
const merged = (0, plugin_settings_1.resolveSettingValues)(handle.fields, { ...this.repo.getFor(pluginName), ...changes });
|
|
40
53
|
try {
|
|
41
54
|
handle.configure?.(merged);
|
|
@@ -44,7 +57,7 @@ let PluginSettingsService = class PluginSettingsService {
|
|
|
44
57
|
throw new plugin_settings_1.PluginSettingsError(err instanceof Error ? err.message : String(err));
|
|
45
58
|
}
|
|
46
59
|
this.repo.setFor(pluginName, merged);
|
|
47
|
-
return
|
|
60
|
+
return viewOf(handle.fields, merged);
|
|
48
61
|
}
|
|
49
62
|
};
|
|
50
63
|
exports.PluginSettingsService = PluginSettingsService;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { SettingsRepository } from '../repositories/settings.repository';
|
|
3
|
+
import { SitesRepository } from '../repositories/sites.repository';
|
|
4
|
+
import { WebhookRepository } from '../repositories/webhook.repository';
|
|
5
|
+
/**
|
|
6
|
+
* At boot, moves every credential an older state file still holds in plain text (API keys, the Plex token,
|
|
7
|
+
* webhook and site headers) into the secret store and leaves none behind. Idempotent: a second boot finds
|
|
8
|
+
* nothing. Logs counts only, never a value.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SecretMigrationService implements OnModuleInit {
|
|
11
|
+
private readonly settings;
|
|
12
|
+
private readonly webhooks;
|
|
13
|
+
private readonly sites;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
constructor(settings: SettingsRepository, webhooks: WebhookRepository, sites: SitesRepository);
|
|
16
|
+
onModuleInit(): void;
|
|
17
|
+
run(): {
|
|
18
|
+
settings: number;
|
|
19
|
+
webhooks: number;
|
|
20
|
+
sites: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var SecretMigrationService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SecretMigrationService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const logger_1 = require("../ports/logger");
|
|
16
|
+
const settings_repository_1 = require("../repositories/settings.repository");
|
|
17
|
+
const sites_repository_1 = require("../repositories/sites.repository");
|
|
18
|
+
const webhook_repository_1 = require("../repositories/webhook.repository");
|
|
19
|
+
/**
|
|
20
|
+
* At boot, moves every credential an older state file still holds in plain text (API keys, the Plex token,
|
|
21
|
+
* webhook and site headers) into the secret store and leaves none behind. Idempotent: a second boot finds
|
|
22
|
+
* nothing. Logs counts only, never a value.
|
|
23
|
+
*/
|
|
24
|
+
let SecretMigrationService = SecretMigrationService_1 = class SecretMigrationService {
|
|
25
|
+
constructor(settings, webhooks, sites) {
|
|
26
|
+
this.settings = settings;
|
|
27
|
+
this.webhooks = webhooks;
|
|
28
|
+
this.sites = sites;
|
|
29
|
+
this.logger = new logger_1.ScopedLogger(SecretMigrationService_1.name);
|
|
30
|
+
}
|
|
31
|
+
onModuleInit() {
|
|
32
|
+
this.run();
|
|
33
|
+
}
|
|
34
|
+
run() {
|
|
35
|
+
const moved = { settings: this.settings.migratePlaintext(), webhooks: this.webhooks.migratePlaintext(), sites: this.sites.migratePlaintext() };
|
|
36
|
+
if (moved.settings + moved.webhooks + moved.sites > 0) {
|
|
37
|
+
this.logger.log(`Moved plaintext credentials to the secret store: ${moved.settings} setting(s), ${moved.webhooks} webhook(s), ${moved.sites} site(s)`);
|
|
38
|
+
}
|
|
39
|
+
return moved;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.SecretMigrationService = SecretMigrationService;
|
|
43
|
+
exports.SecretMigrationService = SecretMigrationService = SecretMigrationService_1 = __decorate([
|
|
44
|
+
(0, common_1.Injectable)(),
|
|
45
|
+
__metadata("design:paramtypes", [settings_repository_1.SettingsRepository,
|
|
46
|
+
webhook_repository_1.WebhookRepository,
|
|
47
|
+
sites_repository_1.SitesRepository])
|
|
48
|
+
], SecretMigrationService);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AppSettings } from '../types';
|
|
2
|
+
import type { WebhookConfig } from '../repositories/webhook.repository';
|
|
3
|
+
import type { GenericSiteConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* What the HTTP API shows of a credential: whether it is set, never the value. A credential is
|
|
6
|
+
* written only when typed (an empty field keeps the stored one) and removed by an explicit clear.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SETTINGS_SECRET_KEYS: readonly ["sonarrApiKey", "radarrApiKey", "plexToken"];
|
|
9
|
+
export type SettingsSecretKey = (typeof SETTINGS_SECRET_KEYS)[number];
|
|
10
|
+
/** The settings as the API answers them: every credential is `''` and its `<name>Set` flag says whether one is stored. */
|
|
11
|
+
export type SettingsView = Omit<AppSettings, SettingsSecretKey> & Record<SettingsSecretKey, ''> & Record<`${SettingsSecretKey}Set`, boolean>;
|
|
12
|
+
export declare function toSettingsView(settings: AppSettings): SettingsView;
|
|
13
|
+
/**
|
|
14
|
+
* The partial settings a PATCH body asks for. The view-only `<name>Set` flags are dropped, an empty
|
|
15
|
+
* credential keeps the stored one, and `clear<Name>: true` removes it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSettingsBody(body: unknown): Partial<AppSettings>;
|
|
18
|
+
/** A name that reads like a credential: Authorization, X-Auth-User, X-Api-Key, Cookie, X-Session-Id, a plugin's `apiToken`. Over-matching is safe: such a value is only hidden, and a typed one still goes through. */
|
|
19
|
+
export declare const isCredentialName: (name: string) => boolean;
|
|
20
|
+
export declare const isCredentialHeader: (name: string) => boolean;
|
|
21
|
+
/** A webhook as the API answers it: a credential header keeps its name and answers `''`, and is listed in `secretHeaders`. */
|
|
22
|
+
export type WebhookView = Omit<WebhookConfig, 'headers'> & {
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
secretHeaders: string[];
|
|
25
|
+
urlSecretSet: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare function toWebhookView(webhook: WebhookConfig): WebhookView;
|
|
28
|
+
/**
|
|
29
|
+
* A webhook address in two halves: the origin (scheme://host:port), which is shown and editable, and the rest
|
|
30
|
+
* (path and query, where a token usually sits), which is never shown. An address that does not parse is all secret.
|
|
31
|
+
*/
|
|
32
|
+
export declare function splitUrl(url: string): {
|
|
33
|
+
origin: string;
|
|
34
|
+
secret: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The address a webhook write leaves. A bare origin on the SAME origin keeps the stored path and query (an echoed
|
|
38
|
+
* view); a bare origin on another host means the address is that origin, so a token never follows to a new host. A
|
|
39
|
+
* full address replaces both. An absent or empty one keeps what is stored.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeWebhookUrl(stored: string, incoming: unknown): string;
|
|
42
|
+
/**
|
|
43
|
+
* The headers a save leaves: the ones in `incoming`, where a credential header sent empty keeps its stored
|
|
44
|
+
* value. A name absent from `incoming` is removed, which is the explicit clear.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mergeHeaders(stored: Record<string, string>, incoming: unknown): Record<string, string>;
|
|
47
|
+
/** A generic site as the API answers it: header names and plain values are shown, a credential header's value never. */
|
|
48
|
+
export type SiteView = Omit<GenericSiteConfig, 'headers'> & {
|
|
49
|
+
headers?: Record<string, string>;
|
|
50
|
+
secretHeaders?: string[];
|
|
51
|
+
};
|
|
52
|
+
export declare function toSiteView(site: GenericSiteConfig): SiteView;
|
|
53
|
+
/** A site as a write carries it: the view-only field dropped, the headers merged over the stored ones. */
|
|
54
|
+
export declare function siteFromWrite(body: Partial<GenericSiteConfig> & {
|
|
55
|
+
secretHeaders?: unknown;
|
|
56
|
+
}, stored?: GenericSiteConfig): Partial<GenericSiteConfig>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCredentialHeader = exports.isCredentialName = exports.SETTINGS_SECRET_KEYS = void 0;
|
|
4
|
+
exports.toSettingsView = toSettingsView;
|
|
5
|
+
exports.parseSettingsBody = parseSettingsBody;
|
|
6
|
+
exports.toWebhookView = toWebhookView;
|
|
7
|
+
exports.splitUrl = splitUrl;
|
|
8
|
+
exports.mergeWebhookUrl = mergeWebhookUrl;
|
|
9
|
+
exports.mergeHeaders = mergeHeaders;
|
|
10
|
+
exports.toSiteView = toSiteView;
|
|
11
|
+
exports.siteFromWrite = siteFromWrite;
|
|
12
|
+
/**
|
|
13
|
+
* What the HTTP API shows of a credential: whether it is set, never the value. A credential is
|
|
14
|
+
* written only when typed (an empty field keeps the stored one) and removed by an explicit clear.
|
|
15
|
+
*/
|
|
16
|
+
exports.SETTINGS_SECRET_KEYS = ['sonarrApiKey', 'radarrApiKey', 'plexToken'];
|
|
17
|
+
function toSettingsView(settings) {
|
|
18
|
+
return {
|
|
19
|
+
...settings,
|
|
20
|
+
sonarrApiKey: '',
|
|
21
|
+
radarrApiKey: '',
|
|
22
|
+
plexToken: '',
|
|
23
|
+
sonarrApiKeySet: settings.sonarrApiKey !== '',
|
|
24
|
+
radarrApiKeySet: settings.radarrApiKey !== '',
|
|
25
|
+
plexTokenSet: settings.plexToken !== '',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The partial settings a PATCH body asks for. The view-only `<name>Set` flags are dropped, an empty
|
|
30
|
+
* credential keeps the stored one, and `clear<Name>: true` removes it.
|
|
31
|
+
*/
|
|
32
|
+
function parseSettingsBody(body) {
|
|
33
|
+
const raw = typeof body === 'object' && body !== null && !Array.isArray(body) ? { ...body } : {};
|
|
34
|
+
for (const key of exports.SETTINGS_SECRET_KEYS) {
|
|
35
|
+
const clear = `clear${key[0].toUpperCase()}${key.slice(1)}`;
|
|
36
|
+
const cleared = raw[clear] === true;
|
|
37
|
+
delete raw[`${key}Set`];
|
|
38
|
+
delete raw[clear];
|
|
39
|
+
if (cleared)
|
|
40
|
+
raw[key] = '';
|
|
41
|
+
else if (raw[key] === '' || raw[key] === undefined || raw[key] === null)
|
|
42
|
+
delete raw[key];
|
|
43
|
+
}
|
|
44
|
+
return raw;
|
|
45
|
+
}
|
|
46
|
+
/** A header whose value carries a credential: it is never shown, only its name. */
|
|
47
|
+
const CREDENTIAL_NAME = /auth|key|token|secret|pass|cookie|sign|cred|session/i;
|
|
48
|
+
/** A name that reads like a credential: Authorization, X-Auth-User, X-Api-Key, Cookie, X-Session-Id, a plugin's `apiToken`. Over-matching is safe: such a value is only hidden, and a typed one still goes through. */
|
|
49
|
+
const isCredentialName = (name) => CREDENTIAL_NAME.test(name);
|
|
50
|
+
exports.isCredentialName = isCredentialName;
|
|
51
|
+
exports.isCredentialHeader = exports.isCredentialName;
|
|
52
|
+
function toWebhookView(webhook) {
|
|
53
|
+
const secretHeaders = Object.keys(webhook.headers).filter(exports.isCredentialHeader);
|
|
54
|
+
const headers = Object.fromEntries(Object.entries(webhook.headers).map(([name, value]) => [name, (0, exports.isCredentialHeader)(name) ? '' : value]));
|
|
55
|
+
const { origin, secret } = splitUrl(webhook.url);
|
|
56
|
+
return { ...webhook, url: origin, urlSecretSet: secret !== '', headers, secretHeaders };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A webhook address in two halves: the origin (scheme://host:port), which is shown and editable, and the rest
|
|
60
|
+
* (path and query, where a token usually sits), which is never shown. An address that does not parse is all secret.
|
|
61
|
+
*/
|
|
62
|
+
function splitUrl(url) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = new URL(url);
|
|
65
|
+
const rest = `${parsed.pathname === '/' ? '' : parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
66
|
+
return { origin: parsed.origin, secret: rest };
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return { origin: '', secret: url };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The address a webhook write leaves. A bare origin on the SAME origin keeps the stored path and query (an echoed
|
|
74
|
+
* view); a bare origin on another host means the address is that origin, so a token never follows to a new host. A
|
|
75
|
+
* full address replaces both. An absent or empty one keeps what is stored.
|
|
76
|
+
*/
|
|
77
|
+
function mergeWebhookUrl(stored, incoming) {
|
|
78
|
+
if (typeof incoming !== 'string' || incoming === '')
|
|
79
|
+
return stored;
|
|
80
|
+
const next = splitUrl(incoming);
|
|
81
|
+
if (next.origin === '' || next.secret !== '')
|
|
82
|
+
return incoming;
|
|
83
|
+
const prior = splitUrl(stored);
|
|
84
|
+
return prior.origin === next.origin ? `${next.origin}${prior.secret}` : next.origin;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The headers a save leaves: the ones in `incoming`, where a credential header sent empty keeps its stored
|
|
88
|
+
* value. A name absent from `incoming` is removed, which is the explicit clear.
|
|
89
|
+
*/
|
|
90
|
+
function mergeHeaders(stored, incoming) {
|
|
91
|
+
if (typeof incoming !== 'object' || incoming === null || Array.isArray(incoming))
|
|
92
|
+
return stored;
|
|
93
|
+
const out = {};
|
|
94
|
+
for (const [name, value] of Object.entries(incoming)) {
|
|
95
|
+
if (typeof value !== 'string')
|
|
96
|
+
continue;
|
|
97
|
+
if (value === '' && (0, exports.isCredentialHeader)(name)) {
|
|
98
|
+
// an empty credential keeps the stored value; with none stored there is nothing to keep, so it is not saved as a literal empty header
|
|
99
|
+
if (name in stored)
|
|
100
|
+
out[name] = stored[name];
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
out[name] = value;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function toSiteView(site) {
|
|
108
|
+
if (!site.headers || Object.keys(site.headers).length === 0)
|
|
109
|
+
return site;
|
|
110
|
+
const secretHeaders = Object.keys(site.headers).filter(exports.isCredentialHeader);
|
|
111
|
+
const headers = Object.fromEntries(Object.entries(site.headers).map(([name, value]) => [name, (0, exports.isCredentialHeader)(name) ? '' : value]));
|
|
112
|
+
return { ...site, headers, secretHeaders };
|
|
113
|
+
}
|
|
114
|
+
/** A site as a write carries it: the view-only field dropped, the headers merged over the stored ones. */
|
|
115
|
+
function siteFromWrite(body, stored) {
|
|
116
|
+
const { secretHeaders: _view, headers, ...rest } = body;
|
|
117
|
+
if (headers === undefined)
|
|
118
|
+
return rest;
|
|
119
|
+
return { ...rest, headers: mergeHeaders(stored?.headers ?? {}, headers) };
|
|
120
|
+
}
|
|
@@ -2,11 +2,13 @@ import { OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
|
|
|
2
2
|
import type { Binaries, WireproxyBinary } from '../ports/binaries';
|
|
3
3
|
import type { HostInfo } from '../ports/host-info';
|
|
4
4
|
import { Dispatcher } from 'undici';
|
|
5
|
-
import { EgressType, VpnSettings, WireguardEgress } from '../types';
|
|
5
|
+
import { Egress, EgressType, VpnSettings, WireguardEgress } from '../types';
|
|
6
6
|
import { VpnProvidersRepository } from '../repositories/vpn-providers.repository';
|
|
7
7
|
import { VpnSettingsRepository } from '../repositories/vpn-settings.repository';
|
|
8
8
|
import { ActiveBlock, BlockSelector } from './egress/block-registry';
|
|
9
9
|
import { ActiveEgress } from './download-tracker.service';
|
|
10
|
+
import { LeakVerdict } from './egress/leak-guard';
|
|
11
|
+
import type { ExitPurpose } from './egress/egress-context';
|
|
10
12
|
import { EgressGate } from './egress/egress-gate';
|
|
11
13
|
import { SupervisorState, WireproxySupervisor } from './egress/wireproxy-supervisor';
|
|
12
14
|
export interface VpnTestResult {
|
|
@@ -21,6 +23,8 @@ export interface ExitStatus {
|
|
|
21
23
|
type: EgressType;
|
|
22
24
|
ready: boolean;
|
|
23
25
|
error?: string;
|
|
26
|
+
/** Last leak-guard verdict; `home` = home IP on purpose (hoster link resolution and captcha only). */
|
|
27
|
+
verdict?: LeakVerdict;
|
|
24
28
|
}
|
|
25
29
|
export interface VpnStatus {
|
|
26
30
|
strictMode: boolean;
|
|
@@ -67,6 +71,7 @@ export declare class VpnService implements OnApplicationBootstrap, OnModuleDestr
|
|
|
67
71
|
private settings;
|
|
68
72
|
private tunnels;
|
|
69
73
|
private readonly leakFlagged;
|
|
74
|
+
private readonly homeWarned;
|
|
70
75
|
private leakTimer;
|
|
71
76
|
private gateRetryTimer;
|
|
72
77
|
/** The last leak-check answer per exit. Absent means unknown: nothing has compared its IP yet. */
|
|
@@ -92,7 +97,7 @@ export declare class VpnService implements OnApplicationBootstrap, OnModuleDestr
|
|
|
92
97
|
* that produced its link. A pinned exit that is gone or not ready fails the
|
|
93
98
|
* download: it never falls back to the routed or direct network.
|
|
94
99
|
*/
|
|
95
|
-
getDispatcherForExit(egressId: string): Dispatcher;
|
|
100
|
+
getDispatcherForExit(egressId: string, purpose?: ExitPurpose): Dispatcher;
|
|
96
101
|
/** HTTP proxy URL on 127.0.0.1 for ffmpeg `-http_proxy`; undefined only for an explicit direct exit or no chain. */
|
|
97
102
|
getFfmpegProxyUrl(url: string, egressId?: string): string | undefined;
|
|
98
103
|
/**
|
|
@@ -177,4 +182,6 @@ export declare class VpnService implements OnApplicationBootstrap, OnModuleDestr
|
|
|
177
182
|
private updateGate;
|
|
178
183
|
protected runTest(dispatcher: Dispatcher): Promise<VpnTestResult>;
|
|
179
184
|
}
|
|
185
|
+
/** The operator ran this exit on the home connection on purpose (hoster link resolution and captcha only). */
|
|
186
|
+
export declare function isHomeByDesign(egress: Egress): boolean;
|
|
180
187
|
export {};
|