Skip to content

WebSharper 10.1.9

Choose a tag to compare

@Jand42 Jand42 released this 29 Oct 15:28
· 184 commits to master since this release

This is a minor release of WebSharper 10.1. NuGet version 10.1.9.686.

Templates for .NET Core SDK: dotnet new install WebSharper.Templates@10.1.9.686

Enhancements

  • #1570 Cache busting for bundled scripts and styles. When a sitelet page uses a bundle produced by the project's esbuild.config.mjs, the server appends a content hash to its links, for example /Scripts/WebSharper/all.js?h=-1351857034 and /Scripts/WebSharper/all.css?h=.... Browsers then load the new version after a deployment instead of a stale cached file. Web workers in Scripts/WebSharper/workers get a hash too, computed over all worker files. No project changes are needed.
    • Hashes are computed from the files under the web root (wwwroot) when they are first used, and cached until the application restarts.
    • Offline (HTML) sitelets do not get hashes, because their pages are generated before bundling.
    • API: new WebSharper.Core.Resources.ScriptVersion and WorkersVersion functions, and a HtmlTextWriter.WriteStartCode overload that takes the web root folder. The existing overload is unchanged and adds no hashes.
  • #1532 CSRF protection for Sitelet APIs. Endpoints handled with Content.Cors can turn on the same cross-site request forgery check as RPCs with CsrfProtection = true in CorsAllows, or WithCsrfProtection() on the C# CorsBuilder. Requests other than GET, HEAD and OPTIONS are then rejected with 403 Forbidden and the body CSRF, unless they are same-origin, come from an origin listed explicitly in Origins ("*" does not count), or are not from a browser. Clients don't need to send anything extra, so Router.XHR and Router.Fetch calls and API consumers outside a browser keep working. The plain HTTP limitations of the RPC check below apply here too.
    • CsrfProtection is a new field of the CorsAllows record, so code that builds a whole CorsAllows record instead of updating the one passed in ({ allows with ... }) needs to set it.
  • #1338 Cross-origin fixes for RPC and Sitelet APIs, to make header-based authentication work the same for both.
    • RPC preflight requests now allow the headers the browser asks for, so a client on another allowed origin can send an Authorization header or other custom headers set in AjaxRemotingProvider.Headers. Previously only Content-Type was allowed.
    • RPC: an origin added with Remoting.AddAllowedOrigin is now sent back as the allowed origin even if "*" is also allowed, so credentialed calls from it work. With only "*", Access-Control-Allow-Credentials is no longer sent, as browsers reject it with "*".
    • Content.Cors now sends Vary: Origin when it allows a specific origin, so caches don't serve the response to a different origin, and matches Origins case-insensitively.
  • #1534 Typed helpers for calling Sitelet endpoints from the client with fetch.
    • Router.FetchText and Router.FetchJson (with FetchTextWith/FetchJsonWith variants taking a base URL and RequestOptions) return Async<string> and the deserialized JSON response, for example let! (user: User) = Router.FetchJson router (Api.GetUser 42). The response type is given by a type annotation.
    • Router.InferFetchText and Router.InferFetchJson (and ...With variants) infer the router from the endpoint type, for example Router.InferFetchJson (Api.GetUser 42).
    • C#: router.FetchText(endpoint, baseUrl, settings) and router.FetchJson<TResult>(endpoint, baseUrl, settings) return a Task.
    • A request body (from Router.Json or a [<Json>] field) is sent with Content-Type: application/json, and FetchJson sends Accept: application/json. Headers set in the given options take precedence, and the options object is not modified.
    • If the response status is not successful (2xx), they raise a FetchException, which has the Status and the Response, whose body can still be read.
    • The existing Router.Fetch, Router.FetchWith and Router.XHR are unchanged.

Fixes

  • #1587 F# builds using the WebSharper booster (wsfscservice, the default on Windows) no longer hang occasionally in the WebSharperCompile step. With parallel compilation, introduced in 10.1.8, F# compilation and WebSharper translation could log at the same time, the two messages got mixed up on the way to wsfsc, and it then waited forever. The booster now sends each message whole, and the F# compilation output (warnings, errors and its timing) is printed after WebSharper translation, at a fixed place in the log, instead of between translation steps. To work around this in 10.1.8, set WebSharperParallelCompilation to false, as an MSBuild property or an environment variable.
  • #1469 dotnet build now regenerates WebSharper output that was deleted, for example the outputDir folder of an SPA or the unpacked files under wwwroot, even when no source file has changed. Previously the build considered the project up to date and skipped WebSharper compilation, so later build steps such as bundling failed on the missing files.
    • The compiler records the files it writes in obj/<configuration>/<framework>/<project>.websharper.files. Before each build, the WebSharperCheckOutputFiles target checks that they exist, and recompiles the project if any is missing.
    • Build steps that delete WebSharper output on every build now cause a recompilation on every build. Run such steps only when WebSharper compiles, for example with BeforeTargets="WebSharperCompile" and, in F# projects, Condition=" '@(FscCommandLineArgs)' != '' ".
  • #960 A %2F in a URL path segment is now read as a / inside a string parameter of a router, for example /test/a%2Fb/c is parsed as Test ("a/b", "c") for [<EndPoint "/test">] Test of string * string. Previously the value was "a%2Fb". Links written by WebSharper still escape / as ~2f, which is safe with every web server. Other percent-encoded characters in path segments are not decoded, as before.
    • ASP.NET Core decodes %25 but not %2F, so an escaped literal %2F (%252F) is also read as /.
  • #1256 A [<Query>] endpoint field of a union, record or other type that takes more than one URL path segment is now written to and parsed from the query string, with the segments separated by /, for example ?tableType=Linked/InstanceId/51377 for Linked { sourceInstanceId = InstanceId 51377 }. Previously links made on the client left out the query argument, and the server could not parse it back from the links it wrote. The same applies to Router.Query, Router.QueryOption and Router.QueryNullable. Values of a single segment are written the same as before.
    • A query argument is now accepted only if its whole value is parsed, for example ?q=1/2 no longer matches an int query field.
  • #1208 Client-side code in server-side F# code, such as InlineControl or an event handler in a WebSharper.UI server-side template, now gives a compile error when it uses a local function or another function value from the server-side code around it, for example foo in let foo a = a + 12 followed by .Save(fun e -> Console.Log (foo 10)). Previously it compiled, and the generated JavaScript failed when it called the function, because the server cannot send a function to the client. Define the function inside the client-side code, or as a top-level function with the JavaScript attribute. Captured values that are not functions are passed to the client as before.
  • #1596 Import of a CSS module or other non-JavaScript file listed in the project's own extra.files now has the correct path in Bundle and BundleOnly projects, for example import Box_module from "./Components/Box.module.css". Previously the path had an extra folder named after the project, so bundlers could not find the file. The fix also applies to web worker bundles of these projects.
  • #1604 F# projects can use internal members of an assembly that grants them access with InternalsVisibleTo. WebSharper's type check dropped the project's output file argument, so it took the assembly name from the last source file, for example Startup for Startup.fs, and reported the internal members as not accessible.

Breaking changes

  • #1533 Stronger and simpler RPC CSRF protection. The server now checks the Sec-Fetch-Site and Origin headers set by the browser instead of a csrftoken cookie. This closes an attack path: a page served over plain HTTP on the same host could call the HTTPS RPC endpoint, so anyone able to inject content into the HTTP site could make RPC calls as the user. The csrftoken cookie is no longer set. On HTTPS, same-origin calls no longer fail the check behind a proxy that changes the Host header, or with Referrer-Policy: no-referrer.
    • Recompile and redeploy the server and client code together. With the cache busting in this release (#1570), browsers then load the new client code instead of an older cached version.
    • Cross-origin RPC calls are accepted only from origins added with WebSharper.Web.Remoting.SetAllowedOrigins or AddAllowedOrigin. If you use Remoting.UseHttps(), add the page's http:// origin.
    • On plain HTTP, same-origin calls are rejected if the browser sends Origin: null (Referrer-Policy: no-referrer), or if a reverse proxy changes the Host header without forwarded headers set up. Use HTTPS, forwarded headers, or an allowed origin.
    • Non-browser clients can call RPCs with POST without handling a token. Calls with GET need an Origin header that matches the host.