Skip to content

Commit c6c33eb

Browse files
committed
feat(vscode): quick fixes for COOKIE002 and LOG001; run-on-save configuration
1 parent 0ff4fec commit c6c33eb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

vscode-extension/src/extension.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,38 @@ export function activate(context: vscode.ExtensionContext) {
8484
actions.push(fix);
8585
}
8686
}
87+
if (code === 'COOKIE002') {
88+
const fix = new vscode.CodeAction('Add HttpOnly; Secure to cookie', vscode.CodeActionKind.QuickFix);
89+
fix.edit = new vscode.WorkspaceEdit();
90+
const lineText = document.lineAt(range.start.line).text;
91+
// Append flags before closing quote/paren if not present
92+
let replaced = lineText;
93+
if (!/HttpOnly/i.test(replaced)) replaced = replaced.replace(/(['"])\s*\)\s*;?$/, '; HttpOnly$1)');
94+
if (!/Secure/i.test(replaced)) replaced = replaced.replace(/(['"])\s*\)\s*;?$/, '; Secure$1)');
95+
fix.edit.replace(
96+
document.uri,
97+
new vscode.Range(new vscode.Position(range.start.line, 0), new vscode.Position(range.start.line, lineText.length)),
98+
replaced
99+
);
100+
fix.diagnostics = [diag];
101+
actions.push(fix);
102+
}
103+
if (code === 'LOG001') {
104+
const fix = new vscode.CodeAction('Redact secret in console log', vscode.CodeActionKind.QuickFix);
105+
fix.edit = new vscode.WorkspaceEdit();
106+
const lineText = document.lineAt(range.start.line).text;
107+
const redacted = lineText
108+
.replace(/sk-[A-Za-z0-9_-]{8,}/g, 'sk-********')
109+
.replace(/eyJ[A-Za-z0-9._-]{20,}/g, 'eyJ********')
110+
.replace(/AKIA[0-9A-Z]{16}/g, 'AKIA**************');
111+
fix.edit.replace(
112+
document.uri,
113+
new vscode.Range(new vscode.Position(range.start.line, 0), new vscode.Position(range.start.line, lineText.length)),
114+
redacted
115+
);
116+
fix.diagnostics = [diag];
117+
actions.push(fix);
118+
}
87119
}
88120
return actions;
89121
}

0 commit comments

Comments
 (0)