Skip to content

v3.5.0

Latest

Choose a tag to compare

@michaelJustin michaelJustin released this 29 Nov 11:58
· 5 commits to master since this release
Immutable release. Only release title and notes can be modified.
46ca7ce

Requires slf4p 1.2.0 and Indy 10.6.3 (or a 10.6.2 build from April 2023 or later).

Security

  • Filter bypass through the context path. The context was chosen from the
    raw request target, before ./.. segments and ; path parameters were
    cleaned up, and the web component handler then cut a fixed number of
    characters off the cleaned target without checking that it still started
    with the context name. A request that stepped out of its context, such as
    /admin/../abcdefg/x.json (also with %2e%2e or ..;), reached a
    *.json or default (/) component of admin with the relative path
    efg/x.json, which a filter on /* did not match (200 instead of 403).
    The context is now chosen from the normalized target, and the context is
    stripped only after checking the prefix on a segment boundary (new
    TdjPathMap.GetPathInContext). A target that has left a context is
    handled by the context it addresses, or answered with 404. (#571)
  • The bare context root (/admin or /admin/) skipped all filters,
    because its path inside the context was empty. It is now /, so filters
    mapped to /* apply to it. (#571)
  • TdjDefaultWebComponent (optional) also stripped the context from the raw
    Request.Document by character count. It now uses the normalized path
    inside the context as well. (#571)
  • TdjDefaultWebComponent (optional) served a file whose name Windows reads
    differently from the path that web filters were matched against. With a
    filter on /private/*, GET /test/x%5C..%5Cprivate%5Csecret.txt returned
    webapps/test/private/secret.txt (an encoded \ is a path separator to
    Windows but not to the filter). The component now answers 404 for a path
    that contains \ or :, or has a segment ending with . or a space
    (which Windows drops), on every platform. (#573)
  • TdjDefaultWebComponent (optional) served /test/PRIVATE/secret.txt past
    a filter on /private/* on Windows, because filters match paths
    case-sensitively (as the Servlet specification requires) and Windows
    opens files case-insensitively, and also by 8.3 short name. Like Tomcat's
    case check and Jetty's alias check, the component now serves a file on
    Windows only if every segment of the request path equals the stored name,
    and answers 404 otherwise. (#573)
  • Session IDs were predictable. Indy's default session list builds them from
    Random after calling Randomize, which reseeds from the clock on every
    call. The new TdjHTTPSessionList, which TdjHTTPServer now uses, takes
    256 bits from the operating system's CSPRNG (RtlGenRandom on Windows,
    /dev/urandom elsewhere) and writes them as 64 hex characters. (#573)
  • The session cookie had no attributes besides Path. It now has
    HttpOnly and SameSite=Lax, and Secure when the request came in over
    TLS. New TdjHTTPServer properties SessionCookieHttpOnly,
    SessionCookieSameSite and SessionCookieSecure (set it behind a
    TLS-terminating proxy) change this. The attributes are set on sessions
    created by GetSession, by contexts created with sessions enabled, and by
    Indy's AutoStartSession. This uses TIdCookie.SameSite, which Indy has
    had since April 2023. (#573)
  • TdjNCSALogFilter (optional) wrote the client-controlled request values
    into its access-log line unescaped. The user name from an
    Authorization: Basic header can contain line breaks, so a client could
    forge log entries. A " could shift the line's fields, and an ESC could
    start a terminal escape sequence for whoever reads the console. The user
    name, method, URI and version are now escaped the way Apache httpd does:
    " → \", \ → \\, control characters → \xHH. The line is built by
    the new FormatNCSALogLine, the escaping is available as NCSAEscape,
    and both are covered by the new djNCSALogFilterTests suite. (#563)
  • djGlobal.HTMLEncode now also escapes ' (as '). It escaped only
    <, >, & and ", so application code that used it for a
    single-quoted attribute value (value='...') could be broken out of with
    a ' (cross-site scripting). The framework's own uses were element text
    and unaffected. It also sizes its result exactly instead of allocating six
    times the input, and returns the input unchanged when there is nothing to
    escape. Its doc comment now says which contexts it is safe for. (#562)

Added

  • RESTful web component (optional, from the archived
    daraja-restful project):
    TdjRestfulComponent in source/optional/rsRestfulComponent.pas, with
    rsRoute, rsConfiguration and rsMediaTypes. It routes requests by path
    template (orders/{id}), HTTP method, Content-Type and Accept. Compared
    with daraja-restful:

    • Accept negotiation follows RFC 7231: */*, type/*, a missing Accept
      header and q= weights work. A route that produces application/json
      used to answer 404 to curl's Accept: */*. No acceptable route gives 406,
      no route for the request's Content-Type gives 415.
    • Path parameters are passed to the handler separately (new third handler
      parameter PathParams). They were added to Request.Params after the
      query parameters, so /orders/42?orderId=999 reached the handler as
      order 999.
    • Exceptions in a handler propagate to the framework: logged, generic 500
      page, context ErrorHandler. The exception class and message used to go
      to the client.
    • A method that is not a standard HTTP method gives 501 (it was a 500 from
      a nil lookup). A path with routes for other methods only gives 405 with
      an Allow header, regardless of Accept. OPTIONS without a route
      answers with Allow, HEAD falls back to the GET route.
    • Routes are matched against TdjServerContext.PathInContext, not against
      Request.Document with the context cut off by character count. A
      trailing slash, .. segments and repeated slashes no longer matter, and
      a target that leaves the context is not routed. Route paths are now paths
      inside the context, including the component's mapping (/api/orders for
      a component mapped to /api/*).
    • The component's own error responses are JSON when the client prefers
      JSON, or accepts JSON and HTML equally and the component produces JSON.
    • Duplicate routes are detected (the old check compared interface
      references and never matched), more literal paths win over templates
      (orders/new before orders/{id}), and logging uses slf4p's format
      arguments.

    Covered by the new suites TrsRestfulUnitTests and
    TrsRestfulServerTests, with a regression test for each of the bugs
    above. demo/20_restful is a JSON CRUD API built on it. (#572)

  • TdjServerContext.PathInContext: the normalized request path inside the
    context (always starting with /), which filters and components are
    matched against. Code that dispatches on the path should use it instead of
    parsing Request.Document. (#571)

  • Start-up banner: on Server.Start, console applications now print "daraja"
    as ASCII art followed by HTTP server framework <version>. It is written at
    most once per process and only when System.IsConsole is true. Disable it
    with TdjServer.ShowBanner := False. The text is available via
    djGlobal.GetServerBanner. (#554)

Changed

  • Requires slf4p 1.2.0, for its ILogger overloads that take format
    arguments and an exception
    (slf4p#97).
  • Requires an Indy build from April 2023 or later, for
    TIdCookie.SameSite (session cookie attributes). Every 10.6.3 build has
    it; a 10.6.2 snapshot from before April 2023 no longer compiles. (#573)

Fixed

  • When a Web Component or Web Filter raised an exception after it had
    started writing its response, the 500 response kept what it had already
    set: a stale Content-Length (so the error page arrived truncated, or the
    client waited for bytes that never came), its Content-Type (e.g. an HTML
    error page labelled application/json), its custom headers, and, for a
    filter, its partial body. The response is now reset before the 500 page is
    written, and a context's ErrorHandler also starts from a clean response.
    If the headers were already sent (a streaming component), the connection
    is closed instead of appending an error page to the partial body. The new
    unit djErrorResponse holds the shared reset and 500-page code, also used
    by TdjHTTPConnector. (#564)

Internal

  • The ResponseNo value that marks a request no handler has answered yet
    (-1, a Daraja convention rather than an Indy one) is now the named
    constant HTTP_NOT_HANDLED in djHTTPConstants. It's used by
    TdjHTTPConnector, TdjHandlerList and TdjDefaultHandler.
    TdjHandlerList previously tested > 0 / < 0 for the same value. No
    behavior change. (#555)
  • Parametrized logging for the five log calls that also pass an exception
    (TdjWebComponentHandler, TdjWebComponentContextHandler,
    TdjWebComponentHolder and TdjWebFilterHolder). They built the message
    before the logger checked the level; they now use slf4p's
    format-arguments-plus-exception overloads. The logged text is unchanged.
    (#559)
  • Version constant set to 3.5.0.