e116941750
* Rotatable secrets * Set new api encryption key var * Lint * Use fallback keys instead of array * Point api encryption key to dedicated value * Add API_ENCRYPTION_KEY to cli * Lint + add api encryption key to env files
23 lines
499 B
TypeScript
23 lines
499 B
TypeScript
import { Header } from "../constants"
|
|
import { BBContext } from "@budibase/types"
|
|
import { isValidInternalAPIKey } from "../utils"
|
|
|
|
/**
|
|
* API Key only endpoint.
|
|
*/
|
|
export default async (ctx: BBContext, next: any) => {
|
|
const apiKey = ctx.request.headers[Header.API_KEY]
|
|
if (!apiKey) {
|
|
ctx.throw(403, "Unauthorized")
|
|
}
|
|
|
|
if (Array.isArray(apiKey)) {
|
|
ctx.throw(403, "Unauthorized")
|
|
}
|
|
|
|
if (!isValidInternalAPIKey(apiKey)) {
|
|
ctx.throw(403, "Unauthorized")
|
|
}
|
|
|
|
return next()
|
|
}
|