sir.kr 커뮤니티 제보(Xbuilder 님 외)와 전수조사 발굴분을 코어·게시판· 이커머스·페이지·ckeditor5 전반에 반영. - 통합 검색 하이라이트: 코어 SearchHighlighter 로 원문 이스케이프 후 강조 (저장형 XSS 차단, board/ecommerce/page 3중복제 통합) - 공개 최신글·인기글·관리자 대시보드: 읽기권한 없는 게시판·블라인드·비활성 게시판 글 필터. 비밀글은 기존 공개 정책대로 제목 노출 유지(본문만 보호) - 게시판 관리 대시보드 권한 게이트, 이커머스 쿠폰 다운로드·리뷰 대상·주문옵션 확정 스코프 강화, 취소/환불 항목 검증 회원/비회원 대칭 - 만료 토큰 거부(SetLocale), 회원 탈퇴·정보관리 실패 시 내부 오류 원문 마스킹 - 예외→응답 매핑 정비(generic catch 상태코드), ckeditor 업로드 권한 게이트 정리 정책 정합 정정: 착수 계획이 "비밀글 제목 노출=취약점"으로 전제해 공개 최신글· 대시보드에 넣었던 is_secret 필터는, 저장소가 확정한 "제목 공개, 본문만 보호" 정책(2026-01-02/02-04/06-18/06-19)과 배치되어 되돌림. 읽기권한·블라인드 필터는 유지. Chrome MCP 실측(T1~T10) + 회귀 테스트로 확인.
111 lines
3.7 KiB
PHP
111 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Search;
|
|
|
|
use App\Search\SearchHighlighter;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* 검색 하이라이트/평문화 공유 헬퍼 회귀 테스트.
|
|
*
|
|
* 게시판·상품·페이지 검색 리스너가 공유하는 SSoT 이므로, XSS 이스케이프와
|
|
* 엔티티-태그 부활 차단을 이 한 곳에서 고정한다.
|
|
*/
|
|
class SearchHighlighterTest extends TestCase
|
|
{
|
|
/**
|
|
* @scenario case=highlighter_escape
|
|
*
|
|
* @effects highlight_escapes_markup_and_marks_keyword
|
|
*/
|
|
public function test_highlight_escapes_markup_in_source_text(): void
|
|
{
|
|
$result = SearchHighlighter::highlight('<img src=x onerror=alert(1)> 날씨', '날씨');
|
|
|
|
// 원문 태그는 이스케이프되어 실행 계약으로 나가지 않는다.
|
|
$this->assertStringNotContainsString('<img', $result);
|
|
$this->assertStringContainsString('<img', $result);
|
|
$this->assertStringNotContainsString('onerror=alert(1)>', $result);
|
|
// 검색어만 <mark> 로 감싸진다.
|
|
$this->assertStringContainsString('<mark>날씨</mark>', $result);
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_escape
|
|
*
|
|
* @effects highlight_escapes_markup_and_marks_keyword
|
|
*/
|
|
public function test_highlight_escapes_when_keyword_absent(): void
|
|
{
|
|
$result = SearchHighlighter::highlight('<script>alert(1)</script>', '없는키워드');
|
|
|
|
$this->assertStringNotContainsString('<script>', $result);
|
|
$this->assertStringContainsString('<script>', $result);
|
|
$this->assertStringNotContainsString('<mark>', $result);
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_escape
|
|
*
|
|
* @effects highlight_escapes_markup_and_marks_keyword
|
|
*/
|
|
public function test_highlight_returns_empty_for_null_or_empty(): void
|
|
{
|
|
$this->assertSame('', SearchHighlighter::highlight(null, '키워드'));
|
|
$this->assertSame('', SearchHighlighter::highlight('', '키워드'));
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_escape
|
|
*
|
|
* @effects highlight_escapes_markup_and_marks_keyword
|
|
*/
|
|
public function test_highlight_handles_empty_keyword_by_escaping_only(): void
|
|
{
|
|
$result = SearchHighlighter::highlight('<b>hello</b>', '');
|
|
|
|
$this->assertSame('<b>hello</b>', $result);
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_plain_text
|
|
*
|
|
* @effects plain_text_never_resurrects_entity_encoded_tags
|
|
*/
|
|
public function test_to_plain_text_strips_real_tags(): void
|
|
{
|
|
$result = SearchHighlighter::toPlainText('<p>hello <strong>world</strong></p>');
|
|
|
|
$this->assertSame('hello world', $result);
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_plain_text
|
|
*
|
|
* @effects plain_text_never_resurrects_entity_encoded_tags
|
|
*/
|
|
public function test_to_plain_text_does_not_resurrect_entity_encoded_tags(): void
|
|
{
|
|
// 저장 시점에 엔티티로 인코딩된 태그: strip_tags 를 먼저 돌리면 통과 후 디코드로 부활한다.
|
|
$encoded = '<script>alert(1)</script> 본문';
|
|
|
|
$result = SearchHighlighter::toPlainText($encoded);
|
|
|
|
// 디코드 후 태그 제거 순서라 부활한 태그가 남지 않는다.
|
|
$this->assertStringNotContainsString('<script>', $result);
|
|
$this->assertStringContainsString('alert(1)', $result);
|
|
$this->assertStringContainsString('본문', $result);
|
|
}
|
|
|
|
/**
|
|
* @scenario case=highlighter_plain_text
|
|
*
|
|
* @effects plain_text_never_resurrects_entity_encoded_tags
|
|
*/
|
|
public function test_to_plain_text_returns_empty_for_null(): void
|
|
{
|
|
$this->assertSame('', SearchHighlighter::toPlainText(null));
|
|
$this->assertSame('', SearchHighlighter::toPlainText(''));
|
|
}
|
|
}
|