Skip to content

Commit

Permalink
read document security checks
Browse files Browse the repository at this point in the history
  • Loading branch information
inetol committed Nov 29, 2024
1 parent 2e059fe commit 77d6fff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"start:server": "bun run ./dist/server.js"
},
"dependencies": {
"@hono/zod-openapi": "~0.18.0",
"@hono/zod-openapi": "~0.18.2",
"env-var": "~7.5.0",
"hono": "~4.6.12"
},
"devDependencies": {
"@biomejs/biome": "~1.9.4",
"@types/bun": "^1.1.13",
"@types/bun": "^1.1.14",
"lefthook": "~1.8.4",
"sort-package-json": "~2.12.0"
},
Expand Down
13 changes: 11 additions & 2 deletions src/document/storage.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { deserialize, serialize } from 'bun:jsc';
import { logger } from '@x-util/logger.ts';
import { config } from '../config.ts';
import { errorHandler } from '../server/errorHandler.ts';
import type { Document } from '../types/Document.ts';
import { ErrorCode } from '../types/ErrorHandler.ts';

export const storage = {
read: async (name: string): Promise<Document> => {
const document = await Bun.file(config.storagePath + name)
.arrayBuffer()
.catch(() => errorHandler.send(ErrorCode.documentNotFound));

try {
return deserialize(await Bun.file(config.storagePath + name).arrayBuffer());
if (document.byteLength <= 0) throw null;

return deserialize(document);
} catch {
return errorHandler.send(ErrorCode.documentNotFound);
logger.error(`Document "${name}" is corrupted! Aborting...`);

return errorHandler.send(ErrorCode.documentCorrupted);
}
},

Expand Down

0 comments on commit 77d6fff

Please sign in to comment.