Skip to content

Commit 30cb5ff

Browse files
Merge pull request #52 from jgamblin/fix/x-generator-version
fix: use project version in x_generator for accurate CNA tracking
2 parents 4e96a9c + f19a78f commit 30cb5ff

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

cveClientlib.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class cveClient {
55
this.key = key;
66
this.url = url;
77
this.user_path = "/org/" + this.org + "/user/" + this.user;
8-
this._version = "1.0.15";
8+
this._version = "1.0.25";
99
}
1010
/* PUT /cve/{id}/adp — the only ADP endpoint per CVE Services API spec
1111
See https://cveawg.mitre.org/api-docs/ */
@@ -22,6 +22,8 @@ class cveClient {
2222
let path = "/cve/" + cve + "/cna";
2323
if(rejected)
2424
path = "/cve/" + cve + "/reject";
25+
if(!cnajson["x_generator"])
26+
cnajson["x_generator"] = {engine: "cveClient/" + this._version};
2527
return this.putjson(path,opts,null,{cnaContainer:cnajson});
2628
}
2729
reservecve(amount,cve_year,batch_type) {

cveInterface.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,7 @@ async function download_json() {
639639
orgId: "00000000-0000-0000-0000-000000000000",
640640
shortName: "none",
641641
};
642-
if (get_deep(client, "constructor.name") && client._version)
643-
returnJSON["x_generator"] = {
644-
engine: client.constructor.name + "/" + client._version,
645-
};
642+
returnJSON["x_generator"] = { engine: "cveClient/" + _version };
646643
$("#cveUpdateModal .cveupdate").attr("download", cve + ".json");
647644
let cson = encodeURIComponent(JSON.stringify(returnJSON));
648645
$("#cveUpdateModal .cveupdate").attr(
@@ -1817,10 +1814,7 @@ async function publish_cve() {
18171814
orgId: client.userobj.org_UUID,
18181815
shortName: client.org,
18191816
};
1820-
if (get_deep(client, "constructor.name") && client._version)
1821-
pubcve["x_generator"] = {
1822-
engine: client.constructor.name + "/" + client._version,
1823-
};
1817+
pubcve["x_generator"] = { engine: "cveClient/" + _version };
18241818
let cve = mr.cve_id;
18251819
let ispublic = mr.state != "RESERVED";
18261820
let rejected = false;
@@ -2079,10 +2073,7 @@ async function reject_cve(confirm) {
20792073
orgId: client.userobj.org_UUID,
20802074
shortName: client.org,
20812075
};
2082-
if (get_deep(client, "constructor.name") && client._version)
2083-
rejcve["x_generator"] = {
2084-
engine: client.constructor.name + "/" + client._version,
2085-
};
2076+
rejcve["x_generator"] = { engine: "cveClient/" + _version };
20862077
let cve = mr.cve_id;
20872078
let ispublic = mr.state != "RESERVED";
20882079
let rejected = true;

tests/api-client.test.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ describe("cveClient — CVE operations", () => {
7575
await client.publishcve("CVE-2024-1234", { description: "test" });
7676
expect(lastFetchUrl).toBe("https://api.example.com/cve/CVE-2024-1234/cna");
7777
expect(lastFetchOpts.method).toBe("POST");
78-
expect(JSON.parse(lastFetchOpts.body)).toEqual({
79-
cnaContainer: { description: "test" },
80-
});
78+
const body = JSON.parse(lastFetchOpts.body);
79+
expect(body.cnaContainer.description).toBe("test");
80+
expect(body.cnaContainer.x_generator.engine).toMatch(/^cveClient\//);
8181
});
8282

8383
it("publishcve uses PUT for update", async () => {
@@ -122,6 +122,38 @@ describe("cveClient — CVE operations", () => {
122122
});
123123
});
124124

125+
describe("cveClient — x_generator", () => {
126+
let client;
127+
128+
beforeEach(() => {
129+
client = new CveClient(
130+
"test-org",
131+
"test-user",
132+
"key",
133+
"https://api.example.com",
134+
);
135+
});
136+
137+
it("injects default x_generator with cveClientlib version when not set", async () => {
138+
const cnajson = { descriptions: [{ lang: "en", value: "test" }] };
139+
await client.publishcve("CVE-2024-1234", cnajson, true);
140+
expect(cnajson["x_generator"]).toEqual({
141+
engine: "cveClient/" + client._version,
142+
});
143+
});
144+
145+
it("preserves caller-provided x_generator (UI path)", async () => {
146+
const cnajson = {
147+
descriptions: [{ lang: "en", value: "test" }],
148+
x_generator: { engine: "cveClient/1.0.25" },
149+
};
150+
await client.publishcve("CVE-2024-1234", cnajson, true);
151+
expect(cnajson["x_generator"]).toEqual({
152+
engine: "cveClient/1.0.25",
153+
});
154+
});
155+
});
156+
125157
describe("cveClient — ADP operations", () => {
126158
let client;
127159

0 commit comments

Comments
 (0)