diff --git a/README.md b/README.md index afd5efb..d333fd8 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,8 @@ can change what that program does, so the details are strict: include an injection attempt through each of them. - `proto = "=http,https"` stops a malformed base URL from reaching any other protocol; redirects are not followed. +- `globoff` stops `{}` or `[]` in a base URL from being expanded into several + requests: one report is one request. - The key is never on a command line, so it does not show up in `ps`. - On Windows `curl.exe` is taken from `System32`, or else from the directories on `PATH` — never from the current directory. It runs with diff --git a/test/test_trace_client.cpp b/test/test_trace_client.cpp index 7be6135..430e4a6 100644 --- a/test/test_trace_client.cpp +++ b/test/test_trace_client.cpp @@ -1005,6 +1005,7 @@ static void curlConfigFixesEveryOptionAndQuotesEveryValue() { shared.application = "My\nGame"; std::string expected = "url = \"https://trace.example.org/api/metrics\"\n" + "globoff\n" "proto = \"=http,https\"\n" "header = \"Content-Type: application/json; charset=utf-8\"\n" "header = \"Expect:\"\n" @@ -1071,6 +1072,21 @@ static void aNewlineInTheBaseUrlCannotAddACurlOption() { } } +static void aBaseUrlIsNeverExpandedIntoSeveralRequests() { + StubServer server; + Log log; + // Left to curl's URL globbing, this is two requests, to /a and to /b, and + // two answers run together into one status that cannot be read. + trace_client::TraceClient client(server.baseUrl() + "/{a,b}", "MyGame", "1.2.3", "k", true, log.logger()); + client.report("startup"); + client.close(); + std::vector got = server.received(); + CHECK_EQ(1u, got.size()); + if (got.empty()) return; + CHECK_EQ(std::string("/{a,b}/api/metrics"), got[0].path); + CHECK_EQ(0u, log.count("[trace]")); +} + static void queueIsBoundedAndDropsRatherThanGrows() { StubServer server; server.hold(); // the sender waits on the first report @@ -1817,6 +1833,7 @@ int main() { {"isValidInstallIdAcceptsOnlyTheDocumentedCharacters", isValidInstallIdAcceptsOnlyTheDocumentedCharacters}, {"nothingTheProgramPassesCanChangeWhereOrWhatCurlSends", nothingTheProgramPassesCanChangeWhereOrWhatCurlSends}, {"aNewlineInTheBaseUrlCannotAddACurlOption", aNewlineInTheBaseUrlCannotAddACurlOption}, + {"aBaseUrlIsNeverExpandedIntoSeveralRequests", aBaseUrlIsNeverExpandedIntoSeveralRequests}, {"queueIsBoundedAndDropsRatherThanGrows", queueIsBoundedAndDropsRatherThanGrows}, {"closeSendsWhatWasJustQueuedBeforeStopping", closeSendsWhatWasJustQueuedBeforeStopping}, {"destructorClosesToo", destructorClosesToo}, diff --git a/trace_client.hpp b/trace_client.hpp index f397c73..112cce7 100644 --- a/trace_client.hpp +++ b/trace_client.hpp @@ -525,6 +525,7 @@ inline std::string curlConfig(const Shared &shared, const std::string &body) { timeout << timeoutWholeSeconds(); std::string config; config += "url = " + curlQuote(shared.endpoint) + "\n"; + config += "globoff\n"; // {} and [] in a URL would otherwise mean several requests config += "proto = \"=http,https\"\n"; config += "header = \"Content-Type: application/json; charset=utf-8\"\n"; config += "header = \"Expect:\"\n"; // no 100-continue round trip for a larger body