@contember/engine-http 2.2.0-alpha.17 → 2.2.0-alpha.18

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 (134) hide show
  1. package/dist/development/index.cjs +3 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +3 -0
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/MasterContainer.cjs +5 -4
  6. package/dist/development/src/MasterContainer.cjs.map +1 -1
  7. package/dist/development/src/MasterContainer.js +5 -4
  8. package/dist/development/src/MasterContainer.js.map +1 -1
  9. package/dist/development/src/application/PanelApiMount.cjs.map +1 -1
  10. package/dist/development/src/application/PanelApiMount.js.map +1 -1
  11. package/dist/development/src/application/application.cjs +19 -12
  12. package/dist/development/src/application/application.cjs.map +1 -1
  13. package/dist/development/src/application/application.js +19 -12
  14. package/dist/development/src/application/application.js.map +1 -1
  15. package/dist/development/src/application/requestBodyMasking.cjs +97 -0
  16. package/dist/development/src/application/requestBodyMasking.cjs.map +1 -0
  17. package/dist/development/src/application/requestBodyMasking.js +97 -0
  18. package/dist/development/src/application/requestBodyMasking.js.map +1 -0
  19. package/dist/development/src/config/configSchema.cjs +28 -0
  20. package/dist/development/src/config/configSchema.cjs.map +1 -1
  21. package/dist/development/src/config/configSchema.js +28 -0
  22. package/dist/development/src/config/configSchema.js.map +1 -1
  23. package/dist/development/src/config/configTemplate.cjs +5 -0
  24. package/dist/development/src/config/configTemplate.cjs.map +1 -1
  25. package/dist/development/src/config/configTemplate.js +5 -0
  26. package/dist/development/src/config/configTemplate.js.map +1 -1
  27. package/dist/development/src/content/ProjectMembershipResolver.cjs +10 -3
  28. package/dist/development/src/content/ProjectMembershipResolver.cjs.map +1 -1
  29. package/dist/development/src/content/ProjectMembershipResolver.js +10 -3
  30. package/dist/development/src/content/ProjectMembershipResolver.js.map +1 -1
  31. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +2 -1
  32. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  33. package/dist/development/src/projectGroup/ProjectGroupContainer.js +2 -1
  34. package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  35. package/dist/development/src/transfer/ImportExecutor.cjs +15 -2
  36. package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
  37. package/dist/development/src/transfer/ImportExecutor.js +15 -2
  38. package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
  39. package/dist/development/src/utils/CryptoWrapper.cjs +11 -0
  40. package/dist/development/src/utils/CryptoWrapper.cjs.map +1 -1
  41. package/dist/development/src/utils/CryptoWrapper.js +11 -0
  42. package/dist/development/src/utils/CryptoWrapper.js.map +1 -1
  43. package/dist/development/src/utils/sentry.cjs +1 -0
  44. package/dist/development/src/utils/sentry.cjs.map +1 -1
  45. package/dist/development/src/utils/sentry.js +1 -0
  46. package/dist/development/src/utils/sentry.js.map +1 -1
  47. package/dist/production/index.cjs +3 -0
  48. package/dist/production/index.cjs.map +1 -1
  49. package/dist/production/index.js +3 -0
  50. package/dist/production/index.js.map +1 -1
  51. package/dist/production/src/MasterContainer.cjs +5 -4
  52. package/dist/production/src/MasterContainer.cjs.map +1 -1
  53. package/dist/production/src/MasterContainer.js +5 -4
  54. package/dist/production/src/MasterContainer.js.map +1 -1
  55. package/dist/production/src/application/PanelApiMount.cjs.map +1 -1
  56. package/dist/production/src/application/PanelApiMount.js.map +1 -1
  57. package/dist/production/src/application/application.cjs +19 -12
  58. package/dist/production/src/application/application.cjs.map +1 -1
  59. package/dist/production/src/application/application.js +19 -12
  60. package/dist/production/src/application/application.js.map +1 -1
  61. package/dist/production/src/application/requestBodyMasking.cjs +97 -0
  62. package/dist/production/src/application/requestBodyMasking.cjs.map +1 -0
  63. package/dist/production/src/application/requestBodyMasking.js +97 -0
  64. package/dist/production/src/application/requestBodyMasking.js.map +1 -0
  65. package/dist/production/src/config/configSchema.cjs +28 -0
  66. package/dist/production/src/config/configSchema.cjs.map +1 -1
  67. package/dist/production/src/config/configSchema.js +28 -0
  68. package/dist/production/src/config/configSchema.js.map +1 -1
  69. package/dist/production/src/config/configTemplate.cjs +5 -0
  70. package/dist/production/src/config/configTemplate.cjs.map +1 -1
  71. package/dist/production/src/config/configTemplate.js +5 -0
  72. package/dist/production/src/config/configTemplate.js.map +1 -1
  73. package/dist/production/src/content/ProjectMembershipResolver.cjs +10 -3
  74. package/dist/production/src/content/ProjectMembershipResolver.cjs.map +1 -1
  75. package/dist/production/src/content/ProjectMembershipResolver.js +10 -3
  76. package/dist/production/src/content/ProjectMembershipResolver.js.map +1 -1
  77. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +2 -1
  78. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  79. package/dist/production/src/projectGroup/ProjectGroupContainer.js +2 -1
  80. package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  81. package/dist/production/src/transfer/ImportExecutor.cjs +15 -2
  82. package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
  83. package/dist/production/src/transfer/ImportExecutor.js +15 -2
  84. package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
  85. package/dist/production/src/utils/CryptoWrapper.cjs +11 -0
  86. package/dist/production/src/utils/CryptoWrapper.cjs.map +1 -1
  87. package/dist/production/src/utils/CryptoWrapper.js +11 -0
  88. package/dist/production/src/utils/CryptoWrapper.js.map +1 -1
  89. package/dist/production/src/utils/sentry.cjs +1 -0
  90. package/dist/production/src/utils/sentry.cjs.map +1 -1
  91. package/dist/production/src/utils/sentry.js +1 -0
  92. package/dist/production/src/utils/sentry.js.map +1 -1
  93. package/dist/tests/cases/unit/requestBodyLogging.test.d.ts +2 -0
  94. package/dist/tests/cases/unit/requestBodyLogging.test.d.ts.map +1 -0
  95. package/dist/tests/cases/unit/requestBodyMasking.test.d.ts +2 -0
  96. package/dist/tests/cases/unit/requestBodyMasking.test.d.ts.map +1 -0
  97. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  98. package/dist/types/MasterContainer.d.ts +7 -0
  99. package/dist/types/MasterContainer.d.ts.map +1 -1
  100. package/dist/types/application/PanelApiMount.d.ts +2 -0
  101. package/dist/types/application/PanelApiMount.d.ts.map +1 -1
  102. package/dist/types/application/application.d.ts +7 -1
  103. package/dist/types/application/application.d.ts.map +1 -1
  104. package/dist/types/application/index.d.ts +1 -0
  105. package/dist/types/application/index.d.ts.map +1 -1
  106. package/dist/types/application/requestBodyMasking.d.ts +10 -0
  107. package/dist/types/application/requestBodyMasking.d.ts.map +1 -0
  108. package/dist/types/config/configSchema.d.ts +10 -0
  109. package/dist/types/config/configSchema.d.ts.map +1 -1
  110. package/dist/types/config/configTemplate.d.ts.map +1 -1
  111. package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
  112. package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
  113. package/dist/types/transfer/ImportExecutor.d.ts +2 -0
  114. package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
  115. package/dist/types/tsconfig.tsbuildinfo +1 -1
  116. package/dist/types/utils/CryptoWrapper.d.ts +5 -0
  117. package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
  118. package/package.json +16 -16
  119. package/src/MasterContainer.ts +5 -3
  120. package/src/application/PanelApiMount.ts +2 -0
  121. package/src/application/application.ts +30 -11
  122. package/src/application/index.ts +1 -0
  123. package/src/application/requestBodyMasking.ts +117 -0
  124. package/src/config/configSchema.ts +30 -0
  125. package/src/config/configTemplate.ts +5 -0
  126. package/src/content/ProjectMembershipResolver.ts +13 -5
  127. package/src/projectGroup/ProjectGroupContainer.ts +1 -0
  128. package/src/transfer/ImportExecutor.ts +16 -2
  129. package/src/utils/CryptoWrapper.ts +12 -0
  130. package/tests/cases/unit/crypto.test.ts +16 -0
  131. package/tests/cases/unit/projectMembershipResolver.test.ts +50 -0
  132. package/tests/cases/unit/requestBodyLogging.test.ts +89 -0
  133. package/tests/cases/unit/requestBodyMasking.test.ts +102 -0
  134. package/tests/cases/unit/serverConfig.test.ts +23 -0
