Skip to content

[BREAKING CHANGES] harden file resolution and implement native Bun routing - #21

Merged
xellanix merged 3 commits into
mainfrom
vite-bun
May 15, 2026
Merged

xellanix merged 3 commits into
mainfrom
vite-bun

Conversation

@xellanix

Copy link
Copy Markdown
Owner

⚠️ BREAKING CHANGES

  • Internal Development: JSON utility functions in the persistence layer no longer automatically resolve paths relative to the process root. Developers must now use the publicDir or execDir helpers when specifying file paths to ensure consistent behavior across different deployment environments.
  • Internal Development: The deployment artifact structure has changed. The server executable no longer requires or expects a frontend folder to be present in its root directory at runtime, as the entry point is now resolved via internal Bun routes.

Overview

This PR hardens file resolution logic to prevent path traversal vulnerabilities and transitions the server to native Bun routing. These changes improve security boundaries, standardize path handling across execution environments, and optimize the deployment pipeline.

Key Changes

🐛 Bug Fixes

  • Harden file resolution and prevent path traversal
    • Refactored the file import handler to use centralized path resolution and enforced strict path boundary checks using startsWith to block advanced path traversal attempts.

🧹 Chore/Refactoring

  • Harden path resolution and add traversal check
    • Standardized JSON persistence to use provided paths directly and centralized directory resolution to handle differences between development and compiled binary environments.
  • Implement native Bun routes for frontend serving
    • Transitioned the server from manual file-system resolution to Bun's built-in routing system, eliminating redundant disk I/O checks and removing the need for the copyFrontend build task.

Version Bump

0.1.0

xellanix added 3 commits May 15, 2026 13:40
Transition the server from manual file-system resolution to Bun's
built-in routing system. This change optimizes performance by
eliminating redundant disk I/O checks for the SPA entry point and
simplifies the overall deployment pipeline.

- Remove the `copyFrontend` task from the build script, as the
  frontend index is now handled via static imports at the code level.
- Configure the `serve` object with explicit routes for '/',
  '/index.html', and '/view' to serve the imported index file.
- Replace legacy file-serving logic and manual path validation in
  the `fetch` handler with a streamlined 404 fallback.
- Introduce a `prod` helper function to maintain the development
  workflow by ensuring the backend continues to redirect to the
  Vite dev server when not in production.

BREAKING CHANGE:
- Internal Development: The deployment artifact structure has changed.
  The server executable no longer requires or expects a `frontend`
  folder to be present in its root directory at runtime, as the entry
  point is now resolved via internal Bun routes.
Ensure the application correctly resolves file paths when running as a
compiled binary and prevent unauthorized access to system files through
the static file server.

- Centralize directory resolution in persistence helpers to handle
  production vs. development environment differences effectively.
- Implement path traversal protection in the fetch handler by
  validating that requested files reside within the execution root.
- Standardize JSON persistence to use provided paths directly instead
  of forcing a relative join with the current working directory.
- Update the settings file path to dynamically resolve based on the
  environment-specific public directory.

BREAKING CHANGE: JSON utility functions in the persistence layer no
longer automatically resolve paths relative to the process root.
- Internal Development: Developers must now use the `publicDir` or
  `execDir` helpers when specifying file paths to ensure consistent
  behavior across different deployment environments.
Refactor the file import handler to use centralized path resolution and
enforce stricter security boundaries for asset management.

- Replace manual environment-based path joining with the `publicDir`
  persistence helper to ensure consistent asset location regardless of
  the execution environment.
- Centralize filename extraction and validation at the start of the
  `importRequest` function, eliminating redundant logic previously
  split between `POST` and `GET` methods.
- Implement a strict path boundary check using `startsWith` to verify
  that resolved file paths remain within the temporary assets
  directory, effectively blocking advanced path traversal attempts.
- Remove unnecessary URI decoding before `basename` extraction to
  standardize path handling.
@xellanix
xellanix merged commit 68e980c into main May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant