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
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
push:
branches: [main, feature/*, release/*]

# Least-privilege default for GITHUB_TOKEN; the `publish` job overrides with `contents: write`.
permissions:
contents: read

jobs:
package:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('referenceLogViewProvider', function () {
assert.ok(actualTime === currentTimeString || actualTime === nextTimeString)
assert.ok(actual.includes('MIT'))
assert.ok(actual.includes('def two_su'))
assert.ok(actual.includes(mockUrl))
assert.match(actual, /https:\/\/www\.amazon\.com/)
assert.ok(!actual.includes(LicenseUtil.getLicenseHtml('MIT')))
})
})
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('referenceLogViewProvider', function () {
assert.ok(actual.includes('apache'))
assert.ok(actual.includes('TEST_REPO'))
assert.ok(actual.includes('test reference'))
assert.ok(actual.includes('flare.com'))
assert.ok(actual.includes('cw.com'))
assert.match(actual, /flare\.com/)
assert.match(actual, /cw\.com/)
})
})
10 changes: 9 additions & 1 deletion packages/core/src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ export class Auth implements AuthService, ConnectionManager {
* e.g. https://view.awsapps.com/start/# will become https://view.awsapps.com/start
*/
public normalizeStartUrl(startUrl: string | undefined) {
return !startUrl ? undefined : startUrl.replace(/[\/#]+$/g, '')
if (!startUrl) {
return undefined
}
// Strip trailing '/' and '#' without a backtracking-prone regex (avoids ReDoS).
let end = startUrl.length
while (end > 0 && (startUrl[end - 1] === '/' || startUrl[end - 1] === '#')) {
end--
}
return startUrl.slice(0, end)
}

public isInternalAmazonUser(): boolean {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/codewhisperer/util/authUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ export class AuthUtil {
}

public reformatStartUrl(startUrl: string | undefined) {
return !startUrl ? undefined : startUrl.replace(/[\/#]+$/g, '')
if (!startUrl) {
return undefined
}
// Strip trailing '/' and '#' without a backtracking-prone regex (avoids ReDoS).
let end = startUrl.length
while (end > 0 && (startUrl[end - 1] === '/' || startUrl[end - 1] === '#')) {
end--
}
return startUrl.slice(0, end)
}

// current active cwspr connection
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/codewhisperer/util/importAdderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function findLineOfFirstCode(editor: vscode.TextEditor, firstLineOfRecomm
// skip //, /*, *, */, empty line
if (
!text.match(/^\s*\/\//) &&
!text.match(/\s*use\s+strict/) &&
!text.match(/^\s*['"]?use\s+strict/) &&
!text.match(/^\s*$/) &&
!text.match(/^\s*\/\s*\*/) &&
!text.match(/^\s*\*/) &&
Expand Down Expand Up @@ -62,7 +62,7 @@ export function findLineOfLastImportStatement(editor: vscode.TextEditor, firstLi
return i + 1
}
} else if (lang === 'javascript' || lang === 'jsx') {
if (text.match(/^\s*import\s+\S+/) || text.match(/=\s*require\s*\(\s*\S+\s*\)\s*;/)) {
if (text.match(/^\s*import\s+\S+/) || text.match(/=\s*require\s*\(/)) {
return i + 1
}
} else if (lang === 'java') {
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/shared/utilities/proxyUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ export class ProxyUtil {
}

const strictSSL = config.proxyStrictSSL
// Handle SSL certificate verification
// Handle SSL certificate verification.
if (!strictSSL) {
// Intentional, explicit user opt-in: this mirrors VS Code's own `http.proxyStrictSSL`
// setting. Only disabled when the user has explicitly turned off strict SSL, e.g. for
// corporate proxies with self-signed certificates. Logged as a warning so it is visible.
// codeql[js/disabling-certificate-validation]
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
this.logger.info('SSL verification disabled via VS Code settings')
this.logger.warn('Proxy SSL certificate verification disabled via VS Code "http.proxyStrictSSL" setting')
return // No need to set CA certs when SSL verification is disabled
}

Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/shared/utilities/textUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export function indent(s: string, size: number = 4, clear: boolean = false): str
throw Error() // TODO: implement "dedent" for negative size.
}
if (clear) {
return s.replace(/^[ \t]*([^\n])/, `${spaces}$1`).replace(/(\n+)[ \t]*([^ \t\n])/g, `$1${spaces}$2`)
return s.replace(/^[ \t]*([^\n])/, `${spaces}$1`).replace(/(\n)[ \t]*([^ \t\n])/g, `$1${spaces}$2`)
}
return spaces + s.replace(/(\n+)(.)/g, `$1${spaces}$2`)
return spaces + s.replace(/(\n)([^\n])/g, `$1${spaces}$2`)
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ export function addCodiconToString(codiconName: string, text: string): string {
* @returns Final output without any new lines or comments
*/
export function stripNewLinesAndComments(text: string): string {
const blockCommentRegExp = /\/\*.*\*\//
const blockCommentRegExp = /\/\*(?:[^*]|\*(?!\/))*\*\//g
let result: string = ''

text.split(/\r|\n/).map((s) => {
Expand Down Expand Up @@ -249,7 +249,13 @@ export function getRandomString(length = 32) {
* @returns a base 64 url string
*/
export function toBase64URL(base64: string) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
const encoded = base64.replace(/\+/g, '-').replace(/\//g, '_')
// Strip trailing '=' padding without a backtracking-prone regex (avoids ReDoS).
let end = encoded.length
while (end > 0 && encoded[end - 1] === '=') {
end--
}
return encoded.slice(0, end)
}

export function undefinedIfEmpty(str: string | undefined): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/shared/extensions/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function echoEnvVarsCmd(varNames: string[]) {
* Trim noisy windows ChildProcess result to final line for easier testing.
*/
function assertOutputContains(rawOutput: string, expectedString: string): void | never {
const output = rawOutput.trim().split('\n').at(-1)?.replace('"', '') ?? ''
const output = rawOutput.trim().split('\n').at(-1)?.replace(/"/g, '') ?? ''
assert.ok(output.includes(expectedString), `Expected output to contain "${expectedString}", but got "${output}"`)
}

Expand Down
7 changes: 4 additions & 3 deletions scripts/createRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ if (changelog.entries.length === 0) {
append += '\n' + fileData.toString()
nodefs.writeFileSync('CHANGELOG.md', append)

child_process.execSync(`git add ${changesDirectory}`)
child_process.execSync(`git rm -rf --ignore-unmatch ${nextReleaseDirectory}`)
child_process.execSync('git add CHANGELOG.md')
// Use execFileSync (no shell) so directory paths cannot be interpreted as shell syntax.
child_process.execFileSync('git', ['add', changesDirectory])
child_process.execFileSync('git', ['rm', '-rf', '--ignore-unmatch', nextReleaseDirectory])
child_process.execFileSync('git', ['add', 'CHANGELOG.md'])

console.log(changesFile)
3 changes: 2 additions & 1 deletion scripts/newChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ const path = join(directory, fileName)
nodefs.writeFileSync(path, JSON.stringify(contents, undefined, '\t') + '\n')

console.log(`Change log written to ${path}`)
child_process.execSync(`git add ${directory}`)
// Use execFileSync (no shell) so the directory path cannot be interpreted as shell syntax.
child_process.execFileSync('git', ['add', directory])
console.log('Change log added to git working directory')
Loading