Skip to content

Commit

Permalink
ensure role name properly encoded (#783)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian DeHamer <[email protected]>
  • Loading branch information
bdehamer authored Oct 14, 2024
1 parent 47b931f commit 6915c1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-boxes-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tuf-js': patch
---

Ensure that role names are properly encoded when used in URLs or file names
8 changes: 5 additions & 3 deletions packages/client/src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ export class Updater {
? metaInfo.version
: undefined;

const encodedRole = encodeURIComponent(role);
const metadataUrl = url.join(
this.metadataBaseUrl,
version ? `${version}.${role}.json` : `${role}.json`
version ? `${version}.${encodedRole}.json` : `${encodedRole}.json`
);

try {
Expand Down Expand Up @@ -439,13 +440,14 @@ export class Updater {
}

private persistMetadata(metaDataName: string, bytesData: Buffer) {
const encodedName = encodeURIComponent(metaDataName);
try {
const filePath = path.join(this.dir, `${metaDataName}.json`);
const filePath = path.join(this.dir, `${encodedName}.json`);
log('WRITE %s', filePath);
fs.writeFileSync(filePath, bytesData.toString('utf8'));
} catch (error) {
throw new PersistError(
`Failed to persist metadata ${metaDataName} error: ${error}`
`Failed to persist metadata ${encodedName} error: ${error}`
);
}
}
Expand Down

0 comments on commit 6915c1f

Please sign in to comment.