@@ -0,0 +1,89 @@
1
+ import { expect, test } from 'bun:test'
2
+ import { createLogger, TestLoggerHandler } from '@contember/logger'
3
+ import { VerifyResult } from '@contember/engine-tenant-api'
4
+ import { Application, LoggerRequestBody } from '../../../src/application/application.js'
5
+ import { Authenticator } from '../../../src/common/Authorizator.js'
6
+ import { HttpResponse } from '../../../src/common/HttpResponse.js'
7
+ import { serverConfigSchema } from '../../../src/config/configSchema.js'
8
+ import { ProjectGroupContainer } from '../../../src/projectGroup/ProjectGroupContainer.js'
9
+ import { ProjectGroupResolver } from '../../../src/projectGroup/ProjectGroupResolver.js'
10
+ import { createMock } from '../../utils.js'
11
+
12
+ const unavailable = (): never => {
13
+ throw new Error('This service is not available in the request logging test')
14
+ }
15
+
16
+ const createTestApplication = () => {
17
+ const loggerHandler = new TestLoggerHandler()
18
+ const logger = createLogger(loggerHandler)
19
+ const groupContainer: ProjectGroupContainer = {
20
+ slug: 'group',
21
+ logger,
22
+ authenticator: createMock<Authenticator>({
23
+ authenticate: async () => new VerifyResult('identity', 'api-key', ['person'], null),
24
+ }),
25
+ get projectMembershipResolver() {
26
+ return unavailable()
27
+ },
28
+ get projectContainerResolver() {
29
+ return unavailable()
30
+ },
31
+ get projectSchemaResolver() {
32
+ return unavailable()
33
+ },
34
+ get projectInitializer() {
35
+ return unavailable()
36
+ },
37
+ get tenantContainer() {
38
+ return unavailable()
39
+ },
40
+ get tenantGraphQLHandler() {
41
+ return unavailable()
42
+ },
43
+ get systemContainer() {
44
+ return unavailable()
45
+ },
46
+ get systemGraphQLHandler() {
47
+ return unavailable()
48
+ },
49
+ }
50
+ const projectGroupResolver = createMock<ProjectGroupResolver>({
51
+ resolveContainer: async () => groupContainer,
52
+ })
53
+ const application = new Application(projectGroupResolver, serverConfigSchema({ port: 0 }), false, undefined, logger)
54
+ return { application, loggerHandler }
55
+ }
56
+
57
+ test('request logs and error reports carry the body with credentials masked', async () => {
58
+ const { application, loggerHandler } = createTestApplication()
59
+ application.addRoute('tenant', '/tenant', ({ logger }) => {
60
+ // An error flushes the request's buffered debug entries, which is where the body used to appear.
61
+ logger.error(new Error('Resolver failed'))
62
+ return new HttpResponse(200, 'ok')
63
+ }, { carriesCredentials: true })
64
+ const running = await application.listen()
65
+ const address = running.server.address()
66
+ try {
67
+ if (address === null || typeof address === 'string') {
68
+ throw new Error('The test server did not bind to a TCP port')
69
+ }
70
+ const query = 'mutation SignIn($email: String!, $password: String!) { signIn(email: $email, password: $password) { ok } }'
71
+ const response = await fetch(`http://127.0.0.1:${address.port}/tenant`, {
72
+ method: 'POST',
73
+ headers: { 'content-type': 'application/json' },
74
+ body: JSON.stringify({ query, operationName: 'SignIn', variables: { email: 'john@example.com', password: 'secret-password' } }),
75
+ })
76
+ expect(response.status).toBe(200)
77
+
78
+ const expectedBody = { query, operationName: 'SignIn', variables: { email: 'john@example.com', password: '[redacted]' } }
79
+ const error = loggerHandler.messages.find(it => it.error instanceof Error && it.error.message === 'Resolver failed')
80
+ expect(error?.loggerAttributes[LoggerRequestBody]).toEqual(expectedBody)
81
+ const started = loggerHandler.messages.find(it => it.message === 'Request processing started')
82
+ expect(started?.ownAttributes.body).toEqual(expectedBody)
83
+
84
+ const logged = loggerHandler.messages.map(it => [it.ownAttributes, it.loggerAttributes[LoggerRequestBody]])
85
+ expect(JSON.stringify(logged)).not.toContain('secret-password')
86
+ } finally {
87
+ await running.close()
88
+ }
89
+ })
@@ -0,0 +1,102 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { maskRequestBody, maskRequestUri } from '../../../src/application/requestBodyMasking.js'
3
+
4
+ describe('maskRequestBody', () => {
5
+ test('masks a variable passed to a secret argument, whatever its name', () => {
6
+ const query = 'mutation($e: String!, $p: String!) { signIn(email: $e, password: $p) { ok } }'
7
+ expect(maskRequestBody({ query, variables: { e: 'john@example.com', p: 'secret-password' } }, true)).toEqual({
8
+ query,
9
+ variables: { e: 'john@example.com', p: '[redacted]' },
10
+ })
11
+ })
12
+
13
+ test('masks secret literals inlined in the query and keeps the rest', () => {
14
+ const masked = maskRequestBody({
15
+ query: 'mutation { signInPasswordless(requestId: "request-1", token: "link-token", mfaOtp: "123456") { ok } }',
16
+ }, true)
17
+ expect(masked).toEqual({
18
+ query: 'mutation {\n signInPasswordless(\n requestId: "request-1"\n token: "[redacted]"\n mfaOtp: "[redacted]"\n ) {\n ok\n }\n}',
19
+ })
20
+ })
21
+
22
+ test('masks secret fields inside input objects, inline and as variables', () => {
23
+ const query = 'mutation($config: Json!) { addIDP(identityProvider: "sso", type: "oidc", configuration: $config) { ok } }'
24
+ expect(maskRequestBody({ query, variables: { config: { clientId: 'client', clientSecret: 'client-secret' } } }, true)).toEqual({
25
+ query,
26
+ variables: { config: { clientId: 'client', clientSecret: '[redacted]' } },
27
+ })
28
+ const inline = maskRequestBody({
29
+ query: 'mutation { updateIDP(identityProvider: "sso", configuration: { clientSecret: "client-secret" }) { ok } }',
30
+ }, true)
31
+ expect(JSON.stringify(inline)).not.toContain('client-secret')
32
+ })
33
+
34
+ test('masks the value of a project secret, which is secret only on that field', () => {
35
+ const query = 'mutation($v: String!) { setProjectSecret(projectSlug: "blog", key: "s3.secret", value: $v) { ok } }'
36
+ expect(maskRequestBody({ query, variables: { v: 's3-secret-value' } }, true)).toEqual({ query, variables: { v: '[redacted]' } })
37
+ const inline = maskRequestBody(
38
+ { query: 'mutation { setProjectSecret(projectSlug: "blog", key: "s3.secret", value: "s3-secret-value") { ok } }' },
39
+ true,
40
+ )
41
+ expect(JSON.stringify(inline)).not.toContain('s3-secret-value')
42
+ const other = 'query { configuration { value } }'
43
+ expect(maskRequestBody({ query: other }, true)).toEqual({ query: other })
44
+ })
45
+
46
+ test('masks every string of a secret list', () => {
47
+ const query = 'mutation($secrets: [ProjectSecret!]) { createProject(projectSlug: "blog", secrets: $secrets) { ok } }'
48
+ expect(maskRequestBody({ query, variables: { secrets: [{ key: 'db.password', value: 'db-secret' }] } }, true)).toEqual({
49
+ query,
50
+ variables: { secrets: [{ key: '[redacted]', value: '[redacted]' }] },
51
+ })
52
+ })
53
+
54
+ test('replaces a query it cannot parse when it may inline a secret', () => {
55
+ expect(maskRequestBody({ query: 'mutation { signIn(password: "secret-password" ' }, true)).toEqual({ query: '[redacted]' })
56
+ })
57
+
58
+ test('masks secret keys of a body that is not a GraphQL request', () => {
59
+ expect(maskRequestBody({ token: 'abc', name: 'x' }, true)).toEqual({ token: '[redacted]', name: 'x' })
60
+ expect(maskRequestBody(undefined, true)).toBeUndefined()
61
+ })
62
+
63
+ test('masks the default value of a variable bound to a secret argument', () => {
64
+ const masked = maskRequestBody({ query: 'mutation($p: String = "default-secret") { signIn(email: "a", password: $p) { ok } }' }, true)
65
+ expect(JSON.stringify(masked)).not.toContain('default-secret')
66
+ })
67
+
68
+ test('masks every variable when the query naming a secret cannot be parsed', () => {
69
+ const body = { query: 'mutation($p: String!) { signIn(email: "a", password: $p) { ok }', variables: { p: 'secret-password' } }
70
+ expect(maskRequestBody(body, true)).toEqual({ query: '[redacted]', variables: { p: '[redacted]' } })
71
+ })
72
+
73
+ test('masks the IdP callback data, inline and as a variable', () => {
74
+ const query = 'mutation($d: Json) { signInIDP(identityProvider: "sso", data: $d) { ok } }'
75
+ const data = { url: 'https://app/cb?code=AUTHCODE', parameters: { id_token: 'IDTOKEN' }, redirectUrl: 'https://app/cb' }
76
+ expect(JSON.stringify(maskRequestBody({ query, variables: { d: data } }, true))).not.toMatch(/AUTHCODE|IDTOKEN/)
77
+ const inline = maskRequestBody({
78
+ query: 'mutation { signInIDP(identityProvider: "sso", idpResponse: { url: "https://app/cb?code=AUTHCODE" }) { ok } }',
79
+ }, true)
80
+ expect(JSON.stringify(inline)).not.toContain('AUTHCODE')
81
+ })
82
+
83
+ test('masks actions variables', () => {
84
+ const query = 'mutation($a: [VariableInput!]!) { setVariables(args: $a) { ok } }'
85
+ expect(maskRequestBody({ query, variables: { a: [{ name: 'webhookToken', value: 'hook-secret' }] } }, true)).toEqual({
86
+ query,
87
+ variables: { a: [{ name: '[redacted]', value: '[redacted]' }] },
88
+ })
89
+ })
90
+
91
+ test('masks a GraphQL request sent as a query string, whose variables are a JSON string', () => {
92
+ const query = { query: 'mutation($p: String!) { signIn(email: "a", password: $p) { ok } }', variables: '{"p":"secret-password"}' }
93
+ expect(JSON.stringify(maskRequestBody(query, true))).not.toContain('secret-password')
94
+ expect(maskRequestUri('/tenant?query=mutation&variables=x', true)).toBe('/tenant?[redacted]')
95
+ expect(maskRequestUri('/content/blog/live?x=1', false)).toBe('/content/blog/live?x=1')
96
+ })
97
+
98
+ test('leaves the project data of routes without credentials as sent', () => {
99
+ const body = { query: 'query { listProduct(filter: { code: { eq: "PROD-1" } }) { token } }' }
100
+ expect(maskRequestBody(body, false)).toBe(body)
101
+ })
102
+ })
@@ -140,3 +140,26 @@ test('migration lock options: zero and negative values are rejected', () => {
140
140
  expect(() => serverConfigSchema({ systemApi: { migrationLockTimeoutMs: 500, migrationMaxAttempts: -1 } })).toThrow('must be a positive integer')
141
141
  expect(() => serverConfigSchema({ systemApi: { migrationLockTimeoutMs: 500, migrationRetryDelayMs: -1 } })).toThrow('must be a non-negative integer')
142
142
  })
143
+
144
+ test('egress: the guard is off when nothing is configured', async () => {
145
+ const { serverConfig } = await readConfig()
146
+ expect(serverConfig.egress?.guard).toBeUndefined()
147
+ })
148
+
149
+ test('egress: read from CONTEMBER_EGRESS_GUARD, _ALLOW_HTTP and _ALLOWLIST', async () => {
150
+ process.env.CONTEMBER_EGRESS_GUARD = 'true'
151
+ process.env.CONTEMBER_EGRESS_ALLOW_HTTP = 'true'
152
+ process.env.CONTEMBER_EGRESS_ALLOWLIST = 'hooks.internal, 10.0.0.0/8'
153
+ try {
154
+ const { serverConfig } = await readConfig()
155
+ expect(serverConfig.egress).toStrictEqual({ guard: true, allowHttp: true, allowlist: ['hooks.internal', '10.0.0.0/8'] })
156
+ } finally {
157
+ delete process.env.CONTEMBER_EGRESS_GUARD
158
+ delete process.env.CONTEMBER_EGRESS_ALLOW_HTTP
159
+ delete process.env.CONTEMBER_EGRESS_ALLOWLIST
160
+ }
161
+ })
162
+
163
+ test('egress: an invalid allowlist entry is refused at startup', () => {
164
+ expect(() => serverConfigSchema({ egress: { guard: true, allowlist: '10.0.0.0/40' } })).toThrow('Invalid egress allowlist entry')
165
+ })