@kosha-ai/server 0.4.1 → 0.5.0

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.
@@ -38,9 +38,13 @@ export declare class ConfigurationsService {
38
38
  */
39
39
  getWithCredentials(provider: string, configurationId: string): Promise<ConfigurationWithCredentials>;
40
40
  /**
41
- * Refuses a URL the server would later be made to fetch from inside its own
42
- * network. Checked when saved so an operator sees why, and again on every
43
- * proxied call, since what a hostname resolves to can change.
41
+ * Refuses a value an operator should be told about now rather than by a
42
+ * failure later: a URL that would have the server fetch cloud metadata, or
43
+ * a value the package says is malformed.
44
+ *
45
+ * Both are checked again at the point of use. A hostname can resolve
46
+ * somewhere else tomorrow, and a value saved before a pattern was added has
47
+ * never been through it.
44
48
  */
45
49
  private checkedFields;
46
50
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EACjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,GAAG;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wEAAwE;AACxE,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,qBAAqB,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,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;;;;OAIG;YACW,aAAa;IAqB3B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
1
+ {"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EACjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,GAAG;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wEAAwE;AACxE,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,qBAAqB,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,qBACa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAHR,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,mBAAmB;IAGhD;;;;;OAKG;IACG,IAAI,CACR,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAkB9B,GAAG,CACP,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,sBAAsB,CAAC;IAc5B,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,sBAAsB,CAAC;IA0C5B,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,sBAAsB,CAAC;IAkBlC,yDAAyD;IACnD,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC;IAMhB;;;OAGG;IACG,kBAAkB,CACtB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,4BAA4B,CAAC;IAmBxC;;;;;;;;OAQG;YACW,aAAa;IAkC3B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
@@ -1,6 +1,6 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { BadRequestException, ConflictException, Injectable, NotFoundException, } from '@nestjs/common';
3
- import { assertPublicHost, assertPublicUrl } from '@kosha-ai/integration-sdk';
3
+ import { assertAllowedHost, assertAllowedUrl } from '@kosha-ai/integration-sdk';
4
4
  import { CryptoService } from '../crypto/crypto.service.js';
5
5
  import { EnvironmentsService } from '../environments/environments.service.js';
6
6
  import { IntegrationRegistry } from '../integrations/integration.registry.js';
@@ -99,22 +99,33 @@ let ConfigurationsService = class ConfigurationsService {
99
99
  };
100
100
  }
101
101
  /**
102
- * Refuses a URL the server would later be made to fetch from inside its own
103
- * network. Checked when saved so an operator sees why, and again on every
104
- * proxied call, since what a hostname resolves to can change.
102
+ * Refuses a value an operator should be told about now rather than by a
103
+ * failure later: a URL that would have the server fetch cloud metadata, or
104
+ * a value the package says is malformed.
105
+ *
106
+ * Both are checked again at the point of use. A hostname can resolve
107
+ * somewhere else tomorrow, and a value saved before a pattern was added has
108
+ * never been through it.
105
109
  */
106
110
  async checkedFields(integration, fields) {
107
111
  for (const field of integration.configFields ?? []) {
108
112
  const value = fields?.[field.key];
109
113
  if (typeof value !== 'string')
110
114
  continue;
115
+ // Anchored here rather than trusting the package to have done it: an
116
+ // unanchored `[a-z]+` matches inside `acme/evil`, so a pattern meant to
117
+ // constrain a value would quietly accept one that escapes it.
118
+ if (field.pattern !== undefined &&
119
+ !new RegExp(`^(?:${field.pattern})$`).test(value)) {
120
+ throw new BadRequestException(`${field.label} is not in the expected format`);
121
+ }
111
122
  if (field.type !== 'url' && field.type !== 'host')
112
123
  continue;
113
124
  try {
114
125
  if (field.type === 'url')
115
- await assertPublicUrl(value);
126
+ await assertAllowedUrl(value);
116
127
  else
117
- await assertPublicHost(value);
128
+ await assertAllowedHost(value);
118
129
  }
119
130
  catch (error) {
120
131
  throw new BadRequestException(error instanceof Error ? error.message : `${field.label} is invalid`);
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { assertPublicUrl } from '@kosha-ai/integration-sdk';
2
+ import { assertAllowedUrl } from '@kosha-ai/integration-sdk';
3
3
  import { BadGatewayException, BadRequestException, Injectable, NotFoundException, } from '@nestjs/common';
4
4
  import { CredentialsService } from '../credentials/credentials.service.js';
5
5
  import { EnvironmentsService } from '../environments/environments.service.js';
@@ -87,9 +87,9 @@ let ProxyService = class ProxyService {
87
87
  throw new BadGatewayException('Provider has no resolvable base URL for this connection');
88
88
  }
89
89
  // Re-resolved per call, not only when saved: a host that answered
90
- // publicly yesterday can point inside the network today.
90
+ // elsewhere yesterday can point at cloud metadata today.
91
91
  if (resolved)
92
- await assertPublicUrl(baseUrl);
92
+ await assertAllowedUrl(baseUrl);
93
93
  const targetUrl = this.buildTargetUrl(baseUrl, request);
94
94
  /*
95
95
  * Header names are compared lowercased, and the integration's headers are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosha-ai/server",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Kosha server: OAuth handshake, encrypted credential storage, token refresh, and an authenticated request proxy for third-party integrations",
5
5
  "keywords": [
6
6
  "kosha",
@@ -109,7 +109,7 @@
109
109
  "rxjs": "^7.8.0",
110
110
  "tslib": "^2.3.0",
111
111
  "zod": "4.5.4",
112
- "@kosha-ai/integration-sdk": "0.4.1"
112
+ "@kosha-ai/integration-sdk": "0.5.0"
113
113
  },
114
114
  "devDependencies": {
115
115
  "@nestjs/testing": "^11.0.0",
@@ -117,7 +117,7 @@
117
117
  "@types/node-forge": "^1.3.14",
118
118
  "@types/pg": "^8.23.1",
119
119
  "prisma": "^7.10.0",
120
- "@kosha-ai/integration-github": "0.4.1",
121
- "@kosha-ai/integration-slack": "0.4.1"
120
+ "@kosha-ai/integration-github": "0.5.0",
121
+ "@kosha-ai/integration-slack": "0.5.0"
122
122
  }
123
123
  }