@tanstack/router-core 1.159.9 → 1.161.1
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.
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/redirect.cjs +0 -6
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/router.cjs +11 -3
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +10 -1
- package/dist/cjs/utils.cjs +11 -4
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +8 -7
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/redirect.js +0 -6
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/router.d.ts +10 -1
- package/dist/esm/router.js +12 -4
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +8 -7
- package/dist/esm/utils.js +11 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/redirect.ts +0 -12
- package/src/router.ts +36 -4
- package/src/utils.ts +20 -8
package/dist/cjs/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ exports.defaultParseSearch = searchParams.defaultParseSearch;
|
|
|
56
56
|
exports.defaultStringifySearch = searchParams.defaultStringifySearch;
|
|
57
57
|
exports.parseSearchWith = searchParams.parseSearchWith;
|
|
58
58
|
exports.stringifySearchWith = searchParams.stringifySearchWith;
|
|
59
|
+
exports.DEFAULT_PROTOCOL_ALLOWLIST = utils.DEFAULT_PROTOCOL_ALLOWLIST;
|
|
59
60
|
exports.buildDevStylesUrl = utils.buildDevStylesUrl;
|
|
60
61
|
exports.createControlledPromise = utils.createControlledPromise;
|
|
61
62
|
exports.decodePath = utils.decodePath;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -24,7 +24,7 @@ export { retainSearchParams, stripSearchParams } from './searchMiddleware.cjs';
|
|
|
24
24
|
export { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, } from './searchParams.cjs';
|
|
25
25
|
export type { SearchSerializer, SearchParser } from './searchParams.cjs';
|
|
26
26
|
export type { OptionalStructuralSharing } from './structuralSharing.cjs';
|
|
27
|
-
export { last, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, createControlledPromise, isModuleNotFoundError, decodePath, escapeHtml, isDangerousProtocol, buildDevStylesUrl, } from './utils.cjs';
|
|
27
|
+
export { last, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, createControlledPromise, isModuleNotFoundError, decodePath, DEFAULT_PROTOCOL_ALLOWLIST, escapeHtml, isDangerousProtocol, buildDevStylesUrl, } from './utils.cjs';
|
|
28
28
|
export type { NoInfer, IsAny, PickAsRequired, PickRequired, PickOptional, WithoutEmpty, Expand, DeepPartial, MakeDifferenceOptional, IsUnion, IsNonEmptyObject, Assign, IntersectAssign, Timeout, Updater, NonNullableUpdater, StringLiteral, ThrowOrOptional, ThrowConstraint, ControlledPromise, ExtractObjects, PartialMergeAllObject, MergeAllPrimitive, ExtractPrimitives, PartialMergeAll, Constrain, ConstrainLiteral, UnionToIntersection, MergeAllObjects, MergeAll, ValidateJSON, StrictOrFrom, LooseReturnType, LooseAsyncReturnType, Awaitable, } from './utils.cjs';
|
|
29
29
|
export type { StandardSchemaValidatorProps, StandardSchemaValidator, AnyStandardSchemaValidator, StandardSchemaValidatorTypes, AnyStandardSchemaValidateSuccess, AnyStandardSchemaValidateFailure, AnyStandardSchemaValidateIssue, AnyStandardSchemaValidateInput, AnyStandardSchemaValidate, ValidatorObj, AnyValidatorObj, ValidatorAdapter, AnyValidatorAdapter, AnyValidatorFn, ValidatorFn, Validator, AnyValidator, AnySchema, DefaultValidator, ResolveSearchValidatorInputFn, ResolveSearchValidatorInput, ResolveValidatorInputFn, ResolveValidatorInput, ResolveValidatorOutputFn, ResolveValidatorOutput, } from './validators.cjs';
|
|
30
30
|
export type { UseRouteContextBaseOptions, UseRouteContextOptions, UseRouteContextResult, } from './useRouteContext.cjs';
|
package/dist/cjs/redirect.cjs
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const utils = require("./utils.cjs");
|
|
4
3
|
function redirect(opts) {
|
|
5
4
|
opts.statusCode = opts.statusCode || opts.code || 307;
|
|
6
|
-
if (!opts._builtLocation && typeof opts.href === "string" && utils.isDangerousProtocol(opts.href)) {
|
|
7
|
-
throw new Error(
|
|
8
|
-
`Redirect blocked: unsafe protocol in href "${opts.href}". Only ${utils.SAFE_URL_PROTOCOLS.join(", ")} protocols are allowed.`
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
5
|
if (!opts._builtLocation && !opts.reloadDocument && typeof opts.href === "string") {
|
|
12
6
|
try {
|
|
13
7
|
new URL(opts.href);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.cjs","sources":["../../src/redirect.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"redirect.cjs","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"names":[],"mappings":";;AAkHO,SAAS,SAOd,MACmD;AACnD,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAElD,MACE,CAAC,KAAK,kBACN,CAAC,KAAK,kBACN,OAAO,KAAK,SAAS,UACrB;AACA,QAAI;AACF,UAAI,IAAI,KAAK,IAAI;AACjB,WAAK,iBAAiB;AAAA,IACxB,QAAQ;AAAA,IAAC;AAAA,EACX;AAEA,QAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;AACxC,MAAI,KAAK,QAAQ,QAAQ,IAAI,UAAU,MAAM,MAAM;AACjD,YAAQ,IAAI,YAAY,KAAK,IAAI;AAAA,EACnC;AAEA,QAAM,WAAW,IAAI,SAAS,MAAM;AAAA,IAClC,QAAQ,KAAK;AAAA,IACb;AAAA,EAAA,CACD;AAEC,WAA+D,UAC/D;AAEF,MAAI,KAAK,OAAO;AACd,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAIO,SAAS,WAAW,KAA8B;AACvD,SAAO,eAAe,YAAY,CAAC,CAAE,IAAY;AACnD;AAIO,SAAS,mBACd,KACoD;AACpD,SAAO,WAAW,GAAG,KAAK,CAAC,CAAC,IAAI,QAAQ;AAC1C;AAIO,SAAS,cAAc,KAAU;AACtC,MAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,sBAAsB;AACvE,WAAO,SAAS,GAAG;AAAA,EACrB;AAEA,SAAO;AACT;;;;;"}
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -82,6 +82,7 @@ class RouterCore {
|
|
|
82
82
|
...newOptions
|
|
83
83
|
};
|
|
84
84
|
this.isServer = this.options.isServer ?? typeof document === "undefined";
|
|
85
|
+
this.protocolAllowlist = new Set(this.options.protocolAllowlist);
|
|
85
86
|
if (this.options.pathParamsAllowedCharacters)
|
|
86
87
|
this.pathParamsDecoder = path.compileDecodeCharMap(
|
|
87
88
|
this.options.pathParamsAllowedCharacters
|
|
@@ -627,7 +628,7 @@ class RouterCore {
|
|
|
627
628
|
publicHref = publicHref ?? location.publicHref;
|
|
628
629
|
}
|
|
629
630
|
const reloadHref = !hrefIsUrl && publicHref ? publicHref : href;
|
|
630
|
-
if (utils.isDangerousProtocol(reloadHref)) {
|
|
631
|
+
if (utils.isDangerousProtocol(reloadHref, this.protocolAllowlist)) {
|
|
631
632
|
if (process.env.NODE_ENV !== "production") {
|
|
632
633
|
console.warn(
|
|
633
634
|
`Blocked navigation to dangerous protocol: ${reloadHref}`
|
|
@@ -923,6 +924,12 @@ class RouterCore {
|
|
|
923
924
|
} catch {
|
|
924
925
|
}
|
|
925
926
|
}
|
|
927
|
+
if (redirect2.options.href && !redirect2.options._builtLocation && // Check for dangerous protocols before processing the redirect
|
|
928
|
+
utils.isDangerousProtocol(redirect2.options.href, this.protocolAllowlist)) {
|
|
929
|
+
throw new Error(
|
|
930
|
+
`Redirect blocked: unsafe protocol in href "${redirect2.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(", ")}.`
|
|
931
|
+
);
|
|
932
|
+
}
|
|
926
933
|
if (!redirect2.headers.get("Location")) {
|
|
927
934
|
redirect2.headers.set("Location", redirect2.options.href);
|
|
928
935
|
}
|
|
@@ -964,7 +971,7 @@ class RouterCore {
|
|
|
964
971
|
};
|
|
965
972
|
this.loadRouteChunk = loadMatches.loadRouteChunk;
|
|
966
973
|
this.preloadRoute = async (opts) => {
|
|
967
|
-
const next = this.buildLocation(opts);
|
|
974
|
+
const next = opts._builtLocation ?? this.buildLocation(opts);
|
|
968
975
|
let matches = this.matchRoutes(next, {
|
|
969
976
|
throwOnError: true,
|
|
970
977
|
preload: true,
|
|
@@ -1070,7 +1077,8 @@ class RouterCore {
|
|
|
1070
1077
|
caseSensitive: options.caseSensitive ?? false,
|
|
1071
1078
|
notFoundMode: options.notFoundMode ?? "fuzzy",
|
|
1072
1079
|
stringifySearch: options.stringifySearch ?? searchParams.defaultStringifySearch,
|
|
1073
|
-
parseSearch: options.parseSearch ?? searchParams.defaultParseSearch
|
|
1080
|
+
parseSearch: options.parseSearch ?? searchParams.defaultParseSearch,
|
|
1081
|
+
protocolAllowlist: options.protocolAllowlist ?? utils.DEFAULT_PROTOCOL_ALLOWLIST
|
|
1074
1082
|
});
|
|
1075
1083
|
if (typeof document !== "undefined") {
|
|
1076
1084
|
self.__TSR_ROUTER__ = this;
|