Set PPQ_ALLOWED_HOSTS dynamically to prevent DNS-rebinding attacks
This commit is contained in:
1 parent
10907a6276
commit
c6ad02d0a7
1 file changed
+51
-8
+51
-8
@@ -1,7 +1,8 @@
|
|||||||
|
import { utils } from '@start9labs/start-sdk'
|
||||||
import { i18n } from './i18n'
|
import { i18n } from './i18n'
|
||||||
import { sdk } from './sdk'
|
import { sdk } from './sdk'
|
||||||
import { manifest } from './manifest'
|
import { manifest } from './manifest'
|
||||||
import { apiPort, dataDir } from './utils'
|
import { apiHostId, apiPort, dataDir } from './utils'
|
||||||
import { configureApiKey } from './actions/configureApiKey'
|
import { configureApiKey } from './actions/configureApiKey'
|
||||||
import { configJson } from './fileModels/config.json'
|
import { configJson } from './fileModels/config.json'
|
||||||
import { storeJson } from './fileModels/store.json'
|
import { storeJson } from './fileModels/store.json'
|
||||||
@@ -23,6 +24,40 @@ export const main = sdk.setupMain(async ({ effects }) => {
|
|||||||
await sdk.action.clearTask(effects, `${manifest.id}:${configureApiKey.id}`)
|
await sdk.action.clearTask(effects, `${manifest.id}:${configureApiKey.id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DNS-rebinding hardening. Upstream's proxy is bound to 0.0.0.0, and without
|
||||||
|
// PPQ_ALLOWED_HOSTS it accepts any Host header — a hostile web page could
|
||||||
|
// reach it as "same-origin" and even overwrite the stored API key via
|
||||||
|
// /setup/api-key. Pin the accepted Hosts to exactly the addresses StartOS
|
||||||
|
// serves this binding on, plus loopback and the bridge (what Open WebUI
|
||||||
|
// dials). Resolved reactively so an address added later is picked up on the
|
||||||
|
// next restart.
|
||||||
|
const servedHosts = await sdk.host
|
||||||
|
.getOwn(
|
||||||
|
effects,
|
||||||
|
apiHostId,
|
||||||
|
(host) =>
|
||||||
|
host
|
||||||
|
? utils
|
||||||
|
.filledAddress(host, {
|
||||||
|
hostId: apiHostId,
|
||||||
|
internalPort: apiPort,
|
||||||
|
username: null,
|
||||||
|
scheme: null,
|
||||||
|
sslScheme: null,
|
||||||
|
suffix: '',
|
||||||
|
})
|
||||||
|
.matchesAny([{ visibility: 'private' }, { visibility: 'public' }])
|
||||||
|
.filter({ exclude: { kind: ['localhost', 'link-local'] } })
|
||||||
|
.hostnames.map((h) => h.hostname)
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
.const()
|
||||||
|
|
||||||
|
const osIp = await sdk.getOsIp(effects)
|
||||||
|
const allowedHosts = Array.from(
|
||||||
|
new Set(['localhost', '127.0.0.1', osIp, ...servedHosts].filter(Boolean)),
|
||||||
|
).join(',')
|
||||||
|
|
||||||
const subcontainer = sdk.SubContainer.of(
|
const subcontainer = sdk.SubContainer.of(
|
||||||
effects,
|
effects,
|
||||||
{ imageId: 'proxy' },
|
{ imageId: 'proxy' },
|
||||||
@@ -48,12 +83,20 @@ export const main = sdk.setupMain(async ({ effects }) => {
|
|||||||
subcontainer,
|
subcontainer,
|
||||||
exec: {
|
exec: {
|
||||||
command: ['node', '/app/dist/bin/server.js'],
|
command: ['node', '/app/dist/bin/server.js'],
|
||||||
env: {
|
env: allowedHosts
|
||||||
PPQ_DATA_DIR: dataDir,
|
? {
|
||||||
HOST: '0.0.0.0',
|
PPQ_DATA_DIR: dataDir,
|
||||||
PORT: apiPort.toString(),
|
HOST: '0.0.0.0',
|
||||||
DEBUG: debug ? 'true' : 'false',
|
PORT: apiPort.toString(),
|
||||||
},
|
DEBUG: debug ? 'true' : 'false',
|
||||||
|
PPQ_ALLOWED_HOSTS: allowedHosts,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
PPQ_DATA_DIR: dataDir,
|
||||||
|
HOST: '0.0.0.0',
|
||||||
|
PORT: apiPort.toString(),
|
||||||
|
DEBUG: debug ? 'true' : 'false',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// The proxy only binds its port after remote attestation of the enclave
|
// The proxy only binds its port after remote attestation of the enclave
|
||||||
// succeeds, so a listening port means the encrypted channel is verified
|
// succeeds, so a listening port means the encrypted channel is verified
|
||||||
@@ -72,4 +115,4 @@ export const main = sdk.setupMain(async ({ effects }) => {
|
|||||||
},
|
},
|
||||||
requires: ['chown'],
|
requires: ['chown'],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user