-
Notifications
You must be signed in to change notification settings - Fork 352
Sanitize subprocess output in run_validate_workflows.cjs (SEC-004) #25971
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,4 +230,51 @@ describe("run_validate_workflows", () => { | |
| const createCall = mockGithub.rest.issues.create.mock.calls[0][0]; | ||
| expect(createCall.body).toContain("... (output truncated)"); | ||
| }); | ||
|
|
||
| it("should sanitize output containing @mentions in new issue body", async () => { | ||
| mockExec.exec.mockImplementation(async (_cmd, _args, options) => { | ||
| if (options?.listeners?.stderr) { | ||
| options.listeners.stderr(Buffer.from("Error: @malicious-user triggered a warning\n")); | ||
| } | ||
| return 1; | ||
| }); | ||
|
|
||
| mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({ | ||
| data: { total_count: 0, items: [] }, | ||
| }); | ||
|
|
||
| mockGithub.rest.issues.create.mockResolvedValue({ | ||
| data: { number: 45, html_url: "https://github.com/testowner/testrepo/issues/45" }, | ||
| }); | ||
|
|
||
| const { main } = await import("./run_validate_workflows.cjs"); | ||
| await main(); | ||
|
|
||
| const createCall = mockGithub.rest.issues.create.mock.calls[0][0]; | ||
| // sanitizeContent should neutralize @mentions so they don't ping users | ||
| expect(createCall.body).not.toMatch(/@malicious-user(?!`)/); | ||
| }); | ||
|
Comment on lines
+234
to
+256
|
||
|
|
||
| it("should sanitize output containing @mentions in comment body", async () => { | ||
| mockExec.exec.mockImplementation(async (_cmd, _args, options) => { | ||
| if (options?.listeners?.stderr) { | ||
| options.listeners.stderr(Buffer.from("Error: @malicious-user triggered a warning\n")); | ||
| } | ||
| return 1; | ||
| }); | ||
|
|
||
| mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({ | ||
| data: { | ||
| total_count: 1, | ||
| items: [{ number: 10, html_url: "https://github.com/testowner/testrepo/issues/10" }], | ||
| }, | ||
| }); | ||
|
|
||
| const { main } = await import("./run_validate_workflows.cjs"); | ||
| await main(); | ||
|
|
||
| const commentCall = mockGithub.rest.issues.createComment.mock.calls[0][0]; | ||
| // sanitizeContent should neutralize @mentions so they don't ping users | ||
| expect(commentCall.body).not.toMatch(/@malicious-user(?!`)/); | ||
| }); | ||
| }); | ||
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.
sanitizeContent(truncatedOutput)is called without amaxLength, and sanitization can expand the string (e.g., wrapping many@mentionsin backticks, balancing fences). That means the final issue/comment body can exceed GitHub's size limits even though you pre-truncate to 50k. To keep the post size bounded, pass an explicitmaxLengthtosanitizeContent(e.g., 50k) and/or perform truncation after sanitization so the sanitized string is what gets size-limited.