Skip to content
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

Support legacy seed in perf #1256

Merged
merged 12 commits into from
Nov 19, 2024
Merged

Support legacy seed in perf #1256

merged 12 commits into from
Nov 19, 2024

Conversation

atuchin-m
Copy link
Collaborator

The PR support npm run seed_tools create -- --revision <old_revision_with_seed_json>

@atuchin-m atuchin-m self-assigned this Nov 7, 2024
@atuchin-m atuchin-m requested a review from a team as a code owner November 7, 2024 12:25
return await readStudies(filesWithContent, false);
} catch {
console.log(`Failed to read studies ${revision}, use seed.json fallback:`);
const seedContent = execSync(`git show "${revision}":seed/seed.json`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected calls to child_process from a function argument revision. This could lead to a command injection if the input is user controllable. Try to avoid calls to child_process, and if it is needed ensure user input is correctly sanitized or sandboxed.

Source: https://semgrep.dev/r/javascript.lang.security.detect-child-process.detect-child-process


Cc @thypon @kdenhartog

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execSync should be called with an array, instead of a string. This would avoid command injections

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execSync() doesn't support string[]. I've made a wrapper over spawnSync() to address this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, git show <rev>:<filename> has to be called in shell=True anyway. spawnSync() actually doesn't provide more security.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add a check to ensure the parameter is a git hash [a-z0-9]+ so it's safe to pass it as is with shell=True.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return await readStudies(filesWithContent, false);
} catch {
console.log(`Failed to read studies ${revision}, use seed.json fallback:`);
const seedContent = execSync(`git show "${revision}":seed/seed.json`, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add a check to ensure the parameter is a git hash [a-z0-9]+ so it's safe to pass it as is with shell=True.

it('test1_git_revision', () => runTest('test1', 'HEAD'));

// Check creating seed using git history for legacy seed.json.
it('legacy_seed', () => runTest('legacy_seed', '3f3eb03e'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls use full revision.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,2556 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about re-building all expected_seed.json with useProtoFieldName: true, in this PR?
or do you want to commit this file as is and then rewrite it separately?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated test files

return await readStudies(filesWithContent, false);
} catch {
console.log(`Failed to read studies ${revision}, use seed.json fallback:`);
const seedContent = execSync(`git show "${revision}":seed/seed.json`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] Detected calls to child_process from a function argument revision. This could lead to a command injection if the input is user controllable. Try to avoid calls to child_process, and if it is needed ensure user input is correctly sanitized or sandboxed.

Source: https://semgrep.dev/r/javascript.lang.security.detect-child-process.detect-child-process


Cc @thypon @kdenhartog

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation code has been added above.
Also we have a follow up issue for sanitizing all the args: #1250

@@ -203,6 +210,16 @@ describe('create command', () => {
serialNumberPath,
]),
).rejects.toThrowError('process.exit(1)');

const expectedError = (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part was missed and the tests ignored expected_errors.txt

@atuchin-m atuchin-m added this pull request to the merge queue Nov 19, 2024
Merged via the queue into main with commit 260ddf1 Nov 19, 2024
6 checks passed
@atuchin-m atuchin-m deleted the support-legacy-seed-in-perf branch November 19, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants