Skip to content

Enhance Support for Serving Static Files #8

Closed

Description

@klkucaj

Is your feature request related to a problem? Please describe.
The current support for serving static files is limited or lacks flexibility in handling various use cases, such as caching, content negotiation, or serving files from custom directories. Enhancing this functionality can improve performance and make the framework more versatile.

Describe the solution you'd like
Enhance static file support by:

  • Adding better caching mechanisms (e.g., ETag, Last-Modified, Cache-Control headers).
  • Allowing configuration for serving files from custom directories.
  • Supporting partial content responses (e.g., Range requests) for large files.
  • Improving MIME type handling for different file extensions.

Describe alternatives you've considered

  • Using an external file server to handle static files. While feasible, this introduces additional complexity and dependencies for applications that need to serve static assets.

Additional context
Enhanced static file support will align the framework with modern web application needs and simplify serving common assets like images, scripts, and styles.

Activity

  1. added
    enhancement
    on Dec 9, 2024
  2. moved this to Next 🌟 in Relic Roadmapon Dec 18, 2024
  3. moved this from Next 🌟 to Later 🥳 in Relic Roadmapon Dec 18, 2024
  4. moved this from Later 🥳 to Backlog in Relic Roadmapon Mar 25, 2025
  5. changed the title [-]RELIC: Enhance Support for Serving Static Files[/-] [+]Enhance Support for Serving Static Files[/+] on Mar 27, 2025
  6. moved this from Backlog to Later 🥳 in Relic Roadmapon Aug 5, 2025
  7. moved this from Later 🥳 to Next 🌟 in Relic Roadmapon Aug 6, 2025
  8. self-assigned this
    on Aug 6, 2025
  9. nielsenko commented on Aug 6, 2025

    @nielsenko
    Collaborator

    The current static file support (inherited from shelf) stems from another time. Going forward the driving principle will be:

    Only serve files that are explicitly allowed, and only on exact path matches.

    This means:

    What to serve:

    • Only files with explicitly allowed extensions (.html, .css, .js, .png, etc.)
    • Only files that exist at the exact requested path
    • Only files within the designated public directory (no path traversal)

    What NOT to serve:

    • Directory listings
    • Files without extensions or with disallowed extensions (.env, .config, .log, etc.)
    • Partial path matches or fuzzy matching
    • Files outside the public root via ../ traversal
    • Hidden files (starting with .)

    Implementation approach:

    Assuming /public is the root of the directory for files served statically .

    Request: /assets/style.css
    ✅ Serve if: file exists at exactly /public/assets/style.css AND .css is allowed
    
    Request: /assets/
    ❌ Don't serve directory listing
    ❌ Don't try to find "close matches"
    
    Request: /assets/../config.json  
    ❌ Block path traversal attempts
    
    Request: /script.php
    ❌ Don't serve if .php not in allowed extensions
    

    Key principles:

    • Explicit allowlist of file extensions
    • Exact path matching only
    • Strict boundary enforcement (stay within public directory)
    • Fail closed - when in doubt, return 404

    This approach minimizes attack surface and prevents accidental exposure of sensitive files.

  10. nielsenko commented on Aug 6, 2025

    @nielsenko
    Collaborator

    Also, we will forego weak eTags and only support strong eTags. The complexity of weak eTags is just not worth the trouble.

  11. moved this from Next 🌟 to Now 🔥 in Relic Roadmapon Aug 11, 2025
  12. moved this from Inbox 📫 to In Progress 🔥 in Serverpod Frameworkson Aug 14, 2025
  13. moved this from In Progress 🔥 to Done 🚀 in Serverpod Frameworkson Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions