Repository navigation
WebSharper 10.1.9
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=-1351857034and/Scripts/WebSharper/all.css?h=.... Browsers then load the new version after a deployment instead of a stale cached file. Web workers inScripts/WebSharper/workersget 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.ScriptVersionandWorkersVersionfunctions, and aHtmlTextWriter.WriteStartCodeoverload that takes the web root folder. The existing overload is unchanged and adds no hashes.
- Hashes are computed from the files under the web root (
- #1532 CSRF protection for Sitelet APIs. Endpoints handled with
Content.Corscan turn on the same cross-site request forgery check as RPCs withCsrfProtection = trueinCorsAllows, orWithCsrfProtection()on the C#CorsBuilder. Requests other than GET, HEAD and OPTIONS are then rejected with403 Forbiddenand the bodyCSRF, unless they are same-origin, come from an origin listed explicitly inOrigins("*"does not count), or are not from a browser. Clients don't need to send anything extra, soRouter.XHRandRouter.Fetchcalls and API consumers outside a browser keep working. The plain HTTP limitations of the RPC check below apply here too.CsrfProtectionis a new field of theCorsAllowsrecord, so code that builds a wholeCorsAllowsrecord 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
Authorizationheader or other custom headers set inAjaxRemotingProvider.Headers. Previously onlyContent-Typewas allowed. - RPC: an origin added with
Remoting.AddAllowedOriginis now sent back as the allowed origin even if"*"is also allowed, so credentialed calls from it work. With only"*",Access-Control-Allow-Credentialsis no longer sent, as browsers reject it with"*". Content.Corsnow sendsVary: Originwhen it allows a specific origin, so caches don't serve the response to a different origin, and matchesOriginscase-insensitively.
- RPC preflight requests now allow the headers the browser asks for, so a client on another allowed origin can send an
- #1534 Typed helpers for calling Sitelet endpoints from the client with
fetch.Router.FetchTextandRouter.FetchJson(withFetchTextWith/FetchJsonWithvariants taking a base URL andRequestOptions) returnAsync<string>and the deserialized JSON response, for examplelet! (user: User) = Router.FetchJson router (Api.GetUser 42). The response type is given by a type annotation.Router.InferFetchTextandRouter.InferFetchJson(and...Withvariants) infer the router from the endpoint type, for exampleRouter.InferFetchJson (Api.GetUser 42).- C#:
router.FetchText(endpoint, baseUrl, settings)androuter.FetchJson<TResult>(endpoint, baseUrl, settings)return aTask. - A request body (from
Router.Jsonor a[<Json>]field) is sent withContent-Type: application/json, andFetchJsonsendsAccept: 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 theStatusand theResponse, whose body can still be read. - The existing
Router.Fetch,Router.FetchWithandRouter.XHRare unchanged.
Fixes
- #1587 F# builds using the WebSharper booster (
wsfscservice, the default on Windows) no longer hang occasionally in theWebSharperCompilestep. 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 towsfsc, 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, setWebSharperParallelCompilationtofalse, as an MSBuild property or an environment variable. - #1469
dotnet buildnow regenerates WebSharper output that was deleted, for example theoutputDirfolder of an SPA or the unpacked files underwwwroot, 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, theWebSharperCheckOutputFilestarget 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)' != '' ".
- The compiler records the files it writes in
- #960 A
%2Fin a URL path segment is now read as a/inside a string parameter of a router, for example/test/a%2Fb/cis parsed asTest ("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
%25but not%2F, so an escaped literal%2F(%252F) is also read as/.
- ASP.NET Core decodes
- #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/51377forLinked { 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 toRouter.Query,Router.QueryOptionandRouter.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/2no longer matches anintquery field.
- A query argument is now accepted only if its whole value is parsed, for example
- #1208 Client-side code in server-side F# code, such as
InlineControlor 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 examplefooinlet foo a = a + 12followed 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 theJavaScriptattribute. Captured values that are not functions are passed to the client as before. - #1596
Importof a CSS module or other non-JavaScript file listed in the project's ownextra.filesnow has the correct path inBundleandBundleOnlyprojects, for exampleimport 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 exampleStartupforStartup.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-SiteandOriginheaders set by the browser instead of acsrftokencookie. 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. Thecsrftokencookie is no longer set. On HTTPS, same-origin calls no longer fail the check behind a proxy that changes theHostheader, or withReferrer-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.SetAllowedOriginsorAddAllowedOrigin. If you useRemoting.UseHttps(), add the page'shttp://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 theHostheader 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
Originheader that matches the host.