parent
00bfaaa53d
commit
6d7ca1b926
3 changed files with 104 additions and 3 deletions
|
@ -83,7 +83,41 @@ void container.load().then((container) => {
|
||||||
type: ['text/plain', 'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded; charset=utf-8'],
|
type: ['text/plain', 'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded; charset=utf-8'],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
app.use(cors())
|
const corsAllowedOrigins = env.get('CORS_ALLOWED_ORIGINS', true)
|
||||||
|
? env.get('CORS_ALLOWED_ORIGINS', true).split(',')
|
||||||
|
: []
|
||||||
|
app.use(
|
||||||
|
cors({
|
||||||
|
credentials: true,
|
||||||
|
exposedHeaders: ['x-captcha-required'],
|
||||||
|
origin: (requestOrigin: string | undefined, callback: (err: Error | null, origin?: string[]) => void) => {
|
||||||
|
const requstOriginIsNotFilled = !requestOrigin || requestOrigin === 'null'
|
||||||
|
const requestOriginatesFromTheDesktopApp = requestOrigin?.startsWith('file://')
|
||||||
|
const requestOriginatesFromClipperForFirefox = requestOrigin?.startsWith('moz-extension://')
|
||||||
|
const requestOriginatesFromSelfHostedAppOnHttpPort = requestOrigin === 'http://localhost'
|
||||||
|
const requestOriginatesFromSelfHostedAppOnCustomPort = requestOrigin?.match(/http:\/\/localhost:\d+/) !== null
|
||||||
|
const requestOriginatesFromSelfHostedApp =
|
||||||
|
requestOriginatesFromSelfHostedAppOnHttpPort || requestOriginatesFromSelfHostedAppOnCustomPort
|
||||||
|
|
||||||
|
const requestIsWhitelisted =
|
||||||
|
corsAllowedOrigins.length === 0 ||
|
||||||
|
requstOriginIsNotFilled ||
|
||||||
|
requestOriginatesFromTheDesktopApp ||
|
||||||
|
requestOriginatesFromClipperForFirefox ||
|
||||||
|
requestOriginatesFromSelfHostedApp
|
||||||
|
|
||||||
|
if (requestIsWhitelisted) {
|
||||||
|
callback(null, [requestOrigin as string])
|
||||||
|
} else {
|
||||||
|
if (corsAllowedOrigins.includes(requestOrigin)) {
|
||||||
|
callback(null, [requestOrigin])
|
||||||
|
} else {
|
||||||
|
callback(new Error('Not allowed by CORS', { cause: 'origin not allowed' }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
app.use(
|
app.use(
|
||||||
robots({
|
robots({
|
||||||
UserAgent: '*',
|
UserAgent: '*',
|
||||||
|
|
|
@ -65,9 +65,45 @@ void container.load().then((container) => {
|
||||||
app.use(json({ limit: requestPayloadLimit }))
|
app.use(json({ limit: requestPayloadLimit }))
|
||||||
app.use(raw({ limit: requestPayloadLimit, type: 'application/octet-stream' }))
|
app.use(raw({ limit: requestPayloadLimit, type: 'application/octet-stream' }))
|
||||||
app.use(urlencoded({ extended: true, limit: requestPayloadLimit }))
|
app.use(urlencoded({ extended: true, limit: requestPayloadLimit }))
|
||||||
|
|
||||||
|
const corsAllowedOrigins = env.get('CORS_ALLOWED_ORIGINS', true)
|
||||||
|
? env.get('CORS_ALLOWED_ORIGINS', true).split(',')
|
||||||
|
: []
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
exposedHeaders: ['Content-Range', 'Accept-Ranges'],
|
credentials: true,
|
||||||
|
exposedHeaders: [
|
||||||
|
'Content-Range',
|
||||||
|
'Accept-Ranges',
|
||||||
|
'Access-Control-Allow-Credentials',
|
||||||
|
'Access-Control-Allow-Origin',
|
||||||
|
],
|
||||||
|
origin: (requestOrigin: string | undefined, callback: (err: Error | null, origin?: string[]) => void) => {
|
||||||
|
const requstOriginIsNotFilled = !requestOrigin || requestOrigin === 'null'
|
||||||
|
const requestOriginatesFromTheDesktopApp = requestOrigin?.startsWith('file://')
|
||||||
|
const requestOriginatesFromClipperForFirefox = requestOrigin?.startsWith('moz-extension://')
|
||||||
|
const requestOriginatesFromSelfHostedAppOnHttpPort = requestOrigin === 'http://localhost'
|
||||||
|
const requestOriginatesFromSelfHostedAppOnCustomPort = requestOrigin?.match(/http:\/\/localhost:\d+/) !== null
|
||||||
|
const requestOriginatesFromSelfHostedApp =
|
||||||
|
requestOriginatesFromSelfHostedAppOnHttpPort || requestOriginatesFromSelfHostedAppOnCustomPort
|
||||||
|
|
||||||
|
const requestIsWhitelisted =
|
||||||
|
corsAllowedOrigins.length === 0 ||
|
||||||
|
requstOriginIsNotFilled ||
|
||||||
|
requestOriginatesFromTheDesktopApp ||
|
||||||
|
requestOriginatesFromClipperForFirefox ||
|
||||||
|
requestOriginatesFromSelfHostedApp
|
||||||
|
|
||||||
|
if (requestIsWhitelisted) {
|
||||||
|
callback(null, [requestOrigin as string])
|
||||||
|
} else {
|
||||||
|
if (corsAllowedOrigins.includes(requestOrigin)) {
|
||||||
|
callback(null, [requestOrigin])
|
||||||
|
} else {
|
||||||
|
callback(new Error('Not allowed by CORS', { cause: 'origin not allowed' }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
app.use(
|
app.use(
|
||||||
|
|
|
@ -129,9 +129,40 @@ export class HomeServer implements HomeServerInterface {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
const corsAllowedOrigins = env.get('CORS_ALLOWED_ORIGINS', true)
|
||||||
|
? env.get('CORS_ALLOWED_ORIGINS', true).split(',')
|
||||||
|
: []
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
exposedHeaders: ['Content-Range', 'Accept-Ranges'],
|
credentials: true,
|
||||||
|
exposedHeaders: ['Content-Range', 'Accept-Ranges', 'x-captcha-required'],
|
||||||
|
origin: (requestOrigin: string | undefined, callback: (err: Error | null, origin?: string[]) => void) => {
|
||||||
|
const requstOriginIsNotFilled = !requestOrigin || requestOrigin === 'null'
|
||||||
|
const requestOriginatesFromTheDesktopApp = requestOrigin?.startsWith('file://')
|
||||||
|
const requestOriginatesFromClipperForFirefox = requestOrigin?.startsWith('moz-extension://')
|
||||||
|
const requestOriginatesFromSelfHostedAppOnHttpPort = requestOrigin === 'http://localhost'
|
||||||
|
const requestOriginatesFromSelfHostedAppOnCustomPort =
|
||||||
|
requestOrigin?.match(/http:\/\/localhost:\d+/) !== null
|
||||||
|
const requestOriginatesFromSelfHostedApp =
|
||||||
|
requestOriginatesFromSelfHostedAppOnHttpPort || requestOriginatesFromSelfHostedAppOnCustomPort
|
||||||
|
|
||||||
|
const requestIsWhitelisted =
|
||||||
|
corsAllowedOrigins.length === 0 ||
|
||||||
|
requstOriginIsNotFilled ||
|
||||||
|
requestOriginatesFromTheDesktopApp ||
|
||||||
|
requestOriginatesFromClipperForFirefox ||
|
||||||
|
requestOriginatesFromSelfHostedApp
|
||||||
|
|
||||||
|
if (requestIsWhitelisted) {
|
||||||
|
callback(null, [requestOrigin as string])
|
||||||
|
} else {
|
||||||
|
if (corsAllowedOrigins.includes(requestOrigin)) {
|
||||||
|
callback(null, [requestOrigin])
|
||||||
|
} else {
|
||||||
|
callback(new Error('Not allowed by CORS', { cause: 'origin not allowed' }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
app.use(
|
app.use(
|
||||||
|
|
Loading…
Reference in a new issue