feat(rails): GIT_RAW_ALLOWED_HOSTS env 로 파일 프록시 allowlist 외부화
- 기존에는 git.nabomhalang.co.kr 한 곳만 하드코딩되어 있었음 - GIT_RAW_ALLOWED_HOSTS=comma,separated,hosts 로 여러 호스트 지원 - 기본값은 기존과 동일 (git.nabomhalang.co.kr) — 행동 변화 없음 - hanarang-rails v0.1.3 의 외부 배포 친화 패키지와 세트
This commit is contained in:
@@ -96,18 +96,28 @@ export class RailsService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch raw file content from the internal Gitea. Restricted to the
|
||||
* Gitea host for safety.
|
||||
* Fetch raw file content from a Git host. Restricted to an allowlist
|
||||
* of hosts for SSRF safety.
|
||||
*
|
||||
* Allowlist is configured via env var GIT_RAW_ALLOWED_HOSTS — comma
|
||||
* separated. Defaults to the hanarang-internal Gitea instance.
|
||||
*/
|
||||
async fetchFileContent(rawUrl: string): Promise<string | null> {
|
||||
const allowedHost = 'git.nabomhalang.co.kr';
|
||||
const allowedHosts = (
|
||||
this.config.get<string>('GIT_RAW_ALLOWED_HOSTS') ??
|
||||
'git.nabomhalang.co.kr'
|
||||
)
|
||||
.split(',')
|
||||
.map((h) => h.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(rawUrl);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (parsed.host !== allowedHost) return null;
|
||||
if (!allowedHosts.includes(parsed.host)) return null;
|
||||
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user