@orchestraai/agent-tools 0.10.16 → 0.10.17
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.devin/adapter.json +1 -1
- package/.hermes/adapter.json +1 -1
- package/.opencode/adapter.json +1 -1
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/runtime/conversation/command-guard.js +1023 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +42 -0
- package/dist/runtime/conversation/shell-parse.js +517 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +11 -2
- package/node_modules/@hono/node-server/dist/index.cjs +63 -17
- package/node_modules/@hono/node-server/dist/index.mjs +63 -17
- package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
- package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
- package/node_modules/@hono/node-server/package.json +1 -1
- package/node_modules/cross-spawn/README.md +19 -3
- package/node_modules/cross-spawn/lib/parse.js +38 -10
- package/node_modules/cross-spawn/lib/util/escape.js +84 -25
- package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
- package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
- package/node_modules/cross-spawn/package.json +21 -24
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/cjs/client/utils.js +9 -5
- package/node_modules/hono/dist/cjs/context.js +1 -1
- package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/cjs/hono-base.js +9 -10
- package/node_modules/hono/dist/cjs/hono.js +0 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
- package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
- package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
- package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
- package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
- package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
- package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
- package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/cjs/utils/body.js +2 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
- package/node_modules/hono/dist/cjs/utils/html.js +5 -0
- package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
- package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
- package/node_modules/hono/dist/cjs/utils/url.js +23 -11
- package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
- package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/client/utils.js +9 -5
- package/node_modules/hono/dist/context.js +1 -1
- package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/helper/css/common.js +11 -8
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/hono-base.js +9 -10
- package/node_modules/hono/dist/hono.js +0 -1
- package/node_modules/hono/dist/jsx/base.js +51 -34
- package/node_modules/hono/dist/jsx/components.js +2 -2
- package/node_modules/hono/dist/jsx/constants.js +2 -1
- package/node_modules/hono/dist/jsx/context.js +15 -2
- package/node_modules/hono/dist/jsx/dom/components.js +2 -2
- package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
- package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
- package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
- package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
- package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
- package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
- package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
- package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
- package/node_modules/hono/dist/utils/body.js +2 -1
- package/node_modules/hono/dist/utils/cookie.js +3 -3
- package/node_modules/hono/dist/utils/html.js +5 -0
- package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/utils/mime.js +3 -2
- package/node_modules/hono/dist/utils/mount.js +58 -0
- package/node_modules/hono/dist/utils/url.js +23 -11
- package/node_modules/hono/dist/validator/validator.js +5 -5
- package/node_modules/hono/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { HtmlEscaped, HtmlEscapedString, StringBufferWithCallbacks } from "../utils/html.js";
|
|
1
|
+
import { HtmlEscaped, HtmlEscapedString, StringBuffer, StringBufferWithCallbacks } from "../utils/html.js";
|
|
2
2
|
import { DOM_MEMO } from "./constants.js";
|
|
3
3
|
import { JSX as JSX$1 } from "./intrinsic-elements.js";
|
|
4
4
|
import { Context } from "./context.js";
|
|
5
5
|
//#region src/jsx/base.d.ts
|
|
6
6
|
export type Props = Record<string, any>;
|
|
7
|
-
type
|
|
7
|
+
type FunctionComponentValue = HtmlEscapedString | Child;
|
|
8
|
+
type FunctionComponentResult = FunctionComponentValue | Promise<FunctionComponentValue>;
|
|
8
9
|
export type FC<P = Props> = {
|
|
9
10
|
(props: P): FunctionComponentResult;
|
|
10
11
|
defaultProps?: Partial<P> | undefined;
|
|
@@ -25,7 +26,9 @@ export declare namespace JSX {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
export declare const getNameSpaceContext: () => Context<string> | undefined;
|
|
28
|
-
export declare const booleanAttributes: string
|
|
29
|
+
export declare const booleanAttributes: Set<string>;
|
|
30
|
+
export declare const markRenderedJSX: (value: HtmlEscapedString) => HtmlEscapedString;
|
|
31
|
+
export declare const attributeToBuffer: (buffer: StringBuffer, prefix: string, key: string, v: unknown, tag?: string) => void;
|
|
29
32
|
export type Child = string | Promise<string> | number | JSXNode | null | undefined | boolean | Child[];
|
|
30
33
|
export declare const renderChildren: (children: Child[]) => HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
31
34
|
export declare const isUntrustedObject: (value: unknown) => boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HtmlEscapedString } from "../utils/html.js";
|
|
2
|
-
import { PropsWithChildren } from "./
|
|
3
|
-
import { Child, FC } from "./
|
|
2
|
+
import { PropsWithChildren } from "./index.js";
|
|
3
|
+
import { Child, FC } from "./index.js";
|
|
4
4
|
//#region src/jsx/components.d.ts
|
|
5
5
|
export declare const childrenToString: (children: Child[]) => Promise<HtmlEscapedString[]>;
|
|
6
6
|
export type ErrorHandler = (error: Error) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PropsWithChildren } from "./
|
|
2
|
-
import { FC } from "./
|
|
1
|
+
import { PropsWithChildren } from "./index.js";
|
|
2
|
+
import { FC } from "./index.js";
|
|
3
3
|
//#region src/jsx/context.d.ts
|
|
4
4
|
export interface Context<T> extends FC<PropsWithChildren<{
|
|
5
5
|
value: T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ErrorHandler, FallbackRender } from "../components.js";
|
|
2
|
-
import { PropsWithChildren } from "../
|
|
3
|
-
import { Child, FC } from "../
|
|
2
|
+
import { PropsWithChildren } from "../index.js";
|
|
3
|
+
import { Child, FC } from "../index.js";
|
|
4
4
|
//#region src/jsx/dom/components.d.ts
|
|
5
5
|
export declare const ErrorBoundary: FC<PropsWithChildren<{
|
|
6
6
|
fallback?: Child;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClassNameSlug, CssClassName, CssVariableType, OnInvalidSlug, rawCssString } from "../../helper/css/common.js";
|
|
2
|
-
import { PropsWithChildren } from "../
|
|
3
|
-
import { FC } from "../
|
|
2
|
+
import { PropsWithChildren } from "../index.js";
|
|
3
|
+
import { FC } from "../index.js";
|
|
4
4
|
//#region src/jsx/dom/css.d.ts
|
|
5
5
|
interface CreateCssJsxDomObjectsType {
|
|
6
6
|
(args: {
|
|
@@ -27,12 +27,14 @@ export declare const useFormStatus: () => FormStatus;
|
|
|
27
27
|
*/
|
|
28
28
|
export declare const useOptimistic: <T, N>(state: T, updateState: (currentState: T, action: N) => T) => [T, (action: N) => void];
|
|
29
29
|
/**
|
|
30
|
-
* This hook returns the current state
|
|
30
|
+
* This hook returns the current state, a function to update the state by form action,
|
|
31
|
+
* and whether an action is pending
|
|
32
|
+
* Actions run one at a time, each receiving the state returned by the previous one
|
|
31
33
|
* @param fn
|
|
32
34
|
* @param initialState
|
|
33
35
|
* @param permalink
|
|
34
|
-
* @returns [T, (data: FormData) => void]
|
|
36
|
+
* @returns [T, (data: FormData) => Promise<void>, boolean]
|
|
35
37
|
*/
|
|
36
|
-
export declare const useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function];
|
|
38
|
+
export declare const useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function, boolean];
|
|
37
39
|
//#endregion
|
|
38
40
|
export {};
|
|
@@ -51,7 +51,7 @@ declare const _default: {
|
|
|
51
51
|
method: "get" | "post";
|
|
52
52
|
action: string | ((formData: FormData) => void | Promise<void>);
|
|
53
53
|
};
|
|
54
|
-
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function];
|
|
54
|
+
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function, boolean];
|
|
55
55
|
useOptimistic: <T, N>(state: T, updateState: (currentState: T, action: N) => T) => [T, (action: N) => void];
|
|
56
56
|
Suspense: FC<PropsWithChildren<{
|
|
57
57
|
fallback: any;
|
|
@@ -74,7 +74,7 @@ declare const _default: {
|
|
|
74
74
|
method: "get" | "post";
|
|
75
75
|
action: string | ((formData: FormData) => void | Promise<void>);
|
|
76
76
|
};
|
|
77
|
-
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function];
|
|
77
|
+
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function, boolean];
|
|
78
78
|
useOptimistic: <T, N>(state: T, updateState: (currentState: T, action: N) => T) => [T, (action: N) => void];
|
|
79
79
|
Suspense: FC<PropsWithChildren<{
|
|
80
80
|
fallback: any;
|
|
@@ -55,7 +55,7 @@ declare const _default: {
|
|
|
55
55
|
}) => JSX$1.Element);
|
|
56
56
|
useImperativeHandle: <T>(ref: RefObject<T | null>, createHandle: () => T, deps: readonly unknown[]) => void;
|
|
57
57
|
useSyncExternalStore: <T>(subscribe: (callback: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T) => T;
|
|
58
|
-
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function];
|
|
58
|
+
useActionState: <T>(fn: Function, initialState: T, permalink?: string) => [T, Function, boolean];
|
|
59
59
|
useOptimistic: <T, N>(state: T, updateState: (currentState: T, action: N) => T) => [T, (action: N) => void];
|
|
60
60
|
Suspense: FC<PropsWithChildren<{
|
|
61
61
|
fallback: any;
|
|
@@ -3,7 +3,8 @@ import { html } from "../helper/html/index.js";
|
|
|
3
3
|
import { Fragment, JSX } from "./base.js";
|
|
4
4
|
import { jsxDEV } from "./jsx-dev-runtime.js";
|
|
5
5
|
//#region src/jsx/jsx-runtime.d.ts
|
|
6
|
+
export declare const jsxTemplate: typeof html;
|
|
6
7
|
export declare const jsxAttr: (key: string, v: string | Promise<string> | Record<string, string | number | null | undefined | boolean>) => HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
7
8
|
export declare const jsxEscape: (value: string) => string;
|
|
8
9
|
//#endregion
|
|
9
|
-
export { Fragment, type JSX, jsxDEV as jsx,
|
|
10
|
+
export { Fragment, type JSX, jsxDEV as jsx, jsxDEV as jsxs };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HtmlEscapedString } from "../utils/html.js";
|
|
2
|
-
import { PropsWithChildren } from "./
|
|
3
|
-
import { Context } from "./
|
|
4
|
-
import { FC
|
|
2
|
+
import { PropsWithChildren } from "./index.js";
|
|
3
|
+
import { Context } from "./index.js";
|
|
4
|
+
import { FC } from "./index.js";
|
|
5
|
+
import { JSXNode } from "./base.js";
|
|
5
6
|
//#region src/jsx/streaming.d.ts
|
|
6
7
|
/**
|
|
7
8
|
* Used to specify nonce for scripts generated by `Suspense` and `ErrorBoundary`.
|
|
@@ -29,6 +29,7 @@ type BasicAuthOptions = {
|
|
|
29
29
|
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
30
30
|
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
31
31
|
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
32
|
+
* @param {...{ username: string; password: string }} [users] - Additional user credentials.
|
|
32
33
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
33
34
|
* @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
|
|
34
35
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Env, MiddlewareHandler } from "../../types.js";
|
|
2
2
|
import { Context } from "../../context.js";
|
|
3
3
|
//#region src/middleware/bearer-auth/index.d.ts
|
|
4
|
-
type
|
|
4
|
+
type MessageValue = string | object | Response;
|
|
5
|
+
type MessageFunction = (c: Context) => MessageValue | Promise<MessageValue>;
|
|
5
6
|
type CustomizedErrorResponseOptions = {
|
|
6
7
|
wwwAuthenticateHeader?: string | object | MessageFunction;
|
|
7
8
|
message?: string | object | MessageFunction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MiddlewareHandler } from "../../
|
|
2
|
-
import { Context } from "../../
|
|
3
|
-
import { AddressType, GetConnInfo } from "../../helper/conninfo/
|
|
1
|
+
import { MiddlewareHandler } from "../../index.js";
|
|
2
|
+
import { Context } from "../../index.js";
|
|
3
|
+
import { AddressType, GetConnInfo } from "../../helper/conninfo/index.js";
|
|
4
4
|
//#region src/middleware/ip-restriction/index.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Function to get IP Address
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Env, Input, MiddlewareHandler } from "../../types.js";
|
|
2
2
|
import { Context, PropsForRenderer } from "../../context.js";
|
|
3
|
-
import { PropsWithChildren } from "../../jsx/
|
|
4
|
-
import { Context as Context$1 } from "../../jsx/
|
|
5
|
-
import { FC } from "../../jsx/
|
|
3
|
+
import { PropsWithChildren } from "../../jsx/index.js";
|
|
4
|
+
import { Context as Context$1 } from "../../jsx/index.js";
|
|
5
|
+
import { FC } from "../../jsx/index.js";
|
|
6
6
|
//#region src/middleware/jsx-renderer/index.d.ts
|
|
7
7
|
export declare const RequestContext: Context$1<Context<any, any, {}> | null>;
|
|
8
8
|
type RendererOptions = {
|
|
@@ -16,6 +16,8 @@ type MountOptions = MountOptionHandler | {
|
|
|
16
16
|
* @param {Function} applicationHandler - other Request Handler
|
|
17
17
|
* @param {MountOptions} [options] - options of `mount()`
|
|
18
18
|
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
19
|
+
* @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
|
|
20
|
+
* @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
|
|
19
21
|
*
|
|
20
22
|
* @example
|
|
21
23
|
* ```ts
|
|
@@ -12,10 +12,10 @@ export type RequestIdOptions = {
|
|
|
12
12
|
/**
|
|
13
13
|
* Request ID Middleware for Hono.
|
|
14
14
|
*
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {RequestIdOptions} [options] - Options for Request ID middleware.
|
|
16
16
|
* @param {number} [options.limitLength=255] - The maximum length of request id.
|
|
17
|
-
* @param {string} [options.headerName=X-Request-Id] - The header name used in request id.
|
|
18
|
-
* @param {
|
|
17
|
+
* @param {string} [options.headerName='X-Request-Id'] - The header name used in request id.
|
|
18
|
+
* @param {(c: Context) => string} [options.generator=() => crypto.randomUUID()] - The request id generation function.
|
|
19
19
|
*
|
|
20
20
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
21
21
|
*
|
|
@@ -68,6 +68,7 @@ interface SecureHeadersOptions {
|
|
|
68
68
|
xXssProtection?: overridableHeader;
|
|
69
69
|
removePoweredBy?: boolean;
|
|
70
70
|
permissionsPolicy?: PermissionsPolicyOptions;
|
|
71
|
+
overwrite?: boolean;
|
|
71
72
|
}
|
|
72
73
|
export declare const NONCE: ContentSecurityPolicyOptionHandler;
|
|
73
74
|
/**
|
|
@@ -94,6 +95,7 @@ export declare const NONCE: ContentSecurityPolicyOptionHandler;
|
|
|
94
95
|
* @param {overridableHeader} [customOptions.xXssProtection=true] - Settings for the X-XSS-Protection header.
|
|
95
96
|
* @param {boolean} [customOptions.removePoweredBy=true] - Settings for remove X-Powered-By header.
|
|
96
97
|
* @param {PermissionsPolicyOptions} [customOptions.permissionsPolicy] - Settings for the Permissions-Policy header.
|
|
98
|
+
* @param {boolean} [customOptions.overwrite=true] - Whether to replace a header that the response already has. Set `false` to keep a header that a handler set itself.
|
|
97
99
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
98
100
|
*
|
|
99
101
|
* @example
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/router/reg-exp-router/node.d.ts
|
|
2
2
|
export declare const LABEL_REG_EXP_STR = "[^/]+";
|
|
3
|
-
export declare const ONLY_WILDCARD_REG_EXP_STR = "
|
|
4
|
-
export declare const TAIL_WILDCARD_REG_EXP_STR = "(
|
|
3
|
+
export declare const ONLY_WILDCARD_REG_EXP_STR = "[^]*";
|
|
4
|
+
export declare const TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
|
|
5
5
|
export declare const PATH_ERROR: unique symbol;
|
|
6
6
|
export type ParamAssocArray = [string, number][];
|
|
7
7
|
export interface Context {
|
|
@@ -9,7 +9,7 @@ export interface Context {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class Node {
|
|
11
11
|
|
|
12
|
-
insert(tokens: readonly string[], index: number, paramMap: ParamAssocArray, context: Context,
|
|
12
|
+
insert(tokens: readonly string[], index: number, paramMap: ParamAssocArray, context: Context, keys: string[]): void;
|
|
13
13
|
buildRegExpStr(): string;
|
|
14
14
|
}
|
|
15
15
|
//#endregion
|
|
@@ -3,7 +3,7 @@ import { ParamAssocArray } from "./node.js";
|
|
|
3
3
|
export type ReplacementMap = number[];
|
|
4
4
|
export declare class Trie {
|
|
5
5
|
|
|
6
|
-
paths: Record<string, [number, ParamAssocArray]>;
|
|
6
|
+
paths: Record<string, [number, ParamAssocArray, string[]]>;
|
|
7
7
|
insert(path: string, isStatic: boolean): void;
|
|
8
8
|
buildRegExp(): [RegExp, ReplacementMap, ReplacementMap];
|
|
9
9
|
}
|
|
@@ -33,7 +33,7 @@ export type CookieOptions = {
|
|
|
33
33
|
prefix?: CookiePrefixOptions;
|
|
34
34
|
} & PartitionedCookieConstraint;
|
|
35
35
|
export type CookiePrefixOptions = 'host' | 'secure';
|
|
36
|
-
export type CookieConstraint<Name> = Name extends `
|
|
36
|
+
export type CookieConstraint<Name> = Lowercase<Name & string> extends `__secure-${string}` ? CookieOptions & SecureCookieConstraint : Lowercase<Name & string> extends `__host-${string}` ? CookieOptions & HostCookieConstraint : CookieOptions;
|
|
37
37
|
export declare const parse: (cookie: string, name?: string) => Cookie;
|
|
38
38
|
export declare const parseSigned: (cookie: string, secret: string | BufferSource, name?: string) => Promise<SignedCookie>;
|
|
39
39
|
export declare const serialize: <Name extends string>(name: Name, value: string, opt?: CookieConstraint<Name>) => string;
|
|
@@ -4,10 +4,10 @@ import { JWTPayload } from "./types.js";
|
|
|
4
4
|
//#region src/utils/jwt/jwt.d.ts
|
|
5
5
|
export interface TokenHeader {
|
|
6
6
|
alg: SignatureAlgorithm;
|
|
7
|
-
typ?:
|
|
7
|
+
typ?: string;
|
|
8
8
|
kid?: string;
|
|
9
9
|
}
|
|
10
|
-
export declare function isTokenHeader(obj: unknown): obj is TokenHeader;
|
|
10
|
+
export declare function isTokenHeader(obj: unknown, typ?: string | string[]): obj is TokenHeader;
|
|
11
11
|
export declare const sign: (payload: JWTPayload, privateKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<string>;
|
|
12
12
|
export type VerifyOptions = {
|
|
13
13
|
/** The expected issuer used for verifying the token */
|
|
@@ -20,6 +20,8 @@ export type VerifyOptions = {
|
|
|
20
20
|
iat?: boolean;
|
|
21
21
|
/** Acceptable audience(s) for the token */
|
|
22
22
|
aud?: string | string[] | RegExp;
|
|
23
|
+
/** The expected `typ` header, for example `at+jwt` for OAuth 2.0 access tokens. When set, the token must have it (default: `JWT`, or no `typ`) */
|
|
24
|
+
typ?: string | string[];
|
|
23
25
|
};
|
|
24
26
|
export type VerifyOptionsWithAlg = {
|
|
25
27
|
/** The algorithm used for decoding the token */
|
|
@@ -35,11 +35,21 @@ export type JSONValue = JSONObject | JSONArray | JSONPrimitive;
|
|
|
35
35
|
* which defaults to `bigint | ReadonlyArray<bigint>`.
|
|
36
36
|
* You can set it to `never` to disable this check.
|
|
37
37
|
*/
|
|
38
|
-
export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T
|
|
38
|
+
export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = JSONParsedInner<T, TError, never>;
|
|
39
|
+
/**
|
|
40
|
+
* `true` when `T` is identical to a type in `TSeen`, a union of one-element tuples.
|
|
41
|
+
*/
|
|
42
|
+
type IsSeen<T, TSeen> = TSeen extends unknown ? (<G>() => G extends [T] ? 1 : 2) extends (<G>() => G extends TSeen ? 1 : 2) ? true : never : never;
|
|
43
|
+
/**
|
|
44
|
+
* A recursive type such as `JSONValue` refers to itself, so `JSONParsed` cannot expand it to the end.
|
|
45
|
+
* `TSeen` holds the types on the current path. A type that is already on the path becomes `JSONValue`.
|
|
46
|
+
*/
|
|
47
|
+
type JSONParsedInner<T, TError, TSeen> = [IsSeen<T, TSeen>] extends [never] ? JSONParsedStep<T, TError, TSeen | [T]> : JSONValue;
|
|
48
|
+
type JSONParsedStep<T, TError, TSeen> = T extends {
|
|
39
49
|
toJSON(): infer J;
|
|
40
50
|
} ? (() => J) extends (() => JSONPrimitive) ? J : (() => J) extends (() => {
|
|
41
51
|
toJSON(): unknown;
|
|
42
|
-
}) ? {} :
|
|
52
|
+
}) ? {} : JSONParsedInner<J, TError, TSeen> : T extends JSONPrimitive ? T : T extends InvalidJSONValue ? never : T extends ReadonlyArray<unknown> ? { [K in keyof T]: JSONParsedInner<InvalidToNull<T[K]>, TError, TSeen>; } extends (infer A) ? A extends ReadonlyArray<unknown> ? A : JSONParsedInner<InvalidToNull<T[number]>, TError, TSeen>[] : never : T extends Set<unknown> | Map<unknown, unknown> | Record<string, never> ? {} : T extends object ? T[keyof T] extends TError ? never : { [K in keyof OmitSymbolKeys<T> as IsInvalid<T[K]> extends true ? never : K]: boolean extends IsInvalid<T[K]> ? T extends Record<K, unknown> ? JSONParsedInner<T[K], TError, never> | undefined : JSONParsedInner<T[K], TError, never> : JSONParsedInner<T[K], TError, never>; } : T extends unknown ? T extends TError ? never : JSONValue : never;
|
|
43
53
|
/**
|
|
44
54
|
* Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
45
55
|
* @copyright from sindresorhus/type-fest
|
|
@@ -72,9 +72,10 @@ const handleParsingAllValues = (form, key, value) => {
|
|
|
72
72
|
* @param {BodyData} form - The form data object.
|
|
73
73
|
* @param {string} key - The dot notation key.
|
|
74
74
|
* @param {BodyDataValue} value - The value to assign.
|
|
75
|
+
* @param {{ count: number }} state - The state object tracking nesting depth.
|
|
75
76
|
*/
|
|
76
77
|
const handleParsingNestedValues = (form, key, value, state) => {
|
|
77
|
-
if (/(?:^|\.)__proto__\./.test(key)) return;
|
|
78
|
+
if (/(?:^|\.)(?:__proto__|constructor\.prototype)\./.test(key)) return;
|
|
78
79
|
let nestedForm = form;
|
|
79
80
|
const keys = key.split(".", 34);
|
|
80
81
|
if (keys.length > 33) throwNestingLimitExceeded();
|
|
@@ -55,7 +55,7 @@ const parse = (cookie, name) => {
|
|
|
55
55
|
const cookieName = trimCookieWhitespace(pairStr.substring(0, valueStartPos));
|
|
56
56
|
if (name && name !== cookieName || !relaxedCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) continue;
|
|
57
57
|
let cookieValue = trimCookieWhitespace(pairStr.substring(valueStartPos + 1));
|
|
58
|
-
if (cookieValue.startsWith("\"") && cookieValue.endsWith("\"")) cookieValue = cookieValue.slice(1, -1);
|
|
58
|
+
if (cookieValue.length >= 2 && cookieValue.startsWith("\"") && cookieValue.endsWith("\"")) cookieValue = cookieValue.slice(1, -1);
|
|
59
59
|
if (validCookieValueRegEx.test(cookieValue)) {
|
|
60
60
|
parsedCookie[cookieName] = tryDecodeURIComponent(cookieValue);
|
|
61
61
|
if (name) break;
|
|
@@ -79,8 +79,8 @@ const parseSigned = async (cookie, secret, name) => {
|
|
|
79
79
|
const _serialize = (name, value, opt = {}) => {
|
|
80
80
|
if (!validCookieNameRegEx.test(name)) throw new Error("Invalid cookie name");
|
|
81
81
|
let cookie = `${name}=${value}`;
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
82
|
+
if (/^__secure-/i.test(name) && !opt.secure) throw new Error("__Secure- Cookie must have Secure attributes");
|
|
83
|
+
if (/^__host-/i.test(name)) {
|
|
84
84
|
if (!opt.secure) throw new Error("__Host- Cookie must have Secure attributes");
|
|
85
85
|
if (opt.path !== "/") throw new Error("__Host- Cookie must have Path attributes with \"/\"");
|
|
86
86
|
if (opt.domain) throw new Error("__Host- Cookie must not have Domain attributes");
|
|
@@ -24,6 +24,11 @@ const stringBufferToString = async (buffer, callbacks) => {
|
|
|
24
24
|
i--;
|
|
25
25
|
if (i < 0) break;
|
|
26
26
|
let r = resolvedBuffer[i];
|
|
27
|
+
if (r == null || typeof r === "boolean") continue;
|
|
28
|
+
if (typeof r === "number") {
|
|
29
|
+
str += r;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
27
32
|
if (typeof r === "object") callbacks.push(...r.callbacks || []);
|
|
28
33
|
const isEscaped = r.isEscaped;
|
|
29
34
|
r = await (typeof r === "object" ? r.toString() : r);
|
|
@@ -12,10 +12,12 @@ import { signing, verifying } from "./jws.js";
|
|
|
12
12
|
const encodeJwtPart = (part) => encodeBase64Url(utf8Encoder.encode(JSON.stringify(part)).buffer).replace(/=/g, "");
|
|
13
13
|
const encodeSignaturePart = (buf) => encodeBase64Url(buf).replace(/=/g, "");
|
|
14
14
|
const decodeJwtPart = (part) => JSON.parse(utf8Decoder.decode(decodeBase64Url(part)));
|
|
15
|
-
|
|
15
|
+
const normalizeTyp = (typ) => typ.toLowerCase().replace(/^application\//, "");
|
|
16
|
+
const isTyp = (value, expected) => typeof value === "string" && [expected].flat().some((typ) => normalizeTyp(typ) === normalizeTyp(value));
|
|
17
|
+
function isTokenHeader(obj, typ) {
|
|
16
18
|
if (typeof obj === "object" && obj !== null) {
|
|
17
19
|
const objWithAlg = obj;
|
|
18
|
-
return "alg" in objWithAlg && Object.values(AlgorithmTypes).includes(objWithAlg.alg) && (!("typ" in objWithAlg) || objWithAlg.typ
|
|
20
|
+
return "alg" in objWithAlg && Object.values(AlgorithmTypes).includes(objWithAlg.alg) && (typ === void 0 ? !("typ" in objWithAlg) || isTyp(objWithAlg.typ, "JWT") : isTyp(objWithAlg.typ, typ)) && !("crit" in objWithAlg);
|
|
19
21
|
}
|
|
20
22
|
return false;
|
|
21
23
|
}
|
|
@@ -39,12 +41,12 @@ const sign = async (payload, privateKey, alg = "HS256") => {
|
|
|
39
41
|
};
|
|
40
42
|
const verify = async (token, publicKey, algOrOptions) => {
|
|
41
43
|
if (!algOrOptions) throw new JwtAlgorithmRequired();
|
|
42
|
-
const { alg, iss, nbf = true, exp = true, iat = true, aud } = typeof algOrOptions === "string" ? { alg: algOrOptions } : algOrOptions;
|
|
44
|
+
const { alg, iss, nbf = true, exp = true, iat = true, aud, typ } = typeof algOrOptions === "string" ? { alg: algOrOptions } : algOrOptions;
|
|
43
45
|
if (!alg) throw new JwtAlgorithmRequired();
|
|
44
46
|
const tokenParts = token.split(".");
|
|
45
47
|
if (tokenParts.length !== 3) throw new JwtTokenInvalid(token);
|
|
46
48
|
const { header, payload } = decode(token);
|
|
47
|
-
if (!isTokenHeader(header)) throw new JwtHeaderInvalid(header);
|
|
49
|
+
if (!isTokenHeader(header, typ)) throw new JwtHeaderInvalid(header);
|
|
48
50
|
if (header.alg !== alg) throw new JwtAlgorithmMismatch(alg, header.alg);
|
|
49
51
|
const now = Math.floor(Date.now() / 1e3);
|
|
50
52
|
if (nbf && payload.nbf !== void 0) {
|
|
@@ -72,6 +74,7 @@ const verify = async (token, publicKey, algOrOptions) => {
|
|
|
72
74
|
} catch {
|
|
73
75
|
throw new JwtTokenInvalid(token);
|
|
74
76
|
}
|
|
77
|
+
if (encodeSignaturePart(signature.buffer) !== tokenParts[2]) throw new JwtTokenInvalid(token);
|
|
75
78
|
if (!await verifying(publicKey, alg, signature, utf8Encoder.encode(headerPayload))) throw new JwtTokenSignatureMismatched(token);
|
|
76
79
|
return payload;
|
|
77
80
|
};
|
|
@@ -83,7 +86,7 @@ const symmetricAlgorithms = [
|
|
|
83
86
|
const verifyWithJwks = async (token, options, init) => {
|
|
84
87
|
const verifyOpts = options.verification || {};
|
|
85
88
|
const header = decodeHeader(token);
|
|
86
|
-
if (!isTokenHeader(header)) throw new JwtHeaderInvalid(header);
|
|
89
|
+
if (!isTokenHeader(header, verifyOpts.typ)) throw new JwtHeaderInvalid(header);
|
|
87
90
|
if (!header.kid) throw new JwtHeaderRequiresKid(header);
|
|
88
91
|
if (symmetricAlgorithms.includes(header.alg)) throw new JwtSymmetricAlgorithmNotAllowed(header.alg);
|
|
89
92
|
if (!options.allowedAlgorithms.includes(header.alg)) throw new JwtAlgorithmNotAllowed(header.alg, options.allowedAlgorithms);
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
const getMimeType = (filename, mimes = baseMimes) => {
|
|
7
7
|
const match = filename.match(/\.([a-zA-Z0-9]+?)$/);
|
|
8
8
|
if (!match) return;
|
|
9
|
-
|
|
9
|
+
const mimeType = mimes[match[1].toLowerCase()];
|
|
10
|
+
return typeof mimeType === "string" ? mimeType : void 0;
|
|
10
11
|
};
|
|
11
12
|
const getExtension = (mimeType) => {
|
|
12
|
-
const baseType = mimeType.split(";", 1)[0].trim();
|
|
13
|
+
const baseType = mimeType.split(";", 1)[0].trim().toLowerCase();
|
|
13
14
|
for (const ext in baseMimes) {
|
|
14
15
|
const stored = baseMimes[ext];
|
|
15
16
|
if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) return ext;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HTTPException } from "../http-exception.js";
|
|
2
|
+
import { GET_MATCH_RESULT } from "../request/constants.js";
|
|
3
|
+
import { getPattern, splitRoutingPath, tryDecode } from "./url.js";
|
|
4
|
+
//#region src/utils/mount.ts
|
|
5
|
+
const countTrailingSlashes = (path) => {
|
|
6
|
+
let index = path.length;
|
|
7
|
+
while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
|
|
8
|
+
return path.length - index;
|
|
9
|
+
};
|
|
10
|
+
const getPathPrefixLength = (c, pathPrefix, routePath) => {
|
|
11
|
+
if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
|
|
12
|
+
const path = c.req.path;
|
|
13
|
+
const matchResult = c.req[GET_MATCH_RESULT];
|
|
14
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
15
|
+
let length = 0;
|
|
16
|
+
for (const part of splitRoutingPath(pathPrefix)) {
|
|
17
|
+
if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
|
|
18
|
+
const pattern = getPattern(part);
|
|
19
|
+
if (pattern && pattern !== "*") {
|
|
20
|
+
const name = pattern[1];
|
|
21
|
+
if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
|
|
22
|
+
paramNames.add(name);
|
|
23
|
+
}
|
|
24
|
+
if (pattern && pattern !== "*" && pattern[2] !== true) {
|
|
25
|
+
const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
|
|
26
|
+
length += value.length + 1;
|
|
27
|
+
} else if (pattern || part.endsWith("*")) {
|
|
28
|
+
const end = path.indexOf("/", length + 1);
|
|
29
|
+
length = end === -1 ? path.length : end;
|
|
30
|
+
} else length += part.length + 1;
|
|
31
|
+
}
|
|
32
|
+
return length;
|
|
33
|
+
};
|
|
34
|
+
const createMountedRequest = (c, pathPrefix, routePath) => {
|
|
35
|
+
if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
|
|
36
|
+
const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
|
|
37
|
+
const path = c.req.path.slice(prefixLength) || "/";
|
|
38
|
+
if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
39
|
+
const rawUrl = c.req.raw.url;
|
|
40
|
+
if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
41
|
+
const rawPathEnd = rawUrl.search(/[?#]/);
|
|
42
|
+
const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
|
|
43
|
+
if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
44
|
+
const url = new URL(rawUrl);
|
|
45
|
+
url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
46
|
+
if (path.includes("%")) {
|
|
47
|
+
let decoded;
|
|
48
|
+
try {
|
|
49
|
+
decoded = decodeURI(path);
|
|
50
|
+
} catch {}
|
|
51
|
+
if (decoded === void 0) {
|
|
52
|
+
if (tryDecode(url.pathname, (value) => decodeURI(value.replace(/%25/g, "%2525"))) !== path) throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return new Request(url, c.req.raw);
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createMountedRequest };
|
|
@@ -41,11 +41,11 @@ const getPattern = (label, next) => {
|
|
|
41
41
|
if (match[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
42
42
|
cacheKey,
|
|
43
43
|
match[1],
|
|
44
|
-
new RegExp(
|
|
44
|
+
new RegExp(`^(?:${match[2]})(?=/${next})`)
|
|
45
45
|
] : [
|
|
46
46
|
label,
|
|
47
47
|
match[1],
|
|
48
|
-
new RegExp(
|
|
48
|
+
new RegExp(`^(?:${match[2]})$`)
|
|
49
49
|
];
|
|
50
50
|
else patternCache[cacheKey] = [
|
|
51
51
|
label,
|
|
@@ -80,9 +80,10 @@ const tryDecode = (str, decoder) => {
|
|
|
80
80
|
* tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
|
|
81
81
|
*/
|
|
82
82
|
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
83
|
+
const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
|
|
83
84
|
const getPath = (request) => {
|
|
84
85
|
const url = request.url;
|
|
85
|
-
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
86
|
+
const start = url.charCodeAt(0) === 47 ? 0 : url.indexOf("/", url.indexOf(":") + 4);
|
|
86
87
|
let i = start;
|
|
87
88
|
for (; i < url.length; i++) {
|
|
88
89
|
const charCode = url.charCodeAt(i);
|
|
@@ -91,7 +92,13 @@ const getPath = (request) => {
|
|
|
91
92
|
const hashIndex = url.indexOf("#", i);
|
|
92
93
|
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
93
94
|
const path = url.slice(start, end);
|
|
94
|
-
|
|
95
|
+
const decoded = tryDecode(path, decodeURIWithPreservedPercent);
|
|
96
|
+
if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
|
|
97
|
+
const rewritten = new URL("http://localhost");
|
|
98
|
+
rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
99
|
+
if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
|
|
100
|
+
}
|
|
101
|
+
return decoded;
|
|
95
102
|
} else if (charCode === 63 || charCode === 35) break;
|
|
96
103
|
}
|
|
97
104
|
return url.slice(start, i);
|
|
@@ -152,17 +159,22 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
152
159
|
const hashIndex = url.indexOf("#", 8);
|
|
153
160
|
if (hashIndex !== -1) url = url.slice(0, hashIndex);
|
|
154
161
|
let encoded;
|
|
155
|
-
if (!multiple && key &&
|
|
156
|
-
|
|
162
|
+
if (!multiple && key && !/[%+&=]/.test(key)) {
|
|
163
|
+
const queryIndex = url.indexOf("?", 8);
|
|
164
|
+
let keyIndex = queryIndex;
|
|
157
165
|
if (keyIndex === -1) return;
|
|
158
166
|
if (!url.startsWith(key, keyIndex + 1)) keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
|
|
159
167
|
while (keyIndex !== -1) {
|
|
160
168
|
const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
|
|
161
|
-
if (trailingKeyCode === 61) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
|
|
170
|
+
if (keyIndex > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex))) break;
|
|
171
|
+
if (trailingKeyCode === 61) {
|
|
172
|
+
const valueIndex = keyIndex + key.length + 2;
|
|
173
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
174
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
175
|
+
}
|
|
176
|
+
return "";
|
|
177
|
+
}
|
|
166
178
|
keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
|
|
167
179
|
}
|
|
168
180
|
encoded = /[%+]/.test(url);
|
|
@@ -2,16 +2,16 @@ import { HTTPException } from "../http-exception.js";
|
|
|
2
2
|
import { bufferToFormData } from "../utils/buffer.js";
|
|
3
3
|
import { getCookie } from "../helper/cookie/index.js";
|
|
4
4
|
//#region src/validator/validator.ts
|
|
5
|
-
const jsonRegex = /^application\/([
|
|
6
|
-
const
|
|
7
|
-
const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
|
|
5
|
+
const jsonRegex = /^application\/([\w.-]+\+)?json$/i;
|
|
6
|
+
const getMediaType = (contentType) => contentType.split(";")[0].trim().toLowerCase();
|
|
8
7
|
const validator = (target, validationFunc) => {
|
|
9
8
|
return async (c, next) => {
|
|
10
9
|
let value = {};
|
|
11
10
|
const contentType = c.req.header("Content-Type");
|
|
11
|
+
const mediaType = contentType ? getMediaType(contentType) : "";
|
|
12
12
|
switch (target) {
|
|
13
13
|
case "json":
|
|
14
|
-
if (!
|
|
14
|
+
if (!jsonRegex.test(mediaType)) break;
|
|
15
15
|
try {
|
|
16
16
|
value = await c.req.json();
|
|
17
17
|
} catch {
|
|
@@ -19,7 +19,7 @@ const validator = (target, validationFunc) => {
|
|
|
19
19
|
}
|
|
20
20
|
break;
|
|
21
21
|
case "form": {
|
|
22
|
-
if (
|
|
22
|
+
if (mediaType !== "multipart/form-data" && mediaType !== "application/x-www-form-urlencoded") break;
|
|
23
23
|
let formData;
|
|
24
24
|
if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
|
|
25
25
|
else try {
|