@veruna/api-contracts 22.3.0 → 22.8.0
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/build/locales/en.d.ts +1 -1
- package/build/locales/en.js +1 -1
- package/build/locales/en.js.map +1 -1
- package/build/locales/index.d.ts +2 -2
- package/build/locales/ru.d.ts +1 -1
- package/build/locales/ru.js +1 -1
- package/build/locales/ru.js.map +1 -1
- package/build/locales/validation.d.ts +12 -2
- package/build/locales/validation.js +12 -2
- package/build/locales/validation.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/v1/ai-call/ai-call-request-params.schema.d.ts +8 -0
- package/build/v1/ai-call/ai-call-request-params.schema.js +16 -1
- package/build/v1/ai-call/ai-call-request-params.schema.js.map +1 -1
- package/build/v1/ai-call/ai-prompt-cache-mode.enum.d.ts +9 -0
- package/build/v1/ai-call/ai-prompt-cache-mode.enum.js +14 -0
- package/build/v1/ai-call/ai-prompt-cache-mode.enum.js.map +1 -0
- package/build/v1/ai-call/index.d.ts +1 -0
- package/build/v1/ai-call/index.js +1 -0
- package/build/v1/ai-call/index.js.map +1 -1
- package/build/v1/client-file/client-file-extensions.d.ts +21 -0
- package/build/v1/client-file/client-file-extensions.js +194 -0
- package/build/v1/client-file/client-file-extensions.js.map +1 -0
- package/build/v1/client-file/index.d.ts +1 -0
- package/build/v1/client-file/index.js +1 -0
- package/build/v1/client-file/index.js.map +1 -1
- package/build/v1/client-file/schemas/upload-magic-type.enum.d.ts +3 -0
- package/build/v1/client-file/schemas/upload-magic-type.enum.js +3 -0
- package/build/v1/client-file/schemas/upload-magic-type.enum.js.map +1 -1
- package/build/v1/client-file/upload-magic-bytes.d.ts +15 -23
- package/build/v1/client-file/upload-magic-bytes.js +75 -37
- package/build/v1/client-file/upload-magic-bytes.js.map +1 -1
- package/build/v1/message/schemas/create-message-request.schema.js +2 -4
- package/build/v1/message/schemas/create-message-request.schema.js.map +1 -1
- package/build/v1/model-route/admin/commands/create-model-route.command.d.ts +14 -0
- package/build/v1/model-route/admin/commands/update-model-route.command.d.ts +14 -0
- package/build/v1/model-route/admin/queries/get-model-route.query.d.ts +7 -0
- package/build/v1/model-route/admin/queries/list-model-routes-by-model.query.d.ts +7 -0
- package/build/v1/model-route/schemas/create-model-route-request.schema.d.ts +7 -0
- package/build/v1/model-route/schemas/create-model-route-request.schema.js +1 -1
- package/build/v1/model-route/schemas/create-model-route-request.schema.js.map +1 -1
- package/build/v1/model-route/schemas/index.d.ts +1 -0
- package/build/v1/model-route/schemas/index.js +1 -0
- package/build/v1/model-route/schemas/index.js.map +1 -1
- package/build/v1/model-route/schemas/list-model-routes-response.schema.d.ts +7 -0
- package/build/v1/model-route/schemas/model-route-response.schema.d.ts +7 -0
- package/build/v1/model-route/schemas/prompt-cache-ttl.enum.d.ts +8 -0
- package/build/v1/model-route/schemas/prompt-cache-ttl.enum.js +13 -0
- package/build/v1/model-route/schemas/prompt-cache-ttl.enum.js.map +1 -0
- package/build/v1/model-route/schemas/provider-generation-config.schema.d.ts +115 -0
- package/build/v1/model-route/schemas/provider-generation-config.schema.js +46 -1
- package/build/v1/model-route/schemas/provider-generation-config.schema.js.map +1 -1
- package/build/v1/model-route/schemas/update-model-route-request.schema.d.ts +7 -0
- package/build/v1/model-route/schemas/update-model-route-request.schema.js +1 -1
- package/build/v1/model-route/schemas/update-model-route-request.schema.js.map +1 -1
- package/build/v1/s2s/commands/upload-ai-file.command.d.ts +1 -0
- package/build/v1/s2s/schemas/s2s-upload-ai-file-response.schema.d.ts +1 -0
- package/build/v1/s2s/schemas/s2s-upload-ai-file-response.schema.js +1 -0
- package/build/v1/s2s/schemas/s2s-upload-ai-file-response.schema.js.map +1 -1
- package/build-esm/.tsbuildinfo +1 -1
- package/build-esm/locales/en.js +1 -1
- package/build-esm/locales/en.js.map +1 -1
- package/build-esm/locales/ru.js +1 -1
- package/build-esm/locales/ru.js.map +1 -1
- package/build-esm/locales/validation.js +12 -2
- package/build-esm/locales/validation.js.map +1 -1
- package/build-esm/v1/ai-call/ai-call-request-params.schema.js +15 -0
- package/build-esm/v1/ai-call/ai-call-request-params.schema.js.map +1 -1
- package/build-esm/v1/ai-call/ai-prompt-cache-mode.enum.js +11 -0
- package/build-esm/v1/ai-call/ai-prompt-cache-mode.enum.js.map +1 -0
- package/build-esm/v1/ai-call/index.js +1 -0
- package/build-esm/v1/ai-call/index.js.map +1 -1
- package/build-esm/v1/client-file/client-file-extensions.js +189 -0
- package/build-esm/v1/client-file/client-file-extensions.js.map +1 -0
- package/build-esm/v1/client-file/index.js +1 -0
- package/build-esm/v1/client-file/index.js.map +1 -1
- package/build-esm/v1/client-file/schemas/upload-magic-type.enum.js +3 -0
- package/build-esm/v1/client-file/schemas/upload-magic-type.enum.js.map +1 -1
- package/build-esm/v1/client-file/upload-magic-bytes.js +74 -36
- package/build-esm/v1/client-file/upload-magic-bytes.js.map +1 -1
- package/build-esm/v1/message/schemas/create-message-request.schema.js +2 -4
- package/build-esm/v1/message/schemas/create-message-request.schema.js.map +1 -1
- package/build-esm/v1/model-route/schemas/create-model-route-request.schema.js +2 -2
- package/build-esm/v1/model-route/schemas/create-model-route-request.schema.js.map +1 -1
- package/build-esm/v1/model-route/schemas/index.js +1 -0
- package/build-esm/v1/model-route/schemas/index.js.map +1 -1
- package/build-esm/v1/model-route/schemas/prompt-cache-ttl.enum.js +10 -0
- package/build-esm/v1/model-route/schemas/prompt-cache-ttl.enum.js.map +1 -0
- package/build-esm/v1/model-route/schemas/provider-generation-config.schema.js +44 -0
- package/build-esm/v1/model-route/schemas/provider-generation-config.schema.js.map +1 -1
- package/build-esm/v1/model-route/schemas/update-model-route-request.schema.js +2 -2
- package/build-esm/v1/model-route/schemas/update-model-route-request.schema.js.map +1 -1
- package/build-esm/v1/s2s/schemas/s2s-upload-ai-file-response.schema.js +1 -0
- package/build-esm/v1/s2s/schemas/s2s-upload-ai-file-response.schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ReasoningEffort } from '../ai/reasoning-effort.enum';
|
|
3
|
+
import { PromptCacheTtl } from '../model-route/schemas/prompt-cache-ttl.enum';
|
|
3
4
|
import { AiImageOperation } from './ai-image-operation.enum';
|
|
4
5
|
import { AiRouteSwitchKind } from './ai-route-switch-kind.enum';
|
|
6
|
+
import { AiPromptCacheMode } from './ai-prompt-cache-mode.enum';
|
|
5
7
|
/** Longest wire value kept for an aspect ratio, a resolution or a quality tier (`1024x1024`, `16:9`, `2K`). */
|
|
6
8
|
export declare const AI_CALL_PARAM_WIRE_MAX_LENGTH = 16;
|
|
7
9
|
/** Longest option id kept for an image style. */
|
|
@@ -9,6 +11,8 @@ export declare const AI_CALL_PARAM_STYLE_MAX_LENGTH = 32;
|
|
|
9
11
|
/** Ceiling of every counted parameter: far above any real request, far below the int32 range. */
|
|
10
12
|
export declare const AI_CALL_PARAM_COUNT_MAX = 1000000000;
|
|
11
13
|
export declare const AI_CALL_UPSTREAM_MAX_LENGTH = 128;
|
|
14
|
+
/** Hex characters of the prompt-prefix fingerprint (tools + shared system prefix). */
|
|
15
|
+
export declare const AI_CALL_PROMPT_PREFIX_HASH_LENGTH = 16;
|
|
12
16
|
/**
|
|
13
17
|
* The parameters of one upstream attempt that drive its price, stored as `ai_calls.request_params`. Every
|
|
14
18
|
* field is optional: a text call fills the text group, an image call the image group. Strings are the wire
|
|
@@ -22,6 +26,10 @@ export declare const AiCallRequestParamsSchema: z.ZodObject<{
|
|
|
22
26
|
inputImageCount: z.ZodOptional<z.ZodNumber>;
|
|
23
27
|
inputFileCount: z.ZodOptional<z.ZodNumber>;
|
|
24
28
|
upstreamProvider: z.ZodOptional<z.ZodString>;
|
|
29
|
+
promptPrefixHash: z.ZodOptional<z.ZodString>;
|
|
30
|
+
promptCacheMode: z.ZodOptional<z.ZodEnum<typeof AiPromptCacheMode>>;
|
|
31
|
+
promptCachePoints: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
promptCacheTtl: z.ZodOptional<z.ZodEnum<typeof PromptCacheTtl>>;
|
|
25
33
|
routeSwitch: z.ZodOptional<z.ZodObject<{
|
|
26
34
|
fromRouteId: z.ZodString;
|
|
27
35
|
kind: z.ZodEnum<typeof AiRouteSwitchKind>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AiCallRequestParamsSchema = exports.AI_CALL_UPSTREAM_MAX_LENGTH = exports.AI_CALL_PARAM_COUNT_MAX = exports.AI_CALL_PARAM_STYLE_MAX_LENGTH = exports.AI_CALL_PARAM_WIRE_MAX_LENGTH = void 0;
|
|
3
|
+
exports.AiCallRequestParamsSchema = exports.AI_CALL_PROMPT_PREFIX_HASH_LENGTH = exports.AI_CALL_UPSTREAM_MAX_LENGTH = exports.AI_CALL_PARAM_COUNT_MAX = exports.AI_CALL_PARAM_STYLE_MAX_LENGTH = exports.AI_CALL_PARAM_WIRE_MAX_LENGTH = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const reasoning_effort_enum_1 = require("../ai/reasoning-effort.enum");
|
|
6
|
+
const prompt_cache_ttl_enum_1 = require("../model-route/schemas/prompt-cache-ttl.enum");
|
|
6
7
|
const ai_image_operation_enum_1 = require("./ai-image-operation.enum");
|
|
7
8
|
const ai_route_switch_kind_enum_1 = require("./ai-route-switch-kind.enum");
|
|
9
|
+
const ai_prompt_cache_mode_enum_1 = require("./ai-prompt-cache-mode.enum");
|
|
8
10
|
/** Longest wire value kept for an aspect ratio, a resolution or a quality tier (`1024x1024`, `16:9`, `2K`). */
|
|
9
11
|
exports.AI_CALL_PARAM_WIRE_MAX_LENGTH = 16;
|
|
10
12
|
/** Longest option id kept for an image style. */
|
|
@@ -12,6 +14,8 @@ exports.AI_CALL_PARAM_STYLE_MAX_LENGTH = 32;
|
|
|
12
14
|
/** Ceiling of every counted parameter: far above any real request, far below the int32 range. */
|
|
13
15
|
exports.AI_CALL_PARAM_COUNT_MAX = 1_000_000_000;
|
|
14
16
|
exports.AI_CALL_UPSTREAM_MAX_LENGTH = 128;
|
|
17
|
+
/** Hex characters of the prompt-prefix fingerprint (tools + shared system prefix). */
|
|
18
|
+
exports.AI_CALL_PROMPT_PREFIX_HASH_LENGTH = 16;
|
|
15
19
|
const countSchema = zod_1.z.number().int().min(0).max(exports.AI_CALL_PARAM_COUNT_MAX);
|
|
16
20
|
const wireSchema = zod_1.z.string().min(1).max(exports.AI_CALL_PARAM_WIRE_MAX_LENGTH);
|
|
17
21
|
/**
|
|
@@ -33,6 +37,17 @@ exports.AiCallRequestParamsSchema = zod_1.z
|
|
|
33
37
|
inputFileCount: countSchema.optional(),
|
|
34
38
|
/** Actual upstream reported by the aggregator, not the configured preference. */
|
|
35
39
|
upstreamProvider: zod_1.z.string().min(1).max(exports.AI_CALL_UPSTREAM_MAX_LENGTH).optional(),
|
|
40
|
+
/** Fingerprint of what every user of the same toolset shares: the tools and the system prefix. */
|
|
41
|
+
promptPrefixHash: zod_1.z
|
|
42
|
+
.string()
|
|
43
|
+
.regex(new RegExp(`^[0-9a-f]{${exports.AI_CALL_PROMPT_PREFIX_HASH_LENGTH}}$`))
|
|
44
|
+
.optional(),
|
|
45
|
+
/** Who placed the prompt-cache points of the request. */
|
|
46
|
+
promptCacheMode: zod_1.z.enum(ai_prompt_cache_mode_enum_1.AiPromptCacheMode).optional(),
|
|
47
|
+
/** Cache points we asked for (explicit points plus an automatic one). */
|
|
48
|
+
promptCachePoints: countSchema.optional(),
|
|
49
|
+
/** The longest cache lifetime among those points. */
|
|
50
|
+
promptCacheTtl: zod_1.z.enum(prompt_cache_ttl_enum_1.PromptCacheTtl).optional(),
|
|
36
51
|
routeSwitch: zod_1.z
|
|
37
52
|
.object({
|
|
38
53
|
fromRouteId: zod_1.z.string().min(1).max(64),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-call-request-params.schema.js","sourceRoot":"","sources":["../../../v1/ai-call/ai-call-request-params.schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,uEAA8D;AAC9D,uEAA6D;AAC7D,2EAAgE;AAEhE,+GAA+G;AAClG,QAAA,6BAA6B,GAAG,EAAE,CAAC;AAChD,iDAAiD;AACpC,QAAA,8BAA8B,GAAG,EAAE,CAAC;AACjD,iGAAiG;AACpF,QAAA,uBAAuB,GAAG,aAAa,CAAC;AACxC,QAAA,2BAA2B,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-call-request-params.schema.js","sourceRoot":"","sources":["../../../v1/ai-call/ai-call-request-params.schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,uEAA8D;AAC9D,wFAA8E;AAC9E,uEAA6D;AAC7D,2EAAgE;AAChE,2EAAgE;AAEhE,+GAA+G;AAClG,QAAA,6BAA6B,GAAG,EAAE,CAAC;AAChD,iDAAiD;AACpC,QAAA,8BAA8B,GAAG,EAAE,CAAC;AACjD,iGAAiG;AACpF,QAAA,uBAAuB,GAAG,aAAa,CAAC;AACxC,QAAA,2BAA2B,GAAG,GAAG,CAAC;AAC/C,sFAAsF;AACzE,QAAA,iCAAiC,GAAG,EAAE,CAAC;AAEpD,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,+BAAuB,CAAC,CAAC;AACzE,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,qCAA6B,CAAC,CAAC;AAExE;;;;;GAKG;AACU,QAAA,yBAAyB,GAAG,OAAC;KACrC,MAAM,CAAC;IACJ,OAAO;IACP,eAAe,EAAE,OAAC,CAAC,IAAI,CAAC,uCAAe,CAAC,CAAC,QAAQ,EAAE;IACnD,eAAe,EAAE,WAAW,CAAC,QAAQ,EAAE;IACvC,4CA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AAC,QAAQ,EAAE;IAClC,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE;IACjC,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE;IAC9B,0CAA0C;IAC1C,UAAU,EAAE,WAAW,CAAC,QAAQ,EAAE;IAClC,sBAAsB;IACtB,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE;IAC7B,2BAA2B;IAC3B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sCAA8B,CAAC,CAAC,QAAQ,EAAE;CAC1E,CAAC;KACD,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Who placed the prompt-cache points of one upstream attempt (`ai_calls.request_params.promptCacheMode`). */
|
|
2
|
+
export declare enum AiPromptCacheMode {
|
|
3
|
+
/** We placed explicit points (Anthropic protocol, Gemini, OpenAI explicit mode). */
|
|
4
|
+
EXPLICIT = "EXPLICIT",
|
|
5
|
+
/** The provider caches on its own (OpenAI automatic caching, DeepSeek, Grok, resellers' OpenAI format). */
|
|
6
|
+
PROVIDER = "PROVIDER",
|
|
7
|
+
/** Caching was switched off for the call: no point, no write. */
|
|
8
|
+
OFF = "OFF"
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AiPromptCacheMode = void 0;
|
|
4
|
+
/** Who placed the prompt-cache points of one upstream attempt (`ai_calls.request_params.promptCacheMode`). */
|
|
5
|
+
var AiPromptCacheMode;
|
|
6
|
+
(function (AiPromptCacheMode) {
|
|
7
|
+
/** We placed explicit points (Anthropic protocol, Gemini, OpenAI explicit mode). */
|
|
8
|
+
AiPromptCacheMode["EXPLICIT"] = "EXPLICIT";
|
|
9
|
+
/** The provider caches on its own (OpenAI automatic caching, DeepSeek, Grok, resellers' OpenAI format). */
|
|
10
|
+
AiPromptCacheMode["PROVIDER"] = "PROVIDER";
|
|
11
|
+
/** Caching was switched off for the call: no point, no write. */
|
|
12
|
+
AiPromptCacheMode["OFF"] = "OFF";
|
|
13
|
+
})(AiPromptCacheMode || (exports.AiPromptCacheMode = AiPromptCacheMode = {}));
|
|
14
|
+
//# sourceMappingURL=ai-prompt-cache-mode.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-prompt-cache-mode.enum.js","sourceRoot":"","sources":["../../../v1/ai-call/ai-prompt-cache-mode.enum.ts"],"names":[],"mappings":";;;AAAA,8GAA8G;AAC9G,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IACzB,oFAAoF;IACpF,0CAAqB,CAAA;IACrB,2GAA2G;IAC3G,0CAAqB,CAAA;IACrB,iEAAiE;IACjE,gCAAW,CAAA;AACf,CAAC,EAPW,iBAAiB,iCAAjB,iBAAiB,QAO5B"}
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./ai-caller.enum"), exports);
|
|
18
18
|
__exportStar(require("./ai-route-switch-kind.enum"), exports);
|
|
19
|
+
__exportStar(require("./ai-prompt-cache-mode.enum"), exports);
|
|
19
20
|
__exportStar(require("./ai-cost-source.enum"), exports);
|
|
20
21
|
__exportStar(require("./ai-attempt-end-code.enum"), exports);
|
|
21
22
|
__exportStar(require("./ai-call.errors"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../v1/ai-call/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,8DAA4C;AAC5C,wDAAsC;AACtC,6DAA2C;AAC3C,mDAAiC;AACjC,4DAA0C;AAC1C,kEAAgD;AAChD,gEAA8C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../v1/ai-call/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,8DAA4C;AAC5C,8DAA4C;AAC5C,wDAAsC;AACtC,6DAA2C;AAC3C,mDAAiC;AACjC,4DAA0C;AAC1C,kEAAgD;AAChD,gEAA8C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ClientFileDocMimeType, ClientFileImageMimeType } from './schemas/client-file-mime-types';
|
|
2
|
+
/** A content type the upload allowlist admits. */
|
|
3
|
+
export type ClientFileAcceptedMimeType = ClientFileImageMimeType | ClientFileDocMimeType;
|
|
4
|
+
/** Every extension we recognise (lowercase, no dot) and the type a file with it is admitted as. */
|
|
5
|
+
export declare const CLIENT_FILE_CONTENT_TYPE_BY_EXTENSION: Readonly<Record<string, ClientFileAcceptedMimeType>>;
|
|
6
|
+
/** The type a file name stands for, or null when we do not know the name. */
|
|
7
|
+
export declare function resolveClientFileContentTypeByName(filename: string): ClientFileAcceptedMimeType | null;
|
|
8
|
+
/**
|
|
9
|
+
* Pick the type to verify an upload against. The declared type is a browser's guess from the OS
|
|
10
|
+
* registry: empty, `application/octet-stream`, `video/mp2t` for a `.ts`, `application/xml` for a
|
|
11
|
+
* `.svg`. When it is such a guess the name decides; when it is a specific type we accept, it stands
|
|
12
|
+
* (the caller may still prefer the name when the bytes contradict that type).
|
|
13
|
+
*
|
|
14
|
+
* `text/plain` is the one generic type that may only become another TEXT type. A text file named
|
|
15
|
+
* `.docx` is still a text file, and sending it to a document converter on the strength of its name
|
|
16
|
+
* would reject something that was fine as it was.
|
|
17
|
+
*
|
|
18
|
+
* Nothing here admits anything by itself: the result goes through the same signature check as a
|
|
19
|
+
* declared type, so a name cannot smuggle a format past the bytes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reconcileClientFileContentTypeByName(declaredContentType: string, filename: string): string;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIENT_FILE_CONTENT_TYPE_BY_EXTENSION = void 0;
|
|
4
|
+
exports.resolveClientFileContentTypeByName = resolveClientFileContentTypeByName;
|
|
5
|
+
exports.reconcileClientFileContentTypeByName = reconcileClientFileContentTypeByName;
|
|
6
|
+
const client_file_mime_types_1 = require("./schemas/client-file-mime-types");
|
|
7
|
+
/**
|
|
8
|
+
* Source and config formats that have no MIME type of their own anywhere browsers or servers agree on.
|
|
9
|
+
* They are admitted as `text/plain`: the bytes are checked like any text, and nothing about them is
|
|
10
|
+
* ever rendered. Markup (XML, SVG) belongs here on purpose — a browser draws it as a page or a picture
|
|
11
|
+
* when it is served under its own type, and plain text is never drawn.
|
|
12
|
+
*/
|
|
13
|
+
const PLAIN_TEXT_EXTENSIONS = [
|
|
14
|
+
'txt',
|
|
15
|
+
'text',
|
|
16
|
+
'log',
|
|
17
|
+
'xml',
|
|
18
|
+
'svg',
|
|
19
|
+
'jsx',
|
|
20
|
+
'tsx',
|
|
21
|
+
'scss',
|
|
22
|
+
'sass',
|
|
23
|
+
'less',
|
|
24
|
+
'vue',
|
|
25
|
+
'svelte',
|
|
26
|
+
'toml',
|
|
27
|
+
'ini',
|
|
28
|
+
'cfg',
|
|
29
|
+
'conf',
|
|
30
|
+
'env',
|
|
31
|
+
'properties',
|
|
32
|
+
'gradle',
|
|
33
|
+
'lua',
|
|
34
|
+
'r',
|
|
35
|
+
'pl',
|
|
36
|
+
'dart',
|
|
37
|
+
'ex',
|
|
38
|
+
'exs',
|
|
39
|
+
'hs',
|
|
40
|
+
'tf',
|
|
41
|
+
'graphql',
|
|
42
|
+
'gql',
|
|
43
|
+
'proto',
|
|
44
|
+
'mk',
|
|
45
|
+
'bat',
|
|
46
|
+
'ps1',
|
|
47
|
+
'tex',
|
|
48
|
+
'diff',
|
|
49
|
+
'patch',
|
|
50
|
+
'srt',
|
|
51
|
+
'vtt',
|
|
52
|
+
'ass',
|
|
53
|
+
'ssa',
|
|
54
|
+
'dockerfile',
|
|
55
|
+
'pas',
|
|
56
|
+
'xsd',
|
|
57
|
+
'xsl',
|
|
58
|
+
'xslt',
|
|
59
|
+
'ipynb',
|
|
60
|
+
'jsonl',
|
|
61
|
+
'ndjson',
|
|
62
|
+
'rst',
|
|
63
|
+
'adoc',
|
|
64
|
+
];
|
|
65
|
+
/** Every extension we recognise (lowercase, no dot) and the type a file with it is admitted as. */
|
|
66
|
+
exports.CLIENT_FILE_CONTENT_TYPE_BY_EXTENSION = {
|
|
67
|
+
...Object.fromEntries(PLAIN_TEXT_EXTENSIONS.map((extension) => [extension, 'text/plain'])),
|
|
68
|
+
html: 'text/html',
|
|
69
|
+
htm: 'text/html',
|
|
70
|
+
md: 'text/markdown',
|
|
71
|
+
markdown: 'text/markdown',
|
|
72
|
+
csv: 'text/csv',
|
|
73
|
+
tsv: 'text/tab-separated-values',
|
|
74
|
+
json: 'application/json',
|
|
75
|
+
yaml: 'text/yaml',
|
|
76
|
+
yml: 'text/yaml',
|
|
77
|
+
css: 'text/css',
|
|
78
|
+
js: 'text/javascript',
|
|
79
|
+
mjs: 'text/javascript',
|
|
80
|
+
cjs: 'text/javascript',
|
|
81
|
+
ts: 'text/x-typescript',
|
|
82
|
+
mts: 'text/x-typescript',
|
|
83
|
+
cts: 'text/x-typescript',
|
|
84
|
+
py: 'text/x-python',
|
|
85
|
+
java: 'text/x-java-source',
|
|
86
|
+
c: 'text/x-c',
|
|
87
|
+
h: 'text/x-c',
|
|
88
|
+
cpp: 'text/x-c++src',
|
|
89
|
+
cc: 'text/x-c++src',
|
|
90
|
+
cxx: 'text/x-c++src',
|
|
91
|
+
hpp: 'text/x-c++src',
|
|
92
|
+
cs: 'text/x-csharp',
|
|
93
|
+
go: 'text/x-go',
|
|
94
|
+
rs: 'text/x-rust',
|
|
95
|
+
rb: 'text/x-ruby',
|
|
96
|
+
php: 'text/x-php',
|
|
97
|
+
swift: 'text/x-swift',
|
|
98
|
+
kt: 'text/x-kotlin',
|
|
99
|
+
kts: 'text/x-kotlin',
|
|
100
|
+
scala: 'text/x-scala',
|
|
101
|
+
sql: 'text/x-sql',
|
|
102
|
+
sh: 'text/x-shellscript',
|
|
103
|
+
bash: 'text/x-shellscript',
|
|
104
|
+
zsh: 'text/x-shellscript',
|
|
105
|
+
pdf: 'application/pdf',
|
|
106
|
+
png: 'image/png',
|
|
107
|
+
jpg: 'image/jpeg',
|
|
108
|
+
jpeg: 'image/jpeg',
|
|
109
|
+
webp: 'image/webp',
|
|
110
|
+
doc: 'application/msword',
|
|
111
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
112
|
+
rtf: 'application/rtf',
|
|
113
|
+
odt: 'application/vnd.oasis.opendocument.text',
|
|
114
|
+
odp: 'application/vnd.oasis.opendocument.presentation',
|
|
115
|
+
ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
116
|
+
xls: 'application/vnd.ms-excel',
|
|
117
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
118
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
119
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
120
|
+
};
|
|
121
|
+
/** Files known by their whole name: they have no extension, or the dot is part of the name. */
|
|
122
|
+
const CONTENT_TYPE_BY_BASENAME = {
|
|
123
|
+
dockerfile: 'text/plain',
|
|
124
|
+
makefile: 'text/plain',
|
|
125
|
+
gnumakefile: 'text/plain',
|
|
126
|
+
rakefile: 'text/plain',
|
|
127
|
+
gemfile: 'text/plain',
|
|
128
|
+
procfile: 'text/plain',
|
|
129
|
+
'.gitignore': 'text/plain',
|
|
130
|
+
'.dockerignore': 'text/plain',
|
|
131
|
+
'.editorconfig': 'text/plain',
|
|
132
|
+
readme: 'text/plain',
|
|
133
|
+
license: 'text/plain',
|
|
134
|
+
jenkinsfile: 'text/plain',
|
|
135
|
+
vagrantfile: 'text/plain',
|
|
136
|
+
};
|
|
137
|
+
/** `.env.local`, `Dockerfile.dev`: the part after the dot is the environment, not the format. */
|
|
138
|
+
const TEXT_NAME_PREFIXES = ['.env.', 'dockerfile.'];
|
|
139
|
+
const PLAIN_TEXT = 'text/plain';
|
|
140
|
+
const TEXT_NATIVE_TYPES = new Set(client_file_mime_types_1.CLIENT_FILE_TEXT_NATIVE_MIME_TYPES);
|
|
141
|
+
const ACCEPTED_TYPES = new Set([
|
|
142
|
+
...client_file_mime_types_1.CLIENT_FILE_IMAGE_MIME_TYPES,
|
|
143
|
+
...client_file_mime_types_1.CLIENT_FILE_DOC_MIME_TYPES,
|
|
144
|
+
]);
|
|
145
|
+
function lookup(table, key) {
|
|
146
|
+
// `Object.hasOwn`: the name comes off the wire, and `constructor` must not resolve to a member.
|
|
147
|
+
return Object.hasOwn(table, key) ? table[key] : null;
|
|
148
|
+
}
|
|
149
|
+
/** The type a file name stands for, or null when we do not know the name. */
|
|
150
|
+
function resolveClientFileContentTypeByName(filename) {
|
|
151
|
+
const basename = (filename.split(/[\\/]/).pop() ?? '').trim().toLowerCase();
|
|
152
|
+
const byName = lookup(CONTENT_TYPE_BY_BASENAME, basename);
|
|
153
|
+
if (byName !== null) {
|
|
154
|
+
return byName;
|
|
155
|
+
}
|
|
156
|
+
if (TEXT_NAME_PREFIXES.some((prefix) => basename.startsWith(prefix))) {
|
|
157
|
+
return PLAIN_TEXT;
|
|
158
|
+
}
|
|
159
|
+
const dot = basename.lastIndexOf('.');
|
|
160
|
+
return dot === -1
|
|
161
|
+
? null
|
|
162
|
+
: lookup(exports.CLIENT_FILE_CONTENT_TYPE_BY_EXTENSION, basename.slice(dot + 1));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Pick the type to verify an upload against. The declared type is a browser's guess from the OS
|
|
166
|
+
* registry: empty, `application/octet-stream`, `video/mp2t` for a `.ts`, `application/xml` for a
|
|
167
|
+
* `.svg`. When it is such a guess the name decides; when it is a specific type we accept, it stands
|
|
168
|
+
* (the caller may still prefer the name when the bytes contradict that type).
|
|
169
|
+
*
|
|
170
|
+
* `text/plain` is the one generic type that may only become another TEXT type. A text file named
|
|
171
|
+
* `.docx` is still a text file, and sending it to a document converter on the strength of its name
|
|
172
|
+
* would reject something that was fine as it was.
|
|
173
|
+
*
|
|
174
|
+
* Nothing here admits anything by itself: the result goes through the same signature check as a
|
|
175
|
+
* declared type, so a name cannot smuggle a format past the bytes.
|
|
176
|
+
*/
|
|
177
|
+
function reconcileClientFileContentTypeByName(declaredContentType, filename) {
|
|
178
|
+
const named = resolveClientFileContentTypeByName(filename);
|
|
179
|
+
if (named === null) {
|
|
180
|
+
return declaredContentType;
|
|
181
|
+
}
|
|
182
|
+
// `text/plain` is what browsers put on source files they do not recognise, so it is no evidence.
|
|
183
|
+
if (declaredContentType !== PLAIN_TEXT && ACCEPTED_TYPES.has(declaredContentType)) {
|
|
184
|
+
return declaredContentType;
|
|
185
|
+
}
|
|
186
|
+
if (declaredContentType === PLAIN_TEXT && !isClientFileTextNativeMimeType(named)) {
|
|
187
|
+
return declaredContentType;
|
|
188
|
+
}
|
|
189
|
+
return named;
|
|
190
|
+
}
|
|
191
|
+
function isClientFileTextNativeMimeType(value) {
|
|
192
|
+
return TEXT_NATIVE_TYPES.has(value);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=client-file-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-file-extensions.js","sourceRoot":"","sources":["../../../v1/client-file/client-file-extensions.ts"],"names":[],"mappings":";;;AAsKA,gFAeC;AAeD,oFAgBC;AApND,6EAO0C;AAK1C;;;;;GAKG;AACH,MAAM,qBAAqB,GAAsB;IAC7C,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,QAAQ;IACR,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,YAAY;IACZ,QAAQ;IACR,KAAK;IACL,GAAG;IACH,IAAI;I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IAAI,cAAc,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAChF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IACD,IAAI,mBAAmB,KAAK,UAAU,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/E,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,8BAA8B,CAAC,KAAa;IACjD,OAAO,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -6,5 +6,6 @@ export * from './upload-magic-bytes';
|
|
|
6
6
|
export * from './attachment-coverage';
|
|
7
7
|
export * from './attachment-coverage.types';
|
|
8
8
|
export * from './client-file-content-kind';
|
|
9
|
+
export * from './client-file-extensions';
|
|
9
10
|
export * from './ai-file-policy.constants';
|
|
10
11
|
export * from './client-document.constants';
|
|
@@ -22,6 +22,7 @@ __exportStar(require("./upload-magic-bytes"), exports);
|
|
|
22
22
|
__exportStar(require("./attachment-coverage"), exports);
|
|
23
23
|
__exportStar(require("./attachment-coverage.types"), exports);
|
|
24
24
|
__exportStar(require("./client-file-content-kind"), exports);
|
|
25
|
+
__exportStar(require("./client-file-extensions"), exports);
|
|
25
26
|
__exportStar(require("./ai-file-policy.constants"), exports);
|
|
26
27
|
__exportStar(require("./client-document.constants"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../v1/client-file/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,8DAA4C;AAC5C,uDAAqC;AACrC,wDAAsC;AACtC,8DAA4C;AAC5C,6DAA2C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../v1/client-file/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,8DAA4C;AAC5C,uDAAqC;AACrC,wDAAsC;AACtC,8DAA4C;AAC5C,6DAA2C;AAC3C,2DAAyC;AAEzC,6DAA2C;AAE3C,8DAA4C"}
|
|
@@ -3,6 +3,9 @@ export declare enum UploadMagicType {
|
|
|
3
3
|
JPEG = "JPEG",
|
|
4
4
|
GIF = "GIF",
|
|
5
5
|
WEBP = "WEBP",
|
|
6
|
+
/** HEIC/HEIF — iPhone photos. Recognised for the diagnostic log only; not accepted. */
|
|
7
|
+
HEIF = "HEIF",
|
|
8
|
+
AVIF = "AVIF",
|
|
6
9
|
PDF = "PDF",
|
|
7
10
|
/** ZIP container. Every OOXML document (docx/xlsx/pptx) is one. */
|
|
8
11
|
ZIP = "ZIP",
|
|
@@ -7,6 +7,9 @@ var UploadMagicType;
|
|
|
7
7
|
UploadMagicType["JPEG"] = "JPEG";
|
|
8
8
|
UploadMagicType["GIF"] = "GIF";
|
|
9
9
|
UploadMagicType["WEBP"] = "WEBP";
|
|
10
|
+
/** HEIC/HEIF — iPhone photos. Recognised for the diagnostic log only; not accepted. */
|
|
11
|
+
UploadMagicType["HEIF"] = "HEIF";
|
|
12
|
+
UploadMagicType["AVIF"] = "AVIF";
|
|
10
13
|
UploadMagicType["PDF"] = "PDF";
|
|
11
14
|
/** ZIP container. Every OOXML document (docx/xlsx/pptx) is one. */
|
|
12
15
|
UploadMagicType["ZIP"] = "ZIP";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-magic-type.enum.js","sourceRoot":"","sources":["../../../../v1/client-file/schemas/upload-magic-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"upload-magic-type.enum.js","sourceRoot":"","sources":["../../../../v1/client-file/schemas/upload-magic-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAkBX;AAlBD,WAAY,eAAe;IACvB,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,uFAAuF;IACvF,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,8BAAW,CAAA;IACX,mEAAmE;IACnE,8BAAW,CAAA;IACX,kDAAkD;IAClD,gCAAa,CAAA;IACb,8BAAW,CAAA;IACX,sEAAsE;IACtE,4CAAyB,CAAA;IACzB,qFAAqF;IACrF,sCAAmB,CAAA;AACvB,CAAC,EAlBW,eAAe,+BAAf,eAAe,QAkB1B"}
|
|
@@ -35,33 +35,25 @@ export declare function detectUploadMagicType(bytes: Uint8Array): UploadMagicTyp
|
|
|
35
35
|
*/
|
|
36
36
|
export declare const EXPECTED_MAGIC_BY_CONTENT_TYPE: Readonly<Record<string, readonly UploadMagicType[]>>;
|
|
37
37
|
/**
|
|
38
|
-
* Let the BYTES name the type — but only inside
|
|
39
|
-
*
|
|
38
|
+
* Let the BYTES name the type — but only inside a family (see above), and only between types we
|
|
39
|
+
* already accept.
|
|
40
40
|
*
|
|
41
|
-
* The case this exists for came from our own pipeline. A KIE CDN served a
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* `.png` URL, which browsers do constantly.
|
|
41
|
+
* The case this exists for came from our own pipeline. A KIE CDN served a generated picture as
|
|
42
|
+
* `Content-Type: image/png` with a WebP body; the downloader trusted the header, so the object was
|
|
43
|
+
* stored under a `.png` name and handed to the person that way. Re-uploading it — our own
|
|
44
|
+
* artifact — failed, because the sniffer correctly saw WebP where PNG was declared. The same thing
|
|
45
|
+
* happens to a Word file saved under `.doc` that is a docx inside: a perfectly ordinary file that
|
|
46
|
+
* a strict reading of the declaration would turn away.
|
|
48
47
|
*
|
|
49
|
-
* Why this is not the "trust the payload" mistake the module warns about: it
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* An uploader gains nothing either — they could declare `image/webp` outright.
|
|
48
|
+
* Why this is not the "trust the payload" mistake the module warns about: it re-routes NOTHING
|
|
49
|
+
* that the uploader could not have declared outright. Everything else keeps the old rule. A ZIP
|
|
50
|
+
* announced as `text/plain` still contradicts its declaration, and cross-family correction is
|
|
51
|
+
* exactly where honouring content over declaration WOULD hand someone a pipeline of their choosing.
|
|
54
52
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* honouring content over declaration WOULD hand someone a pipeline of their
|
|
58
|
-
* choosing — the converter that resolves what a document points at.
|
|
59
|
-
*
|
|
60
|
-
* Returns the content type the caller should proceed with: the detected one
|
|
61
|
-
* when both it and the declaration are accepted image types, otherwise the
|
|
62
|
-
* declaration untouched.
|
|
53
|
+
* Returns the content type the caller should proceed with: the detected one when the declaration
|
|
54
|
+
* belongs to a family that has a type for these bytes, otherwise the declaration untouched.
|
|
63
55
|
*/
|
|
64
|
-
export declare function
|
|
56
|
+
export declare function reconcileContentTypeFamily(declaredContentType: string, bytes: Uint8Array): string;
|
|
65
57
|
export { MagicVerdict } from './schemas/magic-verdict.enum';
|
|
66
58
|
/**
|
|
67
59
|
* Does the content agree with what the uploader claimed it is.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MagicVerdict = exports.EXPECTED_MAGIC_BY_CONTENT_TYPE = exports.UPLOAD_MAGIC_PROBE_BYTES = exports.UploadMagicType = void 0;
|
|
4
4
|
exports.detectUploadMagicType = detectUploadMagicType;
|
|
5
|
-
exports.
|
|
5
|
+
exports.reconcileContentTypeFamily = reconcileContentTypeFamily;
|
|
6
6
|
exports.verifyDeclaredContentType = verifyDeclaredContentType;
|
|
7
7
|
const upload_magic_type_enum_1 = require("./schemas/upload-magic-type.enum");
|
|
8
8
|
const magic_verdict_enum_1 = require("./schemas/magic-verdict.enum");
|
|
@@ -68,6 +68,26 @@ function isWebp(bytes) {
|
|
|
68
68
|
bytes[10] === 0x42 &&
|
|
69
69
|
bytes[11] === 0x50);
|
|
70
70
|
}
|
|
71
|
+
/** ISO base media file: `ftyp` at offset 4, the brand naming the image format right after it. */
|
|
72
|
+
const FTYP_BOX_OFFSET = 4;
|
|
73
|
+
const FTYP_BRAND_OFFSET = 8;
|
|
74
|
+
const FTYP_BRAND_LENGTH = 4;
|
|
75
|
+
const FTYP_TAG = 'ftyp';
|
|
76
|
+
const IMAGE_BRANDS = [
|
|
77
|
+
{ type: upload_magic_type_enum_1.UploadMagicType.HEIF, brands: ['heic', 'heix', 'hevc', 'hevx', 'mif1', 'msf1'] },
|
|
78
|
+
{ type: upload_magic_type_enum_1.UploadMagicType.AVIF, brands: ['avif', 'avis'] },
|
|
79
|
+
];
|
|
80
|
+
function asciiAt(bytes, offset, length) {
|
|
81
|
+
return String.fromCharCode(...bytes.subarray(offset, offset + length));
|
|
82
|
+
}
|
|
83
|
+
function detectIsoImage(bytes) {
|
|
84
|
+
if (bytes.length < FTYP_BRAND_OFFSET + FTYP_BRAND_LENGTH ||
|
|
85
|
+
asciiAt(bytes, FTYP_BOX_OFFSET, FTYP_TAG.length) !== FTYP_TAG) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const brand = asciiAt(bytes, FTYP_BRAND_OFFSET, FTYP_BRAND_LENGTH);
|
|
89
|
+
return IMAGE_BRANDS.find(({ brands }) => brands.includes(brand))?.type ?? null;
|
|
90
|
+
}
|
|
71
91
|
/**
|
|
72
92
|
* Classify a byte prefix. Never guesses: anything unrecognised is UNKNOWN, and
|
|
73
93
|
* the caller decides what that means for the declared type.
|
|
@@ -81,7 +101,7 @@ function detectUploadMagicType(bytes) {
|
|
|
81
101
|
return type;
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
|
-
return upload_magic_type_enum_1.UploadMagicType.UNKNOWN;
|
|
104
|
+
return detectIsoImage(bytes) ?? upload_magic_type_enum_1.UploadMagicType.UNKNOWN;
|
|
85
105
|
}
|
|
86
106
|
/**
|
|
87
107
|
* Signatures a declared content type is allowed to carry.
|
|
@@ -116,52 +136,70 @@ exports.EXPECTED_MAGIC_BY_CONTENT_TYPE = {
|
|
|
116
136
|
],
|
|
117
137
|
};
|
|
118
138
|
/**
|
|
119
|
-
*
|
|
139
|
+
* Content types that one file can legitimately be sold under by mistake, keyed by what the bytes
|
|
140
|
+
* say. Choosing between the members of a family gives the uploader no pipeline they could not have
|
|
141
|
+
* got by declaring that member outright.
|
|
142
|
+
*
|
|
143
|
+
* - Images: all three go through one image branch.
|
|
144
|
+
* - Word: a `.doc` that is really a docx (ZIP) or an RTF is what Word, Google Docs and phones
|
|
145
|
+
* produce; the converter gets the canonical extension of whatever we settle on.
|
|
146
|
+
* - Excel and PowerPoint: the same legacy-vs-OOXML mix-up.
|
|
120
147
|
*
|
|
121
|
-
*
|
|
122
|
-
* but do not accept (GIF) is deliberately absent: recognising it is how we
|
|
148
|
+
* A signature we detect but do not accept (GIF) is deliberately absent: recognising it is how we
|
|
123
149
|
* reject it, not a step towards letting it in.
|
|
124
150
|
*/
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
const CONTENT_TYPE_FAMILIES = [
|
|
152
|
+
{
|
|
153
|
+
[upload_magic_type_enum_1.UploadMagicType.PNG]: 'image/png',
|
|
154
|
+
[upload_magic_type_enum_1.UploadMagicType.JPEG]: 'image/jpeg',
|
|
155
|
+
[upload_magic_type_enum_1.UploadMagicType.WEBP]: 'image/webp',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
[upload_magic_type_enum_1.UploadMagicType.ZIP]: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
159
|
+
[upload_magic_type_enum_1.UploadMagicType.OLE2]: 'application/msword',
|
|
160
|
+
[upload_magic_type_enum_1.UploadMagicType.RTF]: 'application/rtf',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
[upload_magic_type_enum_1.UploadMagicType.ZIP]: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
164
|
+
[upload_magic_type_enum_1.UploadMagicType.OLE2]: 'application/vnd.ms-excel',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
[upload_magic_type_enum_1.UploadMagicType.ZIP]: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
168
|
+
[upload_magic_type_enum_1.UploadMagicType.OLE2]: 'application/vnd.ms-powerpoint',
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
/** Browsers announce an RTF as `text/rtf` too; it belongs to the same family as `application/rtf`. */
|
|
172
|
+
const RTF_ALIASES = { 'text/rtf': 'application/rtf' };
|
|
130
173
|
/**
|
|
131
|
-
* Let the BYTES name the type — but only inside
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* The case this exists for came from our own pipeline. A KIE CDN served a
|
|
135
|
-
* generated picture as `Content-Type: image/png` with a WebP body; the
|
|
136
|
-
* downloader trusted the header, so the object was stored under a `.png` name
|
|
137
|
-
* and handed to the person that way. Re-uploading it — our own artifact —
|
|
138
|
-
* failed, because the sniffer correctly saw WebP where PNG was declared. The
|
|
139
|
-
* same thing happens to any file saved from a site that serves WebP behind a
|
|
140
|
-
* `.png` URL, which browsers do constantly.
|
|
174
|
+
* Let the BYTES name the type — but only inside a family (see above), and only between types we
|
|
175
|
+
* already accept.
|
|
141
176
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
177
|
+
* The case this exists for came from our own pipeline. A KIE CDN served a generated picture as
|
|
178
|
+
* `Content-Type: image/png` with a WebP body; the downloader trusted the header, so the object was
|
|
179
|
+
* stored under a `.png` name and handed to the person that way. Re-uploading it — our own
|
|
180
|
+
* artifact — failed, because the sniffer correctly saw WebP where PNG was declared. The same thing
|
|
181
|
+
* happens to a Word file saved under `.doc` that is a docx inside: a perfectly ordinary file that
|
|
182
|
+
* a strict reading of the declaration would turn away.
|
|
147
183
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
184
|
+
* Why this is not the "trust the payload" mistake the module warns about: it re-routes NOTHING
|
|
185
|
+
* that the uploader could not have declared outright. Everything else keeps the old rule. A ZIP
|
|
186
|
+
* announced as `text/plain` still contradicts its declaration, and cross-family correction is
|
|
187
|
+
* exactly where honouring content over declaration WOULD hand someone a pipeline of their choosing.
|
|
152
188
|
*
|
|
153
|
-
* Returns the content type the caller should proceed with: the detected one
|
|
154
|
-
*
|
|
155
|
-
* declaration untouched.
|
|
189
|
+
* Returns the content type the caller should proceed with: the detected one when the declaration
|
|
190
|
+
* belongs to a family that has a type for these bytes, otherwise the declaration untouched.
|
|
156
191
|
*/
|
|
157
|
-
function
|
|
192
|
+
function reconcileContentTypeFamily(declaredContentType, bytes) {
|
|
158
193
|
const declared = declaredContentType.toLowerCase();
|
|
159
|
-
const
|
|
160
|
-
|
|
194
|
+
const detected = detectUploadMagicType(bytes);
|
|
195
|
+
const expected = Object.hasOwn(exports.EXPECTED_MAGIC_BY_CONTENT_TYPE, declared)
|
|
196
|
+
? exports.EXPECTED_MAGIC_BY_CONTENT_TYPE[declared]
|
|
197
|
+
: undefined;
|
|
198
|
+
if (expected?.includes(detected)) {
|
|
161
199
|
return declaredContentType;
|
|
162
200
|
}
|
|
163
|
-
const
|
|
164
|
-
return detected
|
|
201
|
+
const family = CONTENT_TYPE_FAMILIES.find((members) => Object.values(members).includes(RTF_ALIASES[declared] ?? declared));
|
|
202
|
+
return family?.[detected] ?? declaredContentType;
|
|
165
203
|
}
|
|
166
204
|
var magic_verdict_enum_2 = require("./schemas/magic-verdict.enum");
|
|
167
205
|
Object.defineProperty(exports, "MagicVerdict", { enumerable: true, get: function () { return magic_verdict_enum_2.MagicVerdict; } });
|