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
6 changes: 4 additions & 2 deletions src/app/core/substance-form/substance-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,10 @@
const json = this.substanceFormService.cleanSubstance();
const time = new Date().getTime();

this.substanceFormService.regenUUID();
json.uuid = this.substanceFormService.cleanSubstance().uuid;
// Always generate a fresh UUID for the draft copy — do NOT mutate the live substance,
// otherwise the save logic will treat a new substance as an existing one (PUT vs POST).
// A new UUID on every save ensures no two drafts share the same UUID.
json.uuid = this.utilsService.newUUID();

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

const uuid = json.uuid ? json.uuid : 'register';
const type = json.substanceClass;
Expand Down
9 changes: 4 additions & 5 deletions src/app/core/substance/substance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ export class SubstanceService extends BaseHttpService {
delete (substance as any).$$tmpStructureId;
}

const method = type === 'import' || !substance.uuid ? 'POST' : 'PUT';
// Use POST for new substances (no uuid OR no version), PUT for existing ones
const method = type === 'import' || !substance.uuid || !substance.version ? 'POST' : 'PUT';
const options = { body: substance };

const url = `${this.apiBaseUrl}substances?view=internal`;
Expand Down Expand Up @@ -915,10 +916,8 @@ export class SubstanceService extends BaseHttpService {

saveSubstanceWithoutValidation(substance: SubstanceDetail, type?: string): Observable<SubstanceDetail> {
const url = `${this.apiBaseUrl}substances/novalid?view=internal`;
let method = 'PUT';
if (type && type === 'import') {
method = 'POST';
}
// Use POST for imports or new substances (no uuid or no version)
let method = (type === 'import' || !substance.uuid || !substance.version) ? 'POST' : 'PUT';
const options = {
body: substance
};
Expand Down
Loading