Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix headers v2 #306

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.0.2] - 2024-04-11

### Changed

- Take `process.argv[1]` as an app identifier instead of `process.title`
- More strict header escaping, limit the length to 100 characters per field

## [6.0.1] - 2024-04-07

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions packages/azure-kusto-data/src/clientDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare namespace NodeJS {
}

// This regex allows all printable ascii, except spaces and chars we use in the format
const ReplaceRegex = /[^\x21-\x7A]+/g;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please just align this allover :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah..

const ReplaceRegex = /[^\w.\-()]/g;
const None = "[none]";

export class ClientDetails {
Expand All @@ -33,7 +33,7 @@ export class ClientDetails {

static defaultApplication(): string {
if (isNode) {
return process?.env?.npm_package_name || process.title || None;
return process?.env?.npm_package_name || process?.argv[1] || None;
} else {
return window?.location?.href || None;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ export class ClientDetails {
}

static escapeHeader(header: string, wrapInBrackets: boolean = true): string {
const clean = header.replace(ReplaceRegex, "_");
const clean = header.substring(0, 100).replace(ReplaceRegex, "_");
return wrapInBrackets ? `{${clean}}` : clean;
}

Expand Down
7 changes: 5 additions & 2 deletions packages/azure-kusto-data/test/headersTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ describe("Test Headers", () => {
});

it.concurrent("Should remove unwanted characters", () => {
const clientDetails = ClientDetails.setConnectorDetails("Café", "1 . 0", "my|test{}app", "1.0", true, null, null);
const clientDetails = ClientDetails.setConnectorDetails("Café", "1 . 0", "my|test\\{}\\app", new Array(1024).join("s"), true, null, null);
const headers = clientDetails.getHeaders();
assert.strictEqual(headers["x-ms-client-version"]?.startsWith("Kusto.JavaScript.Client:"), true);
assert.strictEqual(headers["x-ms-app"], "Kusto.Caf_:{1_._0}|App.{my_test_app}:{1.0}");
assert.strictEqual(
headers["x-ms-app"],
"Kusto.Caf_:{1_._0}|App.{my_test____app}:{ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss}"
);
assert.notStrictEqual(headers["x-ms-user"], "[none]");
});
});
Loading