fix(seo,engine): 7.0.7 검증 발견 결함 수정 — 표현식 구조분해 회귀·타이틀 접미사 조립·JSON-LD 이스케이프

- SafeExpressionEvaluator 교체(engine-v1.60.0)가 구 평가기가 허용하던 화살표
 파라미터 배열 구조분해(([k, v]) / ([, vid]))를 누락해 해당 문법을 쓰는 액션
 params 가 미평가 원문으로 전송, 장바구니 담기/바로 구매가 전 상품 불능이던
 회귀를 수정 (engine-v1.60.5, production 재빌드 동반). 저장소 레이아웃 54파일
 104곳 사용 형태 전수를 단위/E2E 테스트로 잠금
- TrimStrings 가 타이틀 접미사의 선행 공백을 제거해 봇 렌더 제목이
 "제목| 사이트명" 으로 접착되고 빈 제목 화면은 "| 사이트명" 이 매달리던 기존
 결함 수정 — 조립 규칙을 composeTitleSuffix 단일 지점(SSoT)으로 정규화
- JSON-LD 직렬화에 JSON_HEX_TAG 미적용으로 검색어의 </script> 가 스크립트
 컨텍스트를 조기 종료해 실행 가능한 script 요소가 재생성되던 반사형 XSS(기존
 결함) 차단 — 태그 문자 이스케이프, 구조화 데이터 의미는 보존
This commit is contained in:
HeuJung committed 2026-08-18 09:53:50 +09:00
1 parent b3d0da9355
commit 0bb2ab9b49
10 files changed
+301 -38

No files matched your search

@@ -5,6 +5,16 @@
>
> 형식: [Keep a Changelog](https://keepachangelog.com/ko/1.1.0/)
## [engine-v1.60.5] - 2026-08-18
### Fixed
#### 화살표 파라미터 배열 구조분해 미지원 회귀 (장바구니/바로구매 불능)
- engine-v1.60.0 의 SafeExpressionEvaluator 교체가 구 평가기(`new Function`)가 허용하던 **화살표 함수 파라미터의 배열 구조분해**(`([k, v]) =>`, `([, vid]) =>`)를 수용하지 않아, 해당 문법을 쓰는 표현식이 전부 파싱 실패했다. 액션 params 는 미평가 원문 문자열 그대로 서버에 전송되어 422 가 되며(스토어프론트 장바구니 담기·바로 구매가 전 상품에서 불능), 저장소 레이아웃 54개 파일 104곳이 이 문법을 사용 중이었다.
- `tryParseParamList` 에 배열 패턴(식별자 + 홀/elision, 파라미터 기본값 조합 포함)을 추가하고 `bindParams` 가 JS iterator 시맨틱(비-iterable 은 TypeError)으로 분해 바인딩하도록 했다. 중첩 패턴·rest·객체 패턴은 배포 레이아웃 사용 0건이라 지원하지 않는다(발견 시 arrow 아님으로 안전 되돌림).
- 회귀 잠금: 사용 형태 전수(단일/쌍/홀/기본값/실전 `_purchase_card.json` 본문) 단위 테스트 추가.
## [engine-v1.60.4] - 2026-08-14
### Security
@@ -70,7 +70,7 @@ const DANGEROUS_GLOBALS = new Set([
* 잡히지 않는다. 따라서 리플렉션·프로토타입·디스크립터 계열을 전부 제거하고 순수 데이터 계열만 노출한다.
* (KVE-2026-1915)
*
* @since engine-v1.60.1
* @since engine-v1.60.5
*/
/**
* 대상 객체가 공유 전역(화이트리스트 전역/생성자)이면 거부합니다.
@@ -245,9 +245,18 @@ type Node =
| { type: 'Empty' }
| { type: 'Try'; block: Node; handlerParam: string | null; handler: Node | null; finalizer: Node | null };
/** 함수/화살표 파라미터 (기본값 지원) */
/**
* 함수/화살표 파라미터 (기본값 지원).
*
* `name` 이 null 이면 배열 구조분해 패턴 — `elements` 가 요소 이름 목록이며
* null 요소는 홀(elision)이다 (`([, vid]) =>` → elements: [null, 'vid']).
* 구 평가기(new Function)가 허용하던 형태로, 레이아웃 전반에서 사용된다.
*
* @since engine-v1.60.5
*/
interface Param {
name: string;
name: string | null;
elements?: (string | null)[];
default: Node | null;
}
@@ -758,8 +767,8 @@ class Parser {
}
/**
* 파라미터 목록을 파싱한다: `ident (= 기본값)?` 를 `,` 로 구분. 열림 `(` 는 호출부가
* 이미 소비한 상태이며, 닫힘 `)` 는 소비하지 않는다(호출부가 검사).
* 파라미터 목록을 파싱한다: `(ident | [배열패턴]) (= 기본값)?` 를 `,` 로 구분.
* 열림 `(` 는 호출부가 이미 소비한 상태이며, 닫힘 `)` 는 소비하지 않는다(호출부가 검사).
*
* @return 파싱된 파라미터 배열, 또는 파라미터 형태가 아니면 null(arrow 아님)
*/
@@ -768,11 +777,18 @@ class Parser {
if (this.isPunct(')')) return params; // 빈 목록
for (;;) {
const p = this.peek();
if (!p || p.type !== 'ident' || FORBIDDEN_KEYWORDS.has(String(p.value))) {
let name: string | null = null;
let elements: (string | null)[] | undefined;
if (p && p.type === 'punct' && p.value === '[') {
const pattern = this.tryParseArrayPattern();
if (!pattern) return null;
elements = pattern;
} else if (p && p.type === 'ident' && !FORBIDDEN_KEYWORDS.has(String(p.value))) {
name = String(p.value);
this.pos += 1;
} else {
return null;
}
const name = String(p.value);
this.pos += 1;
let def: Node | null = null;
if (this.isPunct('=')) {
this.pos += 1; // =
@@ -780,7 +796,7 @@ class Parser {
// 콤마를 소비하지 않으므로 다음 파라미터 구분자 ',' 는 그대로 남는다.
def = this.parseExpression();
}
params.push({ name, default: def });
params.push(elements ? { name, elements, default: def } : { name, default: def });
if (this.isPunct(',')) {
this.pos += 1;
continue;
@@ -790,6 +806,48 @@ class Parser {
return params;
}
/**
* 파라미터 위치의 배열 구조분해 패턴 `[a, , b]` 를 파싱한다.
* 요소는 식별자 또는 홀(elision)만 허용 — 중첩 패턴·rest·요소별 기본값은
* 레이아웃 표현식에서 쓰이지 않으므로 지원하지 않는다(발견 시 arrow 아님으로 되돌림).
*
* @return 요소 이름 배열 (홀은 null), 패턴 형태가 아니면 null
* @since engine-v1.60.5
*/
private tryParseArrayPattern(): (string | null)[] | null {
const save = this.pos;
this.pos += 1; // [
const elements: (string | null)[] = [];
for (;;) {
if (this.isPunct(']')) {
this.pos += 1;
return elements;
}
if (this.isPunct(',')) {
elements.push(null); // 홀 (elision)
this.pos += 1;
continue;
}
const t = this.peek();
if (!t || t.type !== 'ident' || FORBIDDEN_KEYWORDS.has(String(t.value))) {
this.pos = save;
return null;
}
elements.push(String(t.value));
this.pos += 1;
if (this.isPunct(',')) {
this.pos += 1;
continue;
}
if (this.isPunct(']')) {
this.pos += 1;
return elements;
}
this.pos = save;
return null;
}
}
private parseArrowBody(): { body: Node; isBlock: boolean } {
// 블록 본문: (…) => { statements } (return 으로 값 반환)
if (this.isPunct('{')) {
@@ -1387,7 +1445,7 @@ function resolveIdentifier(name: string, scope: Scope): unknown {
*
* @param key 해석된 computed 키(임의 타입)
* @return 정규화된 안전한 프로퍼티 키
* @since engine-v1.60.1
* @since engine-v1.60.5
*/
function normalizeKey(key: unknown): string | symbol {
const normalized = typeof key === 'symbol' ? key : String(key);
@@ -1502,7 +1560,19 @@ function bindParams(params: Param[], args: unknown[], local: Scope): void {
if (v === undefined && p.default) {
v = evalNode(p.default, local);
}
local.vars[p.name] = v;
if (p.elements) {
// 배열 구조분해 패턴 — JS iterator 시맨틱과 동일하게 null/undefined 는 예외
if (v == null) {
throw new TypeError(`Cannot destructure ${String(v)}: value is not iterable`);
}
const arr = Array.isArray(v) ? v : Array.from(v as Iterable<unknown>);
for (let e = 0; e < p.elements.length; e++) {
const name = p.elements[e];
if (name !== null) local.vars[name] = arr[e];
}
} else if (p.name !== null) {
local.vars[p.name] = v;
}
}
}
@@ -147,6 +147,69 @@ describe('SafeExpressionEvaluator', () => {
});
});
describe('arrow param 배열 구조분해 (engine-v1.60.5 회귀 — 장바구니/바로구매 불능)', () => {
// 구 평가기(new Function)가 허용하던 형태 전수: 저장소 레이아웃 54파일 104곳 사용
// (`([code])` 35 · `([field, messages])` 34 · `([k, v])` 등 — _purchase_card.json 이 대표)
it('단일 요소 ([k])', () => {
expect(evalx('Object.entries({ a: 1, b: 2 }).map(([k]) => k)')).toEqual(['a', 'b']);
});
it('두 요소 ([k, v])', () => {
expect(evalx('Object.entries({ a: 1, b: 2 }).map(([k, v]) => k + v)')).toEqual(['a1', 'b2']);
});
it('선행 홀 ([, v])', () => {
expect(evalx('Object.entries({ a: 1, b: null }).filter(([, v]) => v != null).length')).toBe(1);
});
it('배열 인자 직접 분해', () => {
expect(evalx('[[1, 2], [3, 4]].map(([a, b]) => a * b)')).toEqual([2, 12]);
});
it('파라미터 기본값 조합 (([a, b] = []) =>)', () => {
expect(evalx('[undefined].map(([a, b] = [7, 8]) => (a ?? 0) + (b ?? 0))')).toEqual([15]);
});
it('null/undefined 인자 분해는 JS 와 동일하게 예외', () => {
expect(() => evalx('[null].map(([a]) => a)')).toThrow();
});
it('실전 회귀: _purchase_card.json 장바구니 담기 본문 표현식', () => {
const ctx = {
product: { data: { id: 98, has_options: true, options: [{ id: 1 }, { id: 2 }] } },
_local: {
selectedOptionItems: [
{
optionId: 11,
quantity: 2,
additionalOptionSelections: { 5: 50, 6: null },
additionalOptionCustomTexts: { 5: '각인 문구' },
},
],
noOptionQuantity: 1,
},
};
const expr =
'product.data?.has_options && (product.data?.options?.length ?? 0) > 1 ? ' +
'{ product_id: product.data?.id, items: (_local.selectedOptionItems ?? []).map(item => ({ ' +
'product_option_id: item.optionId, quantity: item.quantity, ' +
'additional_option_selections: Object.entries(item.additionalOptionSelections ?? {})' +
'.filter(([, vid]) => vid != null)' +
'.map(([gid, vid]) => ({ additional_option_id: Number(gid), value_id: Number(vid), custom_text: item.additionalOptionCustomTexts?.[Number(gid)] })) ' +
'})) } : { product_id: product.data?.id, items: [{ quantity: _local.noOptionQuantity ?? 1 }] }';
expect(evalx(expr, ctx)).toEqual({
product_id: 98,
items: [
{
product_option_id: 11,
quantity: 2,
additional_option_selections: [{ additional_option_id: 5, value_id: 50, custom_text: '각인 문구' }],
},
],
});
});
});
describe('spread (array / object / call)', () => {
it('배열 스프레드', () => {
expect(evalx('[...a, ...b, 3]', { a: [1], b: [2] })).toEqual([1, 2, 3]);