Skip to content

Conversation

@chan-hwi
Copy link
Contributor

#81 이슈에서 제안된 내용을 구현합니다.

NURL.match(url: string, pattern: string)

urlpattern의 매칭 여부를 검사합니다. 일치하는 경우 path parametes를 추출하여 반환하며, 일치하지 않는 경우 null을 반환합니다.

NURL.match('/v1/user/12345/info', '/v1/user/:userId/info')
// → { userId: '12345' }

NURL.match('/v1/friends/SENDMONEY/block/111/222', '/v1/friends/:serviceCode/block/[nidNo]/:friendNidNo')
// → { serviceCode: 'SENDMONEY', nidNo: '111', friendNidNo: '222' }

NURL.match('https://files/documents/report.pdf', 'https://files/:folder/[filename]')
// → {folder: 'documents', filename: 'report.pdf'}

NURL.match('/no/dynamic/segments', '/no/dynamic/segments')
// → {} (empty object)

NURL.match('/v1/user/12345', '/v1/admin/:id')
// → null (no match)

NURL.mask(url: string, options: MaskOptions)

interface MaskOptions {
    patterns: string[]
    sensitiveParams: string[]
    maskChar?: string         // default: '*'
    maskLength?: number       // default: 4
    preserveLength?: boolean  // default: false, overrides maskLength if true
}

options.patterns 중 일치하는 패턴에 대해, options.sensitiveParams 로 전달된 필드를 마스킹한 결과를 반환합니다.

NURL.mask('/v1/user/12345/info', {
    patterns: ['/v1/user/:userId/info'],
    sensitiveParams: ['userId'],
})
// → '/v1/user/****/info'


NURL.mask('/v1/user/12345/info', {
    patterns: ['/v1/user/:userId/info'],
    sensitiveParams: ['userId'],
    maskChar: 'X',
    maskLength: 6,
})
// → '/v1/user/XXXXXX/info'

NURL.mask('/v1/friends/SENDMONEY/block/12345/67890', {
    patterns: ['/v1/friends/:serviceCode/block/[nidNo]/:friendNidNo'],
    sensitiveParams: ['nidNo', 'friendNidNo'],
    preserveLength: true,
})
// → '/v1/friends/SENDMONEY/block/*****/*****'

NURL.mask('/v1/friends/SENDMONEY/favorite', {
    patterns: [
        '/v1/friends/:serviceCode/:friendNo',
        '/v1/friends/:serviceCode/favorite',
    ],
    sensitiveParams: ['friendNo'],
    preserveLength: true,
})
// → '/v1/friends/SENDMONEY/favorite'

NURL.mask('/user/admin/profile', {
    patterns: ['/user/:id/profile', '/user/admin/:tab'],
    sensitiveParams: ['id'],
    preserveLength: true,
})
// → '/user/admin/profile'

@yceffort-naver yceffort-naver changed the base branch from main to epic/masking December 30, 2025 02:46
Copy link
Contributor

@yceffort-naver yceffort-naver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yceffort-naver
Copy link
Contributor

In the next PR, please also take care of importing {match, mask} from '@naverpay/nurl/utils'.

@yceffort-naver yceffort-naver merged commit 688565b into NaverPayDev:epic/masking Dec 30, 2025
3 of 5 checks passed
@chan-hwi chan-hwi deleted the feature/81 branch December 30, 2025 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants