IBM Guardium

IBM Guardium

Join this online user group to communicate across Security product users and IBM experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

  • 1.  Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Tue October 29, 2024 03:31 AM

    I'm working on a masking use case for CNIC (13-digit) and card numbers (16-digit) using regular expressions. We've created a regex to capture 13 characters for CNIC and 16 characters for card numbers, but we're facing an issue where the regex captures sequences longer than the intended length.

    For the CNIC, we're using this regex: ([0-9][0-9][0-9][0-9])[0-9]-([0-9][0-9][0-9][0-9])[0-9][0-9][0-9]-([0-9]). with Dashes


    And for card numbers with spaces between each group of 4 digits, we're using: ([0-9][0-9])[0-9][0-9] ([0-9][0-9])[0-9][0-9] ([0-9][0-9])[0-9][0-9] ([0-9][0-9])[0-9][0-9].

    How can we ensure that the regex captures only exactly 13 characters for CNICs and exactly 16 characters for card numbers, without matching any longer sequences?

    Thank you for your guidance!



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------


  • 2.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Wed October 30, 2024 09:49 AM

    Hello Ahmad,

    For card numbers I suggest using the Guardium built-in special pattern test:  guardium://CREDIT_CARD (https://www.ibm.com/docs/en/gdp/12.x?topic=policies-special-pattern-tests)

    For custom regex capturing sequences longer than the intended length,  you may use ^ and $ to indicated positions at start and end of a line respectively. There are several websites that helps build and test regex. For example: https://regex101.com/

    Hope this helps



    ------------------------------
    Marcio Bulek
    ------------------------------



  • 3.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Wed October 30, 2024 12:02 PM

    Hello,

    Thank you for the suggestion. I have tried using the ^ and $ symbols in the regex to define the start and end positions, but this approach did not result in masking at the database level as expected.

    Any additional guidance on ensuring that the regex effectively masks data at the DB level would be greatly appreciated.

    Thanks again for your assistance



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------



  • 4.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Wed October 30, 2024 02:10 PM
    Edited by Wendy Zemba Wed October 30, 2024 02:31 PM

    Ahmad:

    It sounds like you are trying to build your own regex for use in a policy extrusion rule. The policy doesn't have a way to limit the number of characters outside of what the regex would control.

    Have you tried using the regex provided by the predefined rules in the Sensitive Data Discovery module? For example, Guardium has this regex for 16 digit CC# with dashes or spaces: ^[0-9]{4}[-, ]?[0-9]{4}[-, ]?[0-9]{4}[-, ]?[0-9]{4}[ ]*$.

    You can find this information by going to Discover Sensitive Data, clone any of the out of the box templates, and view the predefined classification rules available under 'What to discover'.



    ------------------------------
    Wendy Zemba
    Sr. Consultant, Data Protection
    Converge Technology Solutions
    wendy.zemba@convergetp.com

    Need help with your Guardium deployment? Contact me directly to discuss engagement opportunities. Currently serving North America.
    ------------------------------



  • 5.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Fri November 01, 2024 03:47 AM

    Hello Wendy Zemba,

    Thank you for your response.

    I used the regex that you mentioned, but it didn't work and did not mask the data. Additionally, I have uploaded a snapshot for your reference.



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------



  • 6.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Wed October 30, 2024 03:41 PM

    Hello Ahmad,

    I searched online and it seems a CNIC number has the following format: XXXXX-XXXXXX-X  For example: 12345-1234567-1

    This regex should work: ^[0-9]{5}-[0-9]{7}-[0-9]$



    ------------------------------
    Marcio Bulek
    ------------------------------



  • 7.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Fri November 01, 2024 03:16 AM

    Hello Marcio Bulek,

    Thank you for your response. I tried the regex you mentioned, but it didn't work and didn't mask the data. Additionally, I have uploaded a snapshot for your reference.

    Secondly, to capture a 13-digit CNIC with dashes, if the regex ([0-9][0-9][0-9][0-9])[0-9]-([0-9][0-9][0-9][0-9])[0-9][0-9][0-9]-([0-9])  is used, it will mask the data as well. However, if you use ^ and $ at the start and end, it does not work.I have uploaded a snapshot for your reference.

    In my case, the CNIC is without dashes, such as 1234567890123. Please provide the specific regex pattern for masking to capture this format.



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------



  • 8.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Fri November 01, 2024 06:42 AM
      |   view attached

    Hi Ahmad,

    Could you try this one ^([0-9]{4})([0-9]{4})([0-9]{4})([0-9])$ for 1234567890123 format. 

    I hope it works the way you want it to



    ------------------------------
    Veysel Gundogdu
    ------------------------------



  • 9.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Fri November 01, 2024 07:34 AM

    Hello Veysel Gundogdu

    I tried the regex you mentioned ^([0-9]{4})([0-9]{4})([0-9]{4})([0-9])$, but it didn't work and didn't mask the data. Additionally, I have uploaded a snapshot for your reference.

    Secondly, if we use sign ^  and & , masking didn't work.



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------



  • 10.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Fri November 01, 2024 11:49 AM
      |   view attached

    Hi Ahmad,

    You should check your extrusion rule and related configuration details (rule actions, s-tap ) because the regex pattern is valid. Also Data Redaction has some limitations, please check the attachment and link.

    https://www.ibm.com/docs/en/gdp/11.5?topic=actions-logging-ignoring-rule#policy_rule_actions_logging__redact_restrictions



    ------------------------------
    Veysel Gundogdu
    Senior Security Consultant / Managing Partner
    Mernus Bilisim Teknolojileri A.S
    Istanbul
    ------------------------------



  • 11.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Mon November 04, 2024 10:09 AM

    Classification: Public


    Hi,

    Good for testing regex is https://regex101.com/.

    For using ^ and $ you must input all line with white space char..

    You can use filter (^\d{13})(?:\.)$ for your sample string >>1234567890123.<<

     

     

    Regards Petr Mares

     

     






  • 12.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Tue November 05, 2024 01:36 AM

    Hello petr Mares

    Thanks for your suggestion.

    The regex you mentioned didn't work. Additionally, I have uploaded a snapshot for your reference.



    ------------------------------
    Ahmad Hassan Tariq
    ------------------------------



  • 13.  RE: Ensuring Exact Length Matches in Regex for CNIC and Card Number Masking in Guardium

    Posted Wed November 06, 2024 10:19 AM

    Hi,

    I'm sorry, I see "." at the end of string. Try:

    ^\d{13} - for matching only first 13 numbers  Ex: 12345678901234, 1234567890123RT

    ^\d{13}$ - you did try it. This matches only 13 numbers from start line ^ to the end line $, pay attention to the whitespace chars at the begin or end

    \d{13} match only 13 numbers everywhere Ex: 1234567890123456, a1234567890123b

    try web page Regex101 for test your string



    ------------------------------
    petr mares
    ------------------------------