2025-03-12 03:17:35 -07:00
|
|
|
import {debug, setSecret} from '@actions/core'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Masks the `sig` parameter in a URL and sets it as a secret.
|
|
|
|
|
* @param url The URL containing the `sig` parameter.
|
|
|
|
|
* @returns A masked URL where the sig parameter value is replaced with '***' if found,
|
|
|
|
|
* or the original URL if no sig parameter is present.
|
|
|
|
|
*/
|
|
|
|
|
export function maskSigUrl(url: string): string {
|
|
|
|
|
if (!url) return url
|
|
|
|
|
|
|
|
|
|
try {
|
2025-03-13 04:23:45 -07:00
|
|
|
const parsedUrl = new URL(url)
|
|
|
|
|
const signature = parsedUrl.searchParams.get('sig')
|
2025-03-12 03:17:35 -07:00
|
|
|
|
2025-03-13 04:23:45 -07:00
|
|
|
if (signature) {
|
|
|
|
|
setSecret(signature)
|
|
|
|
|
setSecret(encodeURIComponent(signature))
|
|
|
|
|
parsedUrl.searchParams.set('sig', '***')
|
2025-03-12 03:17:35 -07:00
|
|
|
return parsedUrl.toString()
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
debug(
|
2025-03-13 04:23:45 -07:00
|
|
|
`Failed to parse URL: ${url} ${
|
2025-03-12 03:17:35 -07:00
|
|
|
error instanceof Error ? error.message : String(error)
|
|
|
|
|
}`
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Masks any URLs containing signature parameters in the provided object
|
|
|
|
|
*/
|
2025-03-13 04:23:45 -07:00
|
|
|
export function maskSecretUrls(body: Record<string, unknown> | null): void {
|
2025-03-12 03:17:35 -07:00
|
|
|
if (typeof body !== 'object' || body === null) {
|
|
|
|
|
debug('body is not an object or is null')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 04:23:45 -07:00
|
|
|
if (
|
|
|
|
|
'signed_upload_url' in body &&
|
|
|
|
|
typeof body.signed_upload_url === 'string'
|
|
|
|
|
) {
|
|
|
|
|
maskSigUrl(body.signed_upload_url)
|
2025-03-12 03:17:35 -07:00
|
|
|
}
|
2025-03-13 04:23:45 -07:00
|
|
|
if (
|
|
|
|
|
'signed_download_url' in body &&
|
|
|
|
|
typeof body.signed_download_url === 'string'
|
|
|
|
|
) {
|
|
|
|
|
maskSigUrl(body.signed_download_url)
|
2025-03-12 03:17:35 -07:00
|
|
|
}
|
|
|
|
|
}
|