mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* fix: restrict editor-written code in the builder editor and on the editor hostname * fix: simplify builder author code restrictions by hostname * refactor: remove redundant backend custom code hostname checks * refactor: unify builder HTML element rendering restrictions * refactor: clarify builder web frontend hostname terminology * fix: distinguish untrusted builder content in preview notices * refactor: remove unused backend preview security setting * docs: shorten builder code restriction changelog * fix: restrict iframe cookie access across frontend ports * refactor: share web frontend hostname matching * fix: preserve protected HTML interactions and bound iframe height --------- Co-authored-by: Jeremie Pardou <571533+jrmi@users.noreply.github.com>
54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
import { trueValues } from '@baserow/modules/core/utils/constants'
|
|
import { previewSharesWebFrontendHostname } from '@baserow/modules/builder/utils/preview'
|
|
|
|
/**
|
|
* "Author code" is code written by an application's editors: custom
|
|
* JavaScript, external scripts, head HTML, HTML element scripts and IFrame
|
|
* embeds. On a web frontend hostname it could act as the logged-in user,
|
|
* because cookies are scoped by hostname. Use the `$isAuthorCodeRestricted` plugin to
|
|
* ask whether it is restricted on the current page.
|
|
*/
|
|
|
|
/**
|
|
* Nuxt leaves a word such as "no" or "off" as a non-empty string, so the
|
|
* setting is only on for a value that means true.
|
|
*
|
|
* @param {object} publicConfig The public runtime config.
|
|
* @returns {boolean} Whether the instance lets author code run on a web
|
|
* frontend hostname.
|
|
*/
|
|
export const isPreviewSecurityRelaxed = (publicConfig) =>
|
|
trueValues.includes(
|
|
String(publicConfig.builderDangerousRelaxPreviewSecurity ?? '')
|
|
.trim()
|
|
.toLowerCase()
|
|
)
|
|
|
|
/**
|
|
* Whether author code must be kept from acting as the logged-in user.
|
|
*
|
|
* Author code is restricted when the current page uses the main web frontend
|
|
* hostname or an additional configured web frontend hostname, unless the
|
|
* instance relaxes this restriction. This applies regardless of the page mode.
|
|
*
|
|
* @param {object} options
|
|
* @param {boolean} options.isWebFrontendHostname Whether the current page uses
|
|
* a configured web frontend hostname. Anything but `false` counts as yes.
|
|
* @param {object} options.publicConfig The public runtime config.
|
|
* @returns {boolean} Whether author code is restricted.
|
|
*/
|
|
export const isAuthorCodeRestricted = ({
|
|
isWebFrontendHostname,
|
|
publicConfig,
|
|
}) => isWebFrontendHostname !== false && !isPreviewSecurityRelaxed(publicConfig)
|
|
|
|
/**
|
|
* Whether Preview will restrict author code, for the editor to tell the user.
|
|
*
|
|
* @param {object} publicConfig The public runtime config.
|
|
* @returns {boolean} Whether Preview restricts author code.
|
|
*/
|
|
export const isPreviewAuthorCodeRestricted = (publicConfig) =>
|
|
previewSharesWebFrontendHostname(publicConfig) &&
|
|
!isPreviewSecurityRelaxed(publicConfig)
|