Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ jobs:
cache: 'npm'
cache-dependency-path: extensions/ql-vscode/package-lock.json

- name: Check lockfile URLs
working-directory: extensions/ql-vscode
run: npm run check:lockfile-urls

- name: Install dependencies
working-directory: extensions/ql-vscode
run: |
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [UNRELEASED]

- Language-client messages and protocol traces now appear in a separate "CodeQL Language Client" output channel. Set that channel's log level to Trace to enable protocol tracing. Raw language-server output remains in "CodeQL Language Server".
- After an extension-managed CodeQL CLI update, the notification now offers to open the CLI release notes instead of the extension log. [#1095](https://github.com/github/vscode-codeql/issues/1095)
- Remove support for CodeQL CLI versions older than 2.24.3. [#4573](https://github.com/github/vscode-codeql/pull/4573)
- Add support to the model editor for saving and loading JSON data extensions. [#4576](https://github.com/github/vscode-codeql/pull/4576)
Expand Down
96 changes: 65 additions & 31 deletions extensions/ql-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@
"generate": "npm-run-all -p generate:*",
"generate:schemas": "vite-node scripts/generate-schemas.ts",
"generate:chromium-version": "vite-node scripts/generate-chromium-version.ts",
"check:lockfile-urls": "node scripts/check-lockfile-urls.cjs",
"check-types": "find . -type f -name \"tsconfig.json\" -not -path \"./node_modules/*\" -not -path \"*/.vscode-test/*\" | sed -r 's|/[^/]+$||' | sort | uniq | xargs -I {} sh -c \"echo Checking types in {} && cd {} && npx tsc --noEmit\"",
"postinstall": "patch-package",
"prepare": "cd ../.. && husky"
Expand Down Expand Up @@ -2097,7 +2098,7 @@
"tree-kill": "^1.2.2",
"vscode-extension-telemetry": "^0.1.6",
"vscode-jsonrpc": "^8.2.1",
"vscode-languageclient": "^8.0.2",
"vscode-languageclient": "^11.0.0",
Comment thread
cklin marked this conversation as resolved.
Resolved
"yauzl": "^3.4.0",
"zip-a-folder": "^4.0.4"
},
Expand Down Expand Up @@ -2186,12 +2187,19 @@
"@azure/identity": "^4.13.1",
"jest-runner-vscode": {
"@vscode/test-electron": "^3.1.0"
},
"vscode-languageclient": {
"minimatch": "11.0.1"
}
},
"lint-staged": {
"./**/*.{json,css,scss}": [
"./**/!(package-lock).{json,css,scss}": [
"prettier --write"
],
"./**/package-lock.json": [
"prettier --write",
"node scripts/check-lockfile-urls.cjs"
],
"./**/*.{ts,tsx}": [
"prettier --write",
"eslint --fix"
Expand Down
51 changes: 51 additions & 0 deletions extensions/ql-vscode/scripts/check-lockfile-urls.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { readFileSync } = require("node:fs");
const { resolve } = require("node:path");

const paths = process.argv.slice(2);
if (paths.length === 0) {
paths.push(resolve(__dirname, "../package-lock.json"));
}

for (const path of paths) {
const lockfile = JSON.parse(readFileSync(path, "utf8"));
if (
!lockfile.packages ||
typeof lockfile.packages !== "object" ||
Array.isArray(lockfile.packages)
) {
throw new Error(`${path}: expected a lockfile with a packages object`);
}

for (const [name, entry] of Object.entries(lockfile.packages)) {
if (!Object.hasOwn(entry, "resolved")) {
continue;
}

let url;
try {
if (typeof entry.resolved !== "string") {
throw new TypeError("Expected a URL string");
}
url = new URL(entry.resolved);
} catch (error) {
if (!(error instanceof TypeError)) {
throw error;
}
console.error(`${path}: ${name}: invalid resolved URL`);
process.exitCode = 1;
continue;
}

if (
url.protocol !== "https:" ||
url.host !== "registry.npmjs.org" ||
url.username ||
url.password
) {
console.error(
`${path}: ${name}: resolved URL must use https://registry.npmjs.org without credentials (received ${url.protocol}//${url.host})`,
);
process.exitCode = 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class CodeQLLanguageClient extends LanguageClient {
synchronize: {
configurationSection: "codeQL",
},
// Ensure that language server exceptions are logged to the same channel as its output.
outputChannel: languageServerLogger.outputChannel,
// Keep client logs separate from raw language-server output.
outputChannelName: "CodeQL Language Client",
},
true,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { spawnSync } from "child_process";
import { writeFileSync } from "fs";
import { resolve, join } from "path";
import type { DirResult } from "tmp";
import { dirSync } from "tmp-promise";

describe("lockfile URL check", () => {
let directory: DirResult;
const script = resolve(__dirname, "../../../scripts/check-lockfile-urls.cjs");

beforeEach(() => {
directory = dirSync({ unsafeCleanup: true });
});

afterEach(() => {
directory.removeCallback();
});

function check(packages: Record<string, unknown>) {
const path = join(directory.name, "package-lock.json");
writeFileSync(path, JSON.stringify({ lockfileVersion: 3, packages }));
return spawnSync(process.execPath, [script, path], { encoding: "utf8" });
}

it("accepts public registry URLs and entries without resolved URLs", () => {
const result = check({
"": { name: "test" },
"node_modules/example": {
resolved: "https://registry.npmjs.org/example/-/example-1.0.0.tgz",
},
"node_modules/@scope/example": {
resolved:
"https://registry.npmjs.org/@scope/example/-/example-1.0.0.tgz",
},
});

expect(result.status).toBe(0);
expect(result.stderr).toBe("");
});

it.each([
"https://pkgs.dev.azure.com/example/package.tgz",
"https://registry.npmjs.org.example.com/package.tgz",
"http://registry.npmjs.org/package.tgz",
"https://registry.npmjs.org:8443/package.tgz",
"file:../example",
"not-a-url",
null,
])("rejects an invalid download location: %s", (resolved) => {
const result = check({ "node_modules/example": { resolved } });

expect(result.status).toBe(1);
expect(result.stderr).toContain("node_modules/example");
});

it("rejects credentials without exposing them in diagnostics", () => {
const result = check({
"node_modules/example": {
resolved:
"https://user:example-password@registry.npmjs.org/package.tgz",
},
});

expect(result.status).toBe(1);
expect(result.stderr).toContain("without credentials");
expect(result.stderr).not.toContain("example-password");
});
});