-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove logging of any SAS tokens in Actions/Cache and Actions/Artifact #1982
Open
salmanmkc
wants to merge
7
commits into
main
Choose a base branch
from
salmanmkc/obfuscate-sas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+953
−8
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
944e6b7
Add secret and signature masking for cache and artifact packages
salmanmkc 884aa17
remove these changes
salmanmkc 1cd2f8a
Instead of using utility method in core lib, use method in both twirp…
salmanmkc 47c4fa8
masks the whole URL, update tests
salmanmkc 5007821
Remove clean script
salmanmkc 3ac34ff
Mask different situations, malformed URL, encoded, decoded, raw signa…
salmanmkc abd9054
Log debug error when failing to decode
salmanmkc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
packages/artifact/__tests__/artifactTwirpClient.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import {ArtifactHttpClient} from '../src/internal/shared/artifact-twirp-client' | ||
import {setSecret} from '@actions/core' | ||
import {CreateArtifactResponse} from '../src/generated/results/api/v1/artifact' | ||
|
||
jest.mock('@actions/core', () => ({ | ||
setSecret: jest.fn(), | ||
info: jest.fn(), | ||
debug: jest.fn() | ||
})) | ||
|
||
describe('ArtifactHttpClient', () => { | ||
let client: ArtifactHttpClient | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
process.env['ACTIONS_RUNTIME_TOKEN'] = 'test-token' | ||
process.env['ACTIONS_RESULTS_URL'] = 'https://example.com' | ||
client = new ArtifactHttpClient('test-agent') | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env['ACTIONS_RUNTIME_TOKEN'] | ||
delete process.env['ACTIONS_RESULTS_URL'] | ||
}) | ||
|
||
describe('maskSigUrl', () => { | ||
it('should mask the sig parameter and set it as a secret', () => { | ||
const url = | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token') | ||
expect(maskedUrl).toBe( | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***' | ||
) | ||
}) | ||
|
||
it('should return the original URL if no sig parameter is found', () => { | ||
const url = 'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).not.toHaveBeenCalled() | ||
expect(maskedUrl).toBe(url) | ||
}) | ||
|
||
it('should handle sig parameter at the end of the URL', () => { | ||
const url = 'https://example.com/upload?param1=value&sig=secret-token' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token') | ||
expect(maskedUrl).toBe('https://example.com/upload?param1=value&sig=***') | ||
}) | ||
|
||
it('should handle sig parameter in the middle of the URL', () => { | ||
const url = 'https://example.com/upload?sig=secret-token¶m2=value' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token¶m2=value') | ||
expect(maskedUrl).toBe('https://example.com/upload?sig=***') | ||
}) | ||
}) | ||
|
||
describe('maskSecretUrls', () => { | ||
it('should mask signed_upload_url', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const response = { | ||
ok: true, | ||
signed_upload_url: | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
} | ||
|
||
client.maskSecretUrls(response) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
) | ||
}) | ||
|
||
it('should mask signed_download_url', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const response = { | ||
signed_url: | ||
'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
} | ||
|
||
client.maskSecretUrls(response) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/download?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
) | ||
}) | ||
|
||
it('should not call maskSigUrl if URLs are missing', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const response = {} as CreateArtifactResponse | ||
|
||
client.maskSecretUrls(response) | ||
|
||
expect(spy).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should handle both URL types when present', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const response = { | ||
signed_upload_url: 'https://example.com/upload?sig=secret-token1', | ||
signed_url: 'https://example.com/download?sig=secret-token2' | ||
} | ||
|
||
client.maskSecretUrls(response) | ||
|
||
expect(spy).toHaveBeenCalledTimes(2) | ||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/upload?sig=secret-token1' | ||
) | ||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/download?sig=secret-token2' | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import {CacheServiceClient} from '../src/internal/shared/cacheTwirpClient' | ||
import {setSecret} from '@actions/core' | ||
|
||
jest.mock('@actions/core', () => ({ | ||
setSecret: jest.fn(), | ||
info: jest.fn(), | ||
debug: jest.fn() | ||
})) | ||
|
||
describe('CacheServiceClient', () => { | ||
let client: CacheServiceClient | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
process.env['ACTIONS_RUNTIME_TOKEN'] = 'test-token' | ||
client = new CacheServiceClient('test-agent') | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env['ACTIONS_RUNTIME_TOKEN'] | ||
}) | ||
|
||
describe('maskSigUrl', () => { | ||
it('should mask the sig parameter and set it as a secret', () => { | ||
const url = | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=secret-token' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token') | ||
expect(maskedUrl).toBe( | ||
'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z&sig=***' | ||
) | ||
}) | ||
|
||
it('should return the original URL if no sig parameter is found', () => { | ||
const url = 'https://example.com/upload?se=2025-03-05T16%3A47%3A23Z' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).not.toHaveBeenCalled() | ||
expect(maskedUrl).toBe(url) | ||
}) | ||
|
||
it('should handle sig parameter at the end of the URL', () => { | ||
const url = 'https://example.com/upload?param1=value&sig=secret-token' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token') | ||
expect(maskedUrl).toBe('https://example.com/upload?param1=value&sig=***') | ||
}) | ||
|
||
it('should handle sig parameter in the middle of the URL', () => { | ||
const url = 'https://example.com/upload?sig=secret-token¶m2=value' | ||
|
||
const maskedUrl = client.maskSigUrl(url) | ||
|
||
expect(setSecret).toHaveBeenCalledWith('secret-token¶m2=value') | ||
expect(maskedUrl).toBe('https://example.com/upload?sig=***') | ||
}) | ||
}) | ||
|
||
describe('maskSecretUrls', () => { | ||
it('should mask signed_upload_url', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const body = { | ||
signed_upload_url: 'https://example.com/upload?sig=secret-token', | ||
key: 'test-key', | ||
version: 'test-version' | ||
} | ||
|
||
client.maskSecretUrls(body) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/upload?sig=secret-token' | ||
) | ||
}) | ||
|
||
it('should mask signed_download_url', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const body = { | ||
signed_download_url: 'https://example.com/download?sig=secret-token', | ||
key: 'test-key', | ||
version: 'test-version' | ||
} | ||
|
||
client.maskSecretUrls(body) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/download?sig=secret-token' | ||
) | ||
}) | ||
|
||
it('should mask both URLs when both are present', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const body = { | ||
signed_upload_url: 'https://example.com/upload?sig=secret-token1', | ||
signed_download_url: 'https://example.com/download?sig=secret-token2' | ||
} | ||
|
||
client.maskSecretUrls(body) | ||
|
||
expect(spy).toHaveBeenCalledTimes(2) | ||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/upload?sig=secret-token1' | ||
) | ||
expect(spy).toHaveBeenCalledWith( | ||
'https://example.com/download?sig=secret-token2' | ||
) | ||
}) | ||
|
||
it('should not call maskSigUrl when URLs are missing', () => { | ||
const spy = jest.spyOn(client, 'maskSigUrl') | ||
const body = { | ||
key: 'test-key', | ||
version: 'test-version' | ||
} | ||
|
||
client.maskSecretUrls(body) | ||
|
||
expect(spy).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having this as a method on clients (therefore needing to export/test the entire client) how about making a singular
maskSignedURLSignature
utility function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, tried to do that here, discussed with @Link- and was told it's ok to have duplicated code, so reverted the approach with the utility function and put it into each client. Ran into some issue with testing it locally using npm link for some reason. Logically I think it should work with the utility function in core, so open to trying that out, but hit that issue with the test saying the utility function doesn't exist, despite the compiled code showing it and the typescript compiler not complaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same conversation we had for cache / artifacts regarding the clients and shared components. It might not be worth it to block this small fix by a larger effort to address the use of a shared library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't necessarily mean making it shared across packages, more of a utility function in each. Since it's on the client, we're exporting it now (for tests?). It doesn't need to be on the client class since it it doesn't use any class attributes and could be easier to test just that part.
But this is all nonblocking for the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, ya that sounds like a good idea, I can put it in util.ts