{"id":16808946,"url":"https://github.com/timakin/respmask","last_synced_at":"2025-08-03T03:17:42.376Z","repository":{"id":203008143,"uuid":"708604318","full_name":"timakin/respmask","owner":"timakin","description":"Go middleware for dynamically masking specific fields in JSON responses","archived":false,"fork":false,"pushed_at":"2023-10-24T06:16:33.000Z","size":14,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T22:16:55.730Z","etag":null,"topics":["go","golang","golang-library","http","masking","security","security-tools"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timakin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-23T02:09:46.000Z","updated_at":"2024-11-28T05:30:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"c553339e-d64e-413f-8fd9-4bb86d144814","html_url":"https://github.com/timakin/respmask","commit_stats":null,"previous_names":["timakin/respmask"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Frespmask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Frespmask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Frespmask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Frespmask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timakin","download_url":"https://codeload.github.com/timakin/respmask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248323142,"owners_count":21084451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","golang-library","http","masking","security","security-tools"],"created_at":"2024-10-13T10:00:26.173Z","updated_at":"2025-04-11T01:20:38.727Z","avatar_url":"https://github.com/timakin.png","language":"Go","readme":"![test workflow](https://github.com/timakin/respmask/actions/workflows/test.yml/badge.svg)\n\n# respmask\n\n`respmask` is a Go middleware designed to dynamically mask specific fields in JSON responses, catering to the diverse needs of modern APIs dealing with sensitive data.\n\n## Motivation\n\nIn the world of APIs, especially those that handle sensitive or private data, it's imperative to mask certain response fields without altering the actual data model. `respmask` offers a seamless solution, allowing developers to apply dynamic masking depending on the context of the request.\n\n## Features\n\n- **Dynamic Masking Rules**: Define and adapt masking functions based on request context.\n- **Masking Modes**: Switch between `ExactMode` and `RecursiveMode` for granular control over response data masking.\n- **Recursive Masking**: Efficiently traverse and mask nested JSON objects and arrays.\n- **Extendability**: Craft custom masking functions tailored to specific use cases.\n- **Predefined Masking Rules**: Benefit from built-in rules for typical masking scenarios, including emails, passwords, phone numbers, and credit card numbers.\n\n## Installation\n\n```bash\ngo get github.com/timakin/respmask\n```\n\n## Usage\n\n### Basic Usage with Default Masking Rules\n\n1. Leverage the in-built default masking rules.\n\n```go\nimport \"github.com/timakin/respmask\"\n\nfunc maskingConfig(r *http.Request) (map[string]respmask.MaskingFunc, respmask.MaskingMode) {\n    return map[string]respmask.MaskingFunc{\n        \"email\":    respmask.DefaultMaskingRules[respmask.EmailMasking],\n        \"password\": respmask.DefaultMaskingRules[respmask.PasswordMasking],\n        // ... use other default masking functions as needed ...\n    }, respmask.RecursiveMode\n}\n```\n\n2. Integrate the middleware with your HTTP server and choose a masking mode.\n\n```go\nfunc main() {\n    http.Handle(\"/api/data\", respmask.NewMaskingMiddleware(maskingConfig, http.HandlerFunc(handleData)))\n    http.ListenAndServe(\":8080\", nil)\n}\n```\n\n3. Observe specified fields in your JSON responses being masked according to predefined rules!\n\n### Masking Modes\n\n`respmask` offers two distinct masking modes:\n\n- **ExactMode**: Masks keys strictly based on the hierarchy defined in configuration.\n- **RecursiveMode**: Masks keys throughout the JSON structure, regardless of their depth.\n\nFor instance, given a masking function that targets the key \"email\" with `ExactMode` selected, only the top-level \"email\" key will be masked. On the other hand, with `RecursiveMode`, \"email\" keys across all nesting levels will be masked.\n\n### Crafting Custom Masking Functions\n\nDesign your custom masking functions with ease.\n\n```go\nfunc customMaskFunc(input string) string {\n    // Your unique masking logic here\n    return \"masked_value\"\n}\n```\n\nSubsequently, employ your custom function in the dynamic keys definition:\n\n```go\nfunc maskingConfig(r *http.Request) (map[string]respmask.MaskingFunc, respmask.MaskingMode) {\n    return map[string]respmask.MaskingFunc{\n        \"custom_field\": customMaskFunc,\n        // ... other fields and functions ...\n    }, respmask.RecursiveMode\n}\n```\n\n## Testing\n\nRefer to the in-package test cases for insights on how to effectively test the masking functionality.\n\n## Contributing\n\n1. Fork the repository.\n2. Initiate a new branch for your feature or bugfix.\n3. Implement your changes.\n4. Push to your fork and open a pull request!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Frespmask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimakin%2Frespmask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Frespmask/lists"}