Repository navigation
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%2eor..;), reached a
*.jsonor default (/) component ofadminwith 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 (
/adminor/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.Documentby 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.txtreturned
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.txtpast
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
Randomafter callingRandomize, which reseeds from the clock on every
call. The newTdjHTTPSessionList, whichTdjHTTPServernow uses, takes
256 bits from the operating system's CSPRNG (RtlGenRandomon Windows,
/dev/urandomelsewhere) and writes them as 64 hex characters. (#573) - The session cookie had no attributes besides
Path. It now has
HttpOnlyandSameSite=Lax, andSecurewhen the request came in over
TLS. NewTdjHTTPServerpropertiesSessionCookieHttpOnly,
SessionCookieSameSiteandSessionCookieSecure(set it behind a
TLS-terminating proxy) change this. The attributes are set on sessions
created byGetSession, by contexts created with sessions enabled, and by
Indy'sAutoStartSession. This usesTIdCookie.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: Basicheader 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 newFormatNCSALogLine, the escaping is available asNCSAEscape,
and both are covered by the newdjNCSALogFilterTestssuite. (#563)djGlobal.HTMLEncodenow 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):
TdjRestfulComponentinsource/optional/rsRestfulComponent.pas, with
rsRoute,rsConfigurationandrsMediaTypes. It routes requests by path
template (orders/{id}), HTTP method,Content-TypeandAccept. Compared
with daraja-restful:- Accept negotiation follows RFC 7231:
*/*,type/*, a missingAccept
header andq=weights work. A route that producesapplication/json
used to answer 404 to curl'sAccept: */*. No acceptable route gives 406,
no route for the request'sContent-Typegives 415. - Path parameters are passed to the handler separately (new third handler
parameterPathParams). They were added toRequest.Paramsafter the
query parameters, so/orders/42?orderId=999reached the handler as
order 999. - Exceptions in a handler propagate to the framework: logged, generic 500
page, contextErrorHandler. 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
anAllowheader, regardless ofAccept. OPTIONS without a route
answers withAllow, HEAD falls back to the GET route. - Routes are matched against
TdjServerContext.PathInContext, not against
Request.Documentwith 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/ordersfor
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/newbeforeorders/{id}), and logging uses slf4p's format
arguments.
Covered by the new suites
TrsRestfulUnitTestsand
TrsRestfulServerTests, with a regression test for each of the bugs
above.demo/20_restfulis a JSON CRUD API built on it. (#572) - Accept negotiation follows RFC 7231:
-
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
parsingRequest.Document. (#571) -
Start-up banner: on
Server.Start, console applications now print "daraja"
as ASCII art followed byHTTP server framework <version>. It is written at
most once per process and only whenSystem.IsConsoleis true. Disable it
withTdjServer.ShowBanner := False. The text is available via
djGlobal.GetServerBanner. (#554)
Changed
- Requires slf4p 1.2.0, for its
ILoggeroverloads 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 staleContent-Length(so the error page arrived truncated, or the
client waited for bytes that never came), itsContent-Type(e.g. an HTML
error page labelledapplication/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'sErrorHandleralso 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
unitdjErrorResponseholds the shared reset and 500-page code, also used
byTdjHTTPConnector. (#564)
Internal
- The
ResponseNovalue that marks a request no handler has answered yet
(-1, a Daraja convention rather than an Indy one) is now the named
constantHTTP_NOT_HANDLEDindjHTTPConstants. It's used by
TdjHTTPConnector,TdjHandlerListandTdjDefaultHandler.
TdjHandlerListpreviously tested> 0/< 0for the same value. No
behavior change. (#555) - Parametrized logging for the five log calls that also pass an exception
(TdjWebComponentHandler,TdjWebComponentContextHandler,
TdjWebComponentHolderandTdjWebFilterHolder). 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.