@uniformdev/canvas-sveltekit 20.81.1-alpha.53.sha-78fe06af4f → 20.89.1-alpha.78.sha-248d2fa520

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
1
  import { error, redirect } from '@sveltejs/kit';
2
- import { IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, isAllowedReferrer, SECRET_QUERY_STRING_PARAM, } from '@uniformdev/canvas';
2
+ import { IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, isAllowedReferrer, SECRET_QUERY_STRING_PARAM, toLocalRedirectPath, } from '@uniformdev/canvas';
3
3
  import {} from '../models.js';
4
4
  import { clearPreviewData, setPreviewData } from './previewCookie.js';
5
- const BASE_URL_EXAMPLE = 'https://example.com';
6
5
  const compositionQueryParams = {
7
6
  id: 'id',
8
7
  slug: 'slug',
@@ -16,12 +15,6 @@ const contextualEditingQueryParams = [
16
15
  const resolveFullPathDefault = ({ slug, path }) => {
17
16
  return path || slug;
18
17
  };
19
- function validateLocalRedirectUrl(pathToRedirectTo) {
20
- // Prevent open redirection to any complete URL with a protocol
21
- if (pathToRedirectTo?.match(/^[a-z]+:\/\//g)) {
22
- throw new Error('Tried to redirect to absolute URL with protocol. Disallowing open redirect.');
23
- }
24
- }
25
18
  /**
26
19
  * Creates a SvelteKit GET request handler for preview mode.
27
20
  *
@@ -80,14 +73,40 @@ export function createPreviewHandlerGet(options) {
80
73
  if (typeof pathToRedirectTo === 'undefined') {
81
74
  pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
82
75
  }
83
- validateLocalRedirectUrl(pathToRedirectTo);
84
76
  if (!pathToRedirectTo) {
85
77
  error(400, 'Could not resolve the full path of the preview page');
86
78
  }
79
+ // Check if this is valid contextual editing
80
+ const isUniformContextualEditing = searchParams.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === 'true' &&
81
+ isAllowedReferrer(request.headers.get('referer') ?? undefined);
82
+ const localPathToRedirectTo = toLocalRedirectPath(pathToRedirectTo);
83
+ const fullPathToRedirectTo = toLocalRedirectPath(pathToRedirectTo, (redirectSearchParams) => {
84
+ const compositionQueryParamNames = Object.values(compositionQueryParams);
85
+ // Copy query params except secret and composition params
86
+ searchParams.forEach((value, name) => {
87
+ if (name === SECRET_QUERY_STRING_PARAM) {
88
+ return;
89
+ }
90
+ if (compositionQueryParamNames.includes(name)) {
91
+ return;
92
+ }
93
+ redirectSearchParams.append(name, value);
94
+ });
95
+ // Remove contextual editing params if not in contextual editing mode
96
+ if (!isUniformContextualEditing) {
97
+ contextualEditingQueryParams.forEach((param) => {
98
+ redirectSearchParams.delete(param);
99
+ });
100
+ }
101
+ });
102
+ // An open redirect is refused before any preview cookie is set or cleared.
103
+ if (!localPathToRedirectTo || !fullPathToRedirectTo) {
104
+ error(400, 'Invalid preview path');
105
+ }
87
106
  // Handle disable preview
88
107
  if (searchParams.has('disable')) {
89
108
  clearPreviewData(cookies);
90
- redirect(307, pathToRedirectTo);
109
+ redirect(307, localPathToRedirectTo);
91
110
  }
92
111
  const previewSecret = secret();
93
112
  if (!previewSecret) {
@@ -98,9 +117,6 @@ export function createPreviewHandlerGet(options) {
98
117
  if (searchParams.get(SECRET_QUERY_STRING_PARAM) !== previewSecret) {
99
118
  error(401, 'Invalid token');
100
119
  }
101
- // Check if this is valid contextual editing
102
- const isUniformContextualEditing = searchParams.get(IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === 'true' &&
103
- isAllowedReferrer(request.headers.get('referer') ?? undefined);
104
120
  // Set preview cookie
105
121
  const previewData = {
106
122
  isUniformContextualEditing,
@@ -118,26 +134,6 @@ export function createPreviewHandlerGet(options) {
118
134
  // Short max age for contextual editing to avoid stale preview state
119
135
  maxAge: isUniformContextualEditing ? 10 : undefined,
120
136
  });
121
- // Build redirect URL with query params
122
- const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
123
- const compositionQueryParamNames = Object.values(compositionQueryParams);
124
- // Copy query params except secret and composition params
125
- searchParams.forEach((value, name) => {
126
- if (name === SECRET_QUERY_STRING_PARAM) {
127
- return;
128
- }
129
- if (compositionQueryParamNames.includes(name)) {
130
- return;
131
- }
132
- redirectionUrl.searchParams.append(name, value);
133
- });
134
- // Remove contextual editing params if not in contextual editing mode
135
- if (!isUniformContextualEditing) {
136
- contextualEditingQueryParams.forEach((param) => {
137
- redirectionUrl.searchParams.delete(param);
138
- });
139
- }
140
- const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, '');
141
137
  redirect(307, fullPathToRedirectTo);
142
138
  };
143
139
  }
@@ -52,7 +52,7 @@ export function createRouteFetcher(options) {
52
52
  }
53
53
  const resolvedOptions = typeof requestOptions === 'function' ? requestOptions(context) : requestOptions;
54
54
  const time = Date.now();
55
- const response = await routeClient.getRoute({
55
+ const response = await routeClient.get({
56
56
  ...resolvedOptions,
57
57
  state: resolvedOptions?.state ?? defaultPreviewState ?? CANVAS_PUBLISHED_STATE,
58
58
  dataSourceVariant: getDataSourceVariantFromRouteGetParams(resolvedOptions ?? {}, defaultPreviewState),
@@ -24,7 +24,7 @@ export type RouteHandlerOptions<TContext, TResult, TSuccessResult> = {
24
24
  modifyPath?: (path: string, context: TContext) => string;
25
25
  /** The project map ID to use. Defaults to UNIFORM_PROJECT_MAP_ID env var */
26
26
  projectMapId?: string;
27
- /** Override getRoute request parameters */
27
+ /** Override `RouteClient.get` request parameters */
28
28
  requestOptions?: Partial<RouteGetParameters> | ((context: TContext) => Partial<RouteGetParameters>);
29
29
  /** Disable logging of response information and timings */
30
30
  silent?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-sveltekit",
3
- "version": "20.81.1-alpha.53.sha-78fe06af4f",
3
+ "version": "20.89.1-alpha.78.sha-248d2fa520",
4
4
  "description": "SvelteKit SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "scripts": {
@@ -39,19 +39,13 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@sveltejs/kit": "^3.0.0",
42
- "@uniformdev/context-edge": ">=20.0.0",
43
42
  "svelte": "^5.57.1"
44
43
  },
45
- "peerDependenciesMeta": {
46
- "@uniformdev/context-edge": {
47
- "optional": true
48
- }
49
- },
50
44
  "dependencies": {
51
- "@uniformdev/canvas": "20.81.1-alpha.53.sha-78fe06af4f",
52
- "@uniformdev/canvas-svelte": "20.81.1-alpha.53.sha-78fe06af4f",
53
- "@uniformdev/project-map": "20.81.1-alpha.53.sha-78fe06af4f",
54
- "@uniformdev/redirect": "20.81.1-alpha.53.sha-78fe06af4f",
45
+ "@uniformdev/canvas": "20.89.1-alpha.78.sha-248d2fa520",
46
+ "@uniformdev/canvas-svelte": "20.89.1-alpha.78.sha-248d2fa520",
47
+ "@uniformdev/project-map": "20.89.1-alpha.78.sha-248d2fa520",
48
+ "@uniformdev/redirect": "20.89.1-alpha.78.sha-248d2fa520",
55
49
  "colorette": "2.0.20"
56
50
  },
57
51
  "devDependencies": {
@@ -60,7 +54,6 @@
60
54
  "@sveltejs/kit": "3.1.0",
61
55
  "@sveltejs/package": "3.0.1",
62
56
  "@sveltejs/vite-plugin-svelte": "7.3.1",
63
- "@uniformdev/context-edge": "20.81.1-alpha.53.sha-78fe06af4f",
64
57
  "publint": "0.3.25",
65
58
  "svelte": "5.57.3",
66
59
  "svelte-check": "4.7.7",
@@ -76,5 +69,5 @@
76
69
  "publishConfig": {
77
70
  "access": "public"
78
71
  },
79
- "gitHead": "78fe06af4f6478090dd1383cc3511961c46de0e9"
72
+ "gitHead": "248d2fa520900b3e84fd1f7beaf2b3dd8d9100e4"
80
73
  }