Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
fetch-depth: 0

Expand Down
32 changes: 32 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 보안 문제 제보 (Security Policy)

comdraft-lambda는 [comdraft](https://github.com/akodm/comdraft)([comdraft.dev](https://comdraft.dev))의 AI 초안 작성 Lambda와 AWS 인프라입니다. 보안 문제를 찾으셨다면 알려 주세요.

## 제보 방법

**공개 이슈, PR, 토론에는 올리지 말아 주세요.** 고치기 전에 다른 사람이 악용할 수 있습니다.

1. 이 저장소의 [Security 탭 → Report a vulnerability](https://github.com/akodm/comdraft-lambda/security/advisories/new)로 비공개 제보를 남겨 주세요.
2. 아래 내용을 함께 적어 주시면 빠르게 확인할 수 있습니다.
- 문제가 있는 파일 위치나 인프라 설정
- 재현 방법 (요청 예시, 순서)
- 예상되는 영향 (예: 다른 사용자의 저장소 읽기, 과금 유발)

## 처리 과정

- 제보를 받으면 7일 안에 확인 답장을 드립니다.
- 문제가 확인되면 고치는 일정을 공유하고, 고친 뒤 제보 내용을 공개할 시점을 함께 정합니다.
- 원하시면 고친 기록에 제보자로 이름을 남겨 드립니다.

## 범위

- 대상: 이 저장소의 Lambda 코드와 Terraform 인프라 설정, comdraft.dev 서비스
- 대상 아님: 서비스 거부(DoS) 공격 시도, AI 비용을 일부러 크게 발생시키는 시도, 다른 사용자의 계정·데이터에 실제로 접근하는 테스트, AWS·Anthropic·GitHub 등 외부 서비스 자체의 문제

테스트는 본인 계정과 본인 저장소로만 해 주세요.

---

## Reporting a vulnerability (English)

Please **do not** open a public issue. Report it privately via [Security → Report a vulnerability](https://github.com/akodm/comdraft-lambda/security/advisories/new) with the affected file or infrastructure setting, steps to reproduce, and the expected impact. You will get a reply within 7 days. Please test only with your own account and repositories, and do not run denial-of-service or cost-inflating tests.
13 changes: 13 additions & 0 deletions infra/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,23 @@ resource "aws_iam_role" "lambda" {

# Anthropic Workload Identity Federation: 실행 역할로 서명된 웹 ID 토큰(JWT)을 받아 Anthropic 토큰으로 교환
# - 계정 단위 설정 "Outbound web identity federation" 을 먼저 켜야 함 (IAM > Account settings, 수동)
# - audience 를 Anthropic 으로만 제한 (Lambda 가 털려도 다른 서비스용 토큰은 못 받게, audience 없는 요청도 거부)
data "aws_iam_policy_document" "lambda_web_identity" {
statement {
actions = ["sts:GetWebIdentityToken"]
resources = ["*"]

condition {
test = "ForAllValues:StringEquals"
variable = "sts:IdentityTokenAudience"
values = ["https://api.anthropic.com"]
}

condition {
test = "Null"
variable = "sts:IdentityTokenAudience"
values = ["false"]
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/observability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ describe('scrubMessage', () => {
});

describe('scrubBreadcrumb', () => {
it('콘솔 기록은 버리고 주소의 쿼리를 지운다', () => {
it('콘솔 기록은 버리고 주소는 호스트까지만 남긴다', () => {
assert.equal(scrubBreadcrumb({ category: 'console', message: 'x' }), null);
assert.deepEqual(
scrubBreadcrumb({ category: 'http', data: { url: 'https://example.com/a?token=1', method: 'GET' } }),
{ category: 'http', data: { url: 'https://example.com/a', method: 'GET' } },
{ category: 'http', data: { url: 'https://example.com', method: 'GET' } },
);
});

it('GitHub 요청 주소의 저장소 이름과 커밋을 남기지 않는다', () => {
const scrubbed = scrubBreadcrumb({
category: 'http',
data: { url: 'https://api.github.com/repos/someone/private-repo/commits/abc123', method: 'GET' },
});

assert.equal(scrubbed?.data?.url, 'https://api.github.com');
});

it('주소로 읽을 수 없는 값은 쿼리만 지운다', () => {
assert.equal(scrubBreadcrumb({ category: 'http', data: { url: '/relative/path?x=1' } })?.data?.url, '/relative/path');
});
});

describe('scrubEvent', () => {
Expand Down
13 changes: 11 additions & 2 deletions src/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ReportContext } from './run-job.ts';
* - SENTRY_DSN 이 없으면 꺼짐 (로컬 실행, 테스트)
* - 오류만 보냄: 성능 추적·로그 전송은 쓰지 않음
* - SDK 가 스스로 모으는 데이터는 모두 끔 (특히 지역 변수: 커밋 코드, 직접 입력 코드, 토큰이 들어 있음)
* - 보내기 전 메시지의 토큰 형태를 가리고 길이를 제한, 주소 기록은 쿼리를 지움
* - 보내기 전 메시지의 토큰 형태를 가리고 길이를 제한, 주소 기록은 호스트까지만 남김
* - 태그에는 작업 id, 단계, 사유 코드 같은 식별자만 (저장소 이름·요청 문구·코드·응답은 넣지 않음)
*/

Expand Down Expand Up @@ -35,12 +35,21 @@ export const scrubMessage = (message: string): string => {

const stripQuery = (url: string): string => url.replace(/[?#].*$/, '');

// 바깥 요청 주소는 호스트까지만 (GitHub 경로의 비공개 저장소 이름·커밋, 사용자가 넣은 참고 링크 경로를 남기지 않음)
const toOrigin = (url: string): string => {
try {
return new URL(url).origin;
} catch {
return stripQuery(url);
}
};

export const scrubBreadcrumb = (breadcrumb: Breadcrumb): Breadcrumb | null => {
// 콘솔 기록은 보내지 않음
if (breadcrumb.category === 'console') return null;

const data = breadcrumb.data ? { ...breadcrumb.data } : undefined;
if (data && typeof data.url === 'string') data.url = stripQuery(data.url);
if (data && typeof data.url === 'string') data.url = toOrigin(data.url);

return {
...breadcrumb,
Expand Down