@tiledesk/tiledesk-server 3.3.5 → 3.5.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/app.js +7 -0
  3. package/deploynew.sh +7 -1
  4. package/docs/activities-client.md +27 -0
  5. package/docs/mcp-oauth2-it.md +279 -0
  6. package/docs/mcp-oauth2.md +279 -0
  7. package/docs/numeric-input-validation.md +91 -0
  8. package/docs/superpowers/plans/2026-11-10-mcp-oauth2-server-it.md +155 -0
  9. package/docs/superpowers/plans/2026-11-10-mcp-oauth2-server.md +155 -0
  10. package/docs/superpowers/plans/2026-11-10-mcp-oauth2-tybot-it.md +63 -0
  11. package/docs/superpowers/plans/2026-11-10-mcp-oauth2-tybot.md +63 -0
  12. package/docs/superpowers/specs/2026-11-10-mcp-oauth2-design-it.md +207 -0
  13. package/docs/superpowers/specs/2026-11-10-mcp-oauth2-design.md +207 -0
  14. package/jobs.js +15 -0
  15. package/models/mcpOAuthConnection.js +131 -0
  16. package/models/request.js +8 -0
  17. package/package.json +1 -1
  18. package/pubmodules/activities/activityMessageUtil.js +137 -0
  19. package/pubmodules/activities/models/activity.js +2 -0
  20. package/pubmodules/activities/routes/activity.js +39 -11
  21. package/pubmodules/activities/test/execution-filter.test.js +133 -0
  22. package/pubmodules/activities/test/execution-messages.test.js +158 -0
  23. package/pubmodules/canned/cannedResponseRoute.js +6 -9
  24. package/pubmodules/events/eventRoute.js +6 -9
  25. package/pubmodules/executions-publisher/index.js +457 -0
  26. package/pubmodules/executions-publisher/test/audit-consumer.test.js +384 -0
  27. package/pubmodules/executions-publisher/test/executions-publisher.test.js +204 -0
  28. package/pubmodules/pubModulesManager.js +12 -0
  29. package/routes/answered.js +7 -3
  30. package/routes/campaigns.js +7 -3
  31. package/routes/department.js +14 -3
  32. package/routes/executions-refire.js +148 -0
  33. package/routes/faq.js +6 -14
  34. package/routes/filesp.js +9 -4
  35. package/routes/kb.js +40 -15
  36. package/routes/lead.js +23 -28
  37. package/routes/logs.js +8 -1
  38. package/routes/mcp.js +11 -8
  39. package/routes/mcpOAuth.js +133 -0
  40. package/routes/mcpOAuthCallback.js +75 -0
  41. package/routes/message.js +3 -1
  42. package/routes/messagesRoot.js +5 -18
  43. package/routes/project.js +57 -12
  44. package/routes/project_user.js +21 -4
  45. package/routes/property.js +18 -20
  46. package/routes/request.js +36 -45
  47. package/routes/roles.js +8 -18
  48. package/routes/segment.js +8 -18
  49. package/routes/subscription.js +4 -5
  50. package/routes/tag.js +6 -9
  51. package/routes/unanswered.js +7 -3
  52. package/routes/user-request.js +29 -34
  53. package/routes/webhook.js +120 -54
  54. package/services/mcpOAuthDiscovery.js +248 -0
  55. package/services/mcpOAuthGoogleScopes.js +55 -0
  56. package/services/mcpOAuthService.js +732 -0
  57. package/services/mcpService.js +111 -15
  58. package/services/requestService.js +4 -2
  59. package/services/webhookService.js +4 -2
  60. package/test/executions-refire.test.js +362 -0
  61. package/test/kbRoute.js +4 -7
  62. package/test/mcpOAuthDiscovery.test.js +331 -0
  63. package/test/mcpOAuthGoogleScopes.test.js +25 -0
  64. package/test/mcpOAuthRoute.test.js +455 -0
  65. package/test/mcpOAuthService.test.js +693 -0
  66. package/test/mcpOAuthUtils.test.js +348 -0
  67. package/test/mcpServiceOAuth.test.js +267 -0
  68. package/test/numericInput.js +137 -0
  69. package/test/requestRoute.js +57 -0
  70. package/test/webhookConversationRoute.js +51 -0
  71. package/utils/logRedactor.js +4 -2
  72. package/utils/mcpOAuthCrypto.js +69 -0
  73. package/utils/mcpOAuthPkce.js +20 -0
  74. package/utils/numericInput.js +200 -0
  75. package/utils/outboundUrlGuard.js +131 -0
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ const dns = require('dns');
4
+ const http = require('http');
5
+ const https = require('https');
6
+ const net = require('net');
7
+
8
+ const TIMEOUT_MS = 10000;
9
+ const MAX_CONTENT_LENGTH = 1024 * 1024;
10
+
11
+ const blockedAddresses = new net.BlockList();
12
+ [
13
+ ['0.0.0.0', 8],
14
+ ['10.0.0.0', 8],
15
+ ['100.64.0.0', 10],
16
+ ['127.0.0.0', 8],
17
+ ['169.254.0.0', 16],
18
+ ['172.16.0.0', 12],
19
+ ['192.168.0.0', 16],
20
+ ['224.0.0.0', 4],
21
+ ['240.0.0.0', 4]
22
+ ].forEach(([address, prefix]) => blockedAddresses.addSubnet(address, prefix, 'ipv4'));
23
+ [
24
+ ['::', 128],
25
+ ['::1', 128],
26
+ ['fc00::', 7],
27
+ ['fe80::', 10],
28
+ ['ff00::', 8]
29
+ ].forEach(([address, prefix]) => blockedAddresses.addSubnet(address, prefix, 'ipv6'));
30
+
31
+ function insecureAllowed() {
32
+ return process.env.MCP_OAUTH_ALLOW_INSECURE_URLS === 'true';
33
+ }
34
+
35
+ function notAllowed(reason) {
36
+ const error = new Error('URL not allowed: ' + reason);
37
+ error.status = 400;
38
+ error.code = 'bad_request';
39
+ return error;
40
+ }
41
+
42
+ function isBlockedAddress(address) {
43
+ const version = net.isIP(address);
44
+ if (version === 0) {
45
+ return true;
46
+ }
47
+ return blockedAddresses.check(address, version === 6 ? 'ipv6' : 'ipv4');
48
+ }
49
+
50
+ async function resolveHost(host) {
51
+ try {
52
+ const results = await dns.promises.lookup(host, { all: true });
53
+ return results.map((result) => result.address);
54
+ } catch (error) {
55
+ throw notAllowed('host cannot be resolved');
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Checks a user-influenced URL before the server calls it: https only, and the
61
+ * host must not resolve to a loopback, private, link-local or reserved address.
62
+ * MCP_OAUTH_ALLOW_INSECURE_URLS=true (dev/test only) allows http and any host.
63
+ */
64
+ async function assertAllowed(rawUrl) {
65
+ let url;
66
+ try {
67
+ url = new URL(rawUrl);
68
+ } catch (error) {
69
+ throw notAllowed('invalid URL');
70
+ }
71
+
72
+ if (insecureAllowed()) {
73
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') {
74
+ throw notAllowed('unsupported protocol');
75
+ }
76
+ return url;
77
+ }
78
+
79
+ if (url.protocol !== 'https:') {
80
+ throw notAllowed('https is required');
81
+ }
82
+ if (url.username || url.password) {
83
+ throw notAllowed('credentials in URL');
84
+ }
85
+
86
+ const host = url.hostname.replace(/^\[|\]$/g, '');
87
+ const addresses = net.isIP(host) ? [host] : await resolveHost(host);
88
+ if (addresses.length === 0 || addresses.some(isBlockedAddress)) {
89
+ throw notAllowed('private or reserved address');
90
+ }
91
+ return url;
92
+ }
93
+
94
+ // Checked again at connect time: the DNS answer can change after assertAllowed.
95
+ function guardedLookup(hostname, options, callback) {
96
+ if (typeof options === 'function') {
97
+ callback = options;
98
+ options = {};
99
+ }
100
+ dns.lookup(hostname, { ...options, all: true }, (error, addresses) => {
101
+ if (error) {
102
+ return callback(error);
103
+ }
104
+ if (addresses.length === 0 || addresses.some((entry) => isBlockedAddress(entry.address))) {
105
+ return callback(notAllowed('private or reserved address'));
106
+ }
107
+ if (options.all) {
108
+ return callback(null, addresses);
109
+ }
110
+ callback(null, addresses[0].address, addresses[0].family);
111
+ });
112
+ }
113
+
114
+ const guardedHttpAgent = new http.Agent({ lookup: guardedLookup });
115
+ const guardedHttpsAgent = new https.Agent({ lookup: guardedLookup });
116
+
117
+ /** axios options for requests to user-influenced URLs. */
118
+ function httpOptions() {
119
+ const options = {
120
+ maxRedirects: 0,
121
+ timeout: TIMEOUT_MS,
122
+ maxContentLength: MAX_CONTENT_LENGTH
123
+ };
124
+ if (!insecureAllowed()) {
125
+ options.httpAgent = guardedHttpAgent;
126
+ options.httpsAgent = guardedHttpsAgent;
127
+ }
128
+ return options;
129
+ }
130
+
131
+ module.exports = { assertAllowed, httpOptions, isBlockedAddress, guardedLookup };