Skip to content

feat: Add URL pattern matching and masking utilities #81

@yceffort-naver

Description

@yceffort-naver

Background

URL path parameters can contain sensitive information (e.g., user IDs, member numbers). We need utilities to:

  1. Match a URL against a pattern and extract parameters
  2. Mask sensitive parameters in URLs

Proposal

1. NURL.match(url, pattern)

Extract parameters from a URL by matching against a pattern.

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('/v1/user/12345', '/v1/admin/:id')
// → null (no match)

2. NURL.mask(url, options)

Mask sensitive path parameters in a URL.

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

Examples:

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

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

// Preserve original value length
NURL.mask('/v1/user/12345/info', {
    patterns: ['/v1/user/:userId/info'],
    sensitiveParams: ['userId'],
    preserveLength: true,
})
// → '/v1/user/*****/info' (5 chars, same as '12345')

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

Pattern Syntax

Support both existing syntaxes that NURL already recognizes:

Syntax Example
:variable /user/:id
[variable] /user/[id]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions