mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-19 12:28:05 +08:00
masks the whole URL, update tests
This commit is contained in:
@@ -5,10 +5,6 @@ import {ArtifactServiceClientJSON} from '../../generated'
|
||||
import {getResultsServiceUrl, getRuntimeToken} from './config'
|
||||
import {getUserAgentString} from './user-agent'
|
||||
import {NetworkError, UsageError} from './errors'
|
||||
import {
|
||||
CreateArtifactResponse,
|
||||
GetSignedArtifactURLResponse
|
||||
} from '../../generated/results/api/v1/artifact'
|
||||
|
||||
// The twirp http client must implement this interface
|
||||
interface Rpc {
|
||||
@@ -77,24 +73,32 @@ export class ArtifactHttpClient implements Rpc {
|
||||
/**
|
||||
* Masks the `sig` parameter in a URL and sets it as a secret.
|
||||
* @param url The URL containing the `sig` parameter.
|
||||
* @param urlType The type of the URL (e.g., 'signed_upload_url', 'signed_download_url').
|
||||
* @returns A masked URL where the sig parameter value is replaced with '***' if found,
|
||||
* or the original URL if no sig parameter is present.
|
||||
*/
|
||||
maskSigUrl(url: string, urlType: string): void {
|
||||
const sigMatch = url.match(/[?&]sig=([^&]+)/)
|
||||
if (sigMatch) {
|
||||
setSecret(sigMatch[1])
|
||||
debug(`Masked ${urlType}: ${url.replace(sigMatch[1], '***')}`)
|
||||
maskSigUrl(url: string): string {
|
||||
const sigIndex = url.indexOf('sig=')
|
||||
if (sigIndex !== -1) {
|
||||
const sigValue = url.substring(sigIndex + 4)
|
||||
setSecret(sigValue)
|
||||
return `${url.substring(0, sigIndex + 4)}***`
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
maskSecretUrls(
|
||||
body: CreateArtifactResponse | GetSignedArtifactURLResponse
|
||||
): void {
|
||||
if ('signedUploadUrl' in body && body.signedUploadUrl) {
|
||||
this.maskSigUrl(body.signedUploadUrl, 'signed_upload_url')
|
||||
}
|
||||
if ('signedUrl' in body && body.signedUrl) {
|
||||
this.maskSigUrl(body.signedUrl, 'signed_url')
|
||||
maskSecretUrls(body): void {
|
||||
if (typeof body === 'object' && body !== null) {
|
||||
if (
|
||||
'signed_upload_url' in body &&
|
||||
typeof body.signed_upload_url === 'string'
|
||||
) {
|
||||
this.maskSigUrl(body.signed_upload_url)
|
||||
}
|
||||
if ('signed_url' in body && typeof body.signed_url === 'string') {
|
||||
this.maskSigUrl(body.signed_url)
|
||||
}
|
||||
} else {
|
||||
debug('body is not an object or is null')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user