mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +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>
88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
import { describe, expect, test } from 'vitest'
|
|
|
|
import {
|
|
getBuilderPreviewApiPath,
|
|
getBuilderPreviewCookieName,
|
|
getBuilderPreviewCookiePath,
|
|
getBuilderPreviewIdFromApiUrl,
|
|
getBuilderPreviewSsrCookieName,
|
|
getBuilderPreviewUserSourceAuthConfig,
|
|
getBuilderPreviewUserSourceCookieName,
|
|
previewSharesWebFrontendHostname,
|
|
} from '@baserow/modules/builder/utils/preview'
|
|
|
|
const config = { public: { baserowFrontendCookiePrefix: 'test_' } }
|
|
|
|
describe('builder preview cookies', () => {
|
|
test('uses fixed names and builder-specific paths', () => {
|
|
expect(getBuilderPreviewCookieName(config)).toBe(
|
|
'test_baserow_builder_preview'
|
|
)
|
|
expect(getBuilderPreviewSsrCookieName(config)).toBe(
|
|
'test_baserow_builder_preview_ssr'
|
|
)
|
|
expect(getBuilderPreviewUserSourceCookieName()).toBe(
|
|
'baserow_builder_preview_user_source'
|
|
)
|
|
expect(getBuilderPreviewCookiePath(42)).toBe('/builder/preview/42')
|
|
})
|
|
|
|
test('uses and recognizes builder-scoped preview API paths', () => {
|
|
expect(getBuilderPreviewApiPath(42, 'pages/7/elements/')).toBe(
|
|
'builder/preview/42/pages/7/elements/'
|
|
)
|
|
expect(
|
|
getBuilderPreviewIdFromApiUrl(
|
|
'https://api.example.com/api/builder/preview/42/pages/7/elements/'
|
|
)
|
|
).toBe(42)
|
|
expect(
|
|
getBuilderPreviewIdFromApiUrl(
|
|
'builder/domains/published/page/7/elements/'
|
|
)
|
|
).toBeNull()
|
|
})
|
|
|
|
test('provides core with generic user source authentication settings', () => {
|
|
const builder = {
|
|
id: 42,
|
|
user_sources: [{ id: 10 }, { id: 11 }],
|
|
}
|
|
|
|
expect(
|
|
getBuilderPreviewUserSourceAuthConfig(
|
|
builder,
|
|
'https://preview.example.com'
|
|
)
|
|
).toEqual({
|
|
authenticationUrls: {
|
|
10: 'builder/preview/42/user-sources/10/token-auth/',
|
|
11: 'builder/preview/42/user-sources/11/token-auth/',
|
|
},
|
|
refreshUrl: 'builder/preview/42/user-source-auth-refresh/',
|
|
cookieName: 'baserow_builder_preview_user_source',
|
|
cookieOptions: {
|
|
cookieUrl: 'https://preview.example.com',
|
|
path: '/builder/preview/42',
|
|
sameSite: 'Lax',
|
|
},
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('previewSharesWebFrontendHostname', () => {
|
|
test.each([
|
|
['http://localhost:3000', 'http://localhost:3000', true],
|
|
['http://localhost:3001', 'http://localhost:3000', true],
|
|
['https://preview.example.com', 'https://example.com', false],
|
|
['', 'https://example.com', true],
|
|
])('%s vs %s', (builderPreviewUrl, publicWebFrontendUrl, expected) => {
|
|
expect(
|
|
previewSharesWebFrontendHostname({
|
|
builderPreviewUrl,
|
|
publicWebFrontendUrl,
|
|
})
|
|
).toBe(expected)
|
|
})
|
|
})
|