Skip to content

Commit d2e7485

Browse files
committed
Harden protocol icon check logging against injection
- sanitize untrusted values before writing to stderr - apply sanitization to missing protocol names and caught error messages - keep current script behavior and exit codes unchanged
1 parent d2d5cc6 commit d2e7485

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

scripts/check-protocol-icons.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const protocolIconPath = path.join(
2626

2727
const protocolMetadata = JSON.parse(fs.readFileSync(protocolMetadataPath, 'utf8'));
2828

29+
const sanitizeForLog = (value) =>
30+
String(value)
31+
.replace(/[\r\n\t]/g, ' ')
32+
.replace(/[^\x20-\x7E]/g, '')
33+
.trim();
34+
2935
const capitalizeFirstLetter = (value) => {
3036
if (!value) {
3137
return '';
@@ -134,7 +140,7 @@ const main = async () => {
134140
if (missingIconProtocols.length) {
135141
console.error('Protocol icons missing for currently visible protocols:');
136142
missingIconProtocols.forEach((protocolName) => {
137-
console.error(`- ${protocolName}`);
143+
console.error(`- ${sanitizeForLog(protocolName)}`);
138144
});
139145
process.exitCode = 1;
140146
return;
@@ -146,6 +152,7 @@ const main = async () => {
146152
};
147153

148154
main().catch((error) => {
149-
console.error(`Protocol icon check failed: ${error.message}`);
155+
const safeErrorMessage = sanitizeForLog(error?.message || 'Unknown error');
156+
console.error(`Protocol icon check failed: ${safeErrorMessage}`);
150157
process.exitCode = 1;
151158
});

0 commit comments

Comments
 (0)