GithubHelp home page GithubHelp logo

Comments (5)

JasonLiuZhuoCheng avatar JasonLiuZhuoCheng commented on August 16, 2024 1

For example,

	type ID struct {
	RandomField  string `mask:"email"`
	RandomNumber int    `mask:"password"`
}

type myRecord struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields
	ID            ID
	Phone         string
	Url           string `mask:"email"`
	Email         string `mask:"email"`
	Name          string `mask:"email"`
	Address       string
	CreditCard    string
}
record := myRecord{
	ID:         ID{RandomField: "sdjofij", RandomNumber: 1534250},
	Phone:      "090-0000-0000",
	Url:        "http://admin:mysecretpassword@localhost:1234/uri",
	Email:      "[email protected]",
	Name:       "John Doe",
	Address:    "1 AB Road, Paradise",
	CreditCard: "4444-4444-4444-4444",
}

maskTool := masker.NewMaskTool(filter.TagFilter(customMasker.MEmail, customMasker.MPassword))
filteredData := maskTool.MaskDetails(record)

will generate log
filter-data={"Address":"1 AB Road, Paradise","CreditCard":"4444-4444-4444-4444","Email":"dum****@dummy.com","ID":{"RandomField":"sdj****","RandomNumber":0},"Name":"Joh****e","Phone":"090-0000-0000","Url":"htt****admin:mysecretpassword@localhost:1234/uri"}
which the RandomNumber is not correct

from golang-masking-tool.

JasonLiuZhuoCheng avatar JasonLiuZhuoCheng commented on August 16, 2024

The other use case is when I try to mask api request/response, and I am trying to mask the protobuf generated struct, something like this:

type SyncEmployeeInfoRequest struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	EmployeeInfos    []*SyncEmployeeInfoRequest_EmployeeInfo `protobuf:"bytes,1,rep,name=employee_infos,json=employeeInfos,proto3" json:"employee_infos,omitempty" mask:"password"`
	OriginalClientId int32                                   `protobuf:"varint,2,opt,name=original_client_id,json=originalClientId,proto3" json:"original_client_id,omitempty"`
}

and I do this to log the request:

resp, err = next(ctx, req)
maskTool := masker.NewMaskTool(filter.TagFilter(customMasker.MPassword))
			filteredData := maskTool.MaskDetails(req)
			ll := logger.Info().Str("service", service).
				Str("method", method).
				Str("version", build.Version).
				Interface("in", filteredData).

the log will be
in={"original_client_id":1} which the entire EmployeeInfos is gone. I have tried other filters like name, email, and all leads to this behavior, which makes me wonder if nested struct works or not.

from golang-masking-tool.

anu1097 avatar anu1097 commented on August 16, 2024

For example,

	type ID struct {
	RandomField  string `mask:"email"`
	RandomNumber int    `mask:"password"`
}

type myRecord struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields
	ID            ID
	Phone         string
	Url           string `mask:"email"`
	Email         string `mask:"email"`
	Name          string `mask:"email"`
	Address       string
	CreditCard    string
}
record := myRecord{
	ID:         ID{RandomField: "sdjofij", RandomNumber: 1534250},
	Phone:      "090-0000-0000",
	Url:        "http://admin:mysecretpassword@localhost:1234/uri",
	Email:      "[email protected]",
	Name:       "John Doe",
	Address:    "1 AB Road, Paradise",
	CreditCard: "4444-4444-4444-4444",
}

maskTool := masker.NewMaskTool(filter.TagFilter(customMasker.MEmail, customMasker.MPassword))
filteredData := maskTool.MaskDetails(record)

will generate log filter-data={"Address":"1 AB Road, Paradise","CreditCard":"4444-4444-4444-4444","Email":"dum****@dummy.com","ID":{"RandomField":"sdj****","RandomNumber":0},"Name":"Joh****e","Phone":"090-0000-0000","Url":"htt****admin:mysecretpassword@localhost:1234/uri"} which the RandomNumber is not correct

So for this issue, you are using customMasker.MPassword on a int type, I need to update Readme to mention that the maskers work on string coz they need to iterate over it to either mask it completely or partially. Currently support for non-string datatype is missing. Will need to add one to just replace it with some custom String. But Partial masking will not be possible.

from golang-masking-tool.

JasonLiuZhuoCheng avatar JasonLiuZhuoCheng commented on August 16, 2024

so when will non-string datatype masking be available? When will the datatype be masked completely?

from golang-masking-tool.

anu1097 avatar anu1097 commented on August 16, 2024

So this use-case wasn't in my mind when I created the library. The masking library only masks string types in nested structures and returns in same structure. Hence Number is converted to 0 to remove sensitive information.

from golang-masking-tool.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.