Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed revision selection so the 64-revision cap prefers the newest matching branches and tags instead of pruning by ref-name order. [#1122](https://github.com/sourcebot-dev/sourcebot/pull/1122)
- Fixed infinite pagination loop in Gitea/Forgejo when an API token can only see a subset of org repos (the `x-total-count` header reports org total while token returns fewer items). [#1130](https://github.com/sourcebot-dev/sourcebot/pull/1130)
- Fixed path injection vulnerability (CodeQL js/path-injection) in review agent log writing by validating paths stay within the expected log directory. [#1134](https://github.com/sourcebot-dev/sourcebot/pull/1134)
- Fixed missing workflow permissions in `docs-broken-links.yml` by adding explicit `permissions: {}` to follow least privilege principle. [#1131](https://github.com/sourcebot-dev/sourcebot/pull/1131)
- Fixed CodeQL missing-workflow-permissions alert by adding explicit empty permissions to `deploy-railway.yml`. [#1132](https://github.com/sourcebot-dev/sourcebot/pull/1132)

Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ You can optionally include a scope to indicate which package is affected:

PR description:
- If a GitHub issue number was provided, include `Fixes #<github_issue_number>` in the PR description
- If a Linear issue ID was provided (e.g., SOU-123), include `Fixes SOU-123` at the top of the PR description to auto-link the PR to the Linear issue

After the PR is created:
- Update CHANGELOG.md with an entry under `[Unreleased]` linking to the new PR. New entries should be placed at the bottom of their section.
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/features/agents/review-agent/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Octokit } from "octokit";
import { generatePrReviews } from "@/features/agents/review-agent/nodes/generatePrReview";
import { githubPushPrReviews } from "@/features/agents/review-agent/nodes/githubPushPrReviews";
import { githubPrParser } from "@/features/agents/review-agent/nodes/githubPrParser";
import { getReviewAgentLogDir } from "@/features/agents/review-agent/nodes/invokeDiffReviewLlm";
import { env } from "@sourcebot/shared";
import { GitHubPullRequest } from "@/features/agents/review-agent/types";
import path from "path";
Expand Down Expand Up @@ -30,7 +31,7 @@ export async function processGitHubPullRequest(octokit: Octokit, pullRequest: Gi

let reviewAgentLogPath: string | undefined;
if (env.REVIEW_AGENT_LOGGING_ENABLED) {
const reviewAgentLogDir = path.join(env.DATA_CACHE_DIR, "review-agent");
const reviewAgentLogDir = getReviewAgentLogDir();
if (!fs.existsSync(reviewAgentLogDir)) {
fs.mkdirSync(reviewAgentLogDir, { recursive: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ import OpenAI from "openai";
import { sourcebot_file_diff_review, sourcebot_file_diff_review_schema } from "@/features/agents/review-agent/types";
import { env } from "@sourcebot/shared";
import fs from "fs";
import path from "path";
import { createLogger } from "@sourcebot/shared";

const logger = createLogger('invoke-diff-review-llm');

export const getReviewAgentLogDir = (): string => {
return path.join(env.DATA_CACHE_DIR, 'review-agent');
};

const validateLogPath = (logPath: string): void => {
const resolved = path.resolve(logPath);
const logDir = getReviewAgentLogDir();
if (!resolved.startsWith(logDir + path.sep)) {
throw new Error('reviewAgentLogPath escapes log directory');
}
};

export const invokeDiffReviewLlm = async (reviewAgentLogPath: string | undefined, prompt: string): Promise<sourcebot_file_diff_review> => {
logger.debug("Executing invoke_diff_review_llm");

Expand All @@ -19,6 +32,7 @@ export const invokeDiffReviewLlm = async (reviewAgentLogPath: string | undefined
});

if (reviewAgentLogPath) {
validateLogPath(reviewAgentLogPath);
fs.appendFileSync(reviewAgentLogPath, `\n\nPrompt:\n${prompt}`);
}

Expand All @@ -32,6 +46,7 @@ export const invokeDiffReviewLlm = async (reviewAgentLogPath: string | undefined

const openaiResponse = completion.choices[0].message.content;
if (reviewAgentLogPath) {
validateLogPath(reviewAgentLogPath);
fs.appendFileSync(reviewAgentLogPath, `\n\nResponse:\n${openaiResponse}`);
}

Expand Down
Loading