{"id":22779965,"url":"https://github.com/duffn/libvmod-querymodifier","last_synced_at":"2025-06-15T16:02:31.608Z","repository":{"id":267560993,"uuid":"901557891","full_name":"duffn/libvmod-querymodifier","owner":"duffn","description":"A Varnish VMOD that allows modification of a URL's query parameters.","archived":false,"fork":false,"pushed_at":"2025-03-04T00:58:10.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T05:49:20.819Z","etag":null,"topics":["varnish","varnish-cache","vmod"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/duffn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-12-10T22:07:55.000Z","updated_at":"2025-03-04T00:56:04.000Z","dependencies_parsed_at":"2024-12-11T04:19:08.280Z","dependency_job_id":"18aff79d-77ad-40d1-ab90-7eb6faf6146b","html_url":"https://github.com/duffn/libvmod-querymodifier","commit_stats":null,"previous_names":["duffn/libvmod-querymodifier"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duffn%2Flibvmod-querymodifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duffn%2Flibvmod-querymodifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duffn%2Flibvmod-querymodifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duffn%2Flibvmod-querymodifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duffn","download_url":"https://codeload.github.com/duffn/libvmod-querymodifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246326783,"owners_count":20759439,"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":["varnish","varnish-cache","vmod"],"created_at":"2024-12-11T20:11:51.409Z","updated_at":"2025-06-15T16:02:31.597Z","avatar_url":"https://github.com/duffn.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libvmod-querymodifier\n\nThis is a simple Varnish VMOD that allows modification of a URL's query parameters by including or excluding specified parameters and their values.\n\n## Status\n\nℹ️ This VMOD is currently exploratory and being actively developed and tested. It has not been run in any production environment yet,\nso you should not yet use this in a production environment. \n\nIf you need to manipulate querystrings in production, you should currently explore [`libvmod-queryfilter`](https://github.com/nytimes/libvmod-queryfilter/) or [`vmod-querystring`](https://git.sr.ht/~dridi/vmod-querystring).\n\nIf instead you just want to contribute to a friendly VMOD repository, continue on!\n\n## Usage\n\n### Inclusion\n\nList the parameters that you would like to have _remain_ in the URL. All other query parameters and their values will be removed.\n\n```\nimport querymodifier;\n\nset req.url = querymodifier.modifyparams(url=req.url, params=\"search,id\", exclude_params=false);\n# Or use the convenience function, `includeparams`.\nset req.url = querymodifier.includeparams(url=req.url, params=\"search,id\");\n\n# Original URL: example.com/?search=name\u0026ts=123456789\u0026id=987654321\n# Modified URL: example.com/?search=name\u0026id=987654321\n```\n\n### Exclusion\n\nList the parameters that you would like to have _removed_ from the URL. All other query parameters and their values will remain.\n\n```\nimport querymodifier;\n\nset req.url = querymodifier.modifyparams(url=req.url, params=\"ts,v\", exclude_params=true);\n# Or use the convenience function, `excludeparams`.\nset req.url = querymodifier.excludparams(url=req.url, params=\"ts,v\");\n\n# Original URL: example.com/?search=name\u0026ts=123456789\u0026v=123456789\u0026id=987654321\n# Modified URL: example.com/?search=name\u0026id=987654321\n```\n\n### Remove all valid query parameters\n\nRemove all query parameters by passing in an empty string.\n\n```\nimport querymodifier;\nset req.url = querymodifier.modifyparams(url=req.url, params=\"\", exclude_params=true);\n# Or use the convenience function, `excludeallparams`.\n# set req.url = querymodifier.excludeallparams(url=req.url);\n\n# Original URL: example.com/?search=name\u0026ts=123456789\u0026v=123456789\u0026id=987654321\n# Modified URL: example.com/\n```\n\n### Remove all query string\n\nRemove all  of the query string, i.e. everything after, and including the `?` regardless of if\nthe are valid `name=value` query string parameters.\n\n```\nimport querymodifier;\nset req.url = querymodifier.removeallquerystring(url=req.url);\n\n# Original URL: example.com/?123456\n# Modified URL: example.com/\n```\n\n### Additional\n\nSee the tests for more parameter edge cases.\n\n## Building\n\nThis module is primarily manually tested with Varnish 7.7, but also includes vtc tests for version 7.5 and 7.6.\n\n```\n./bootstrap\nmake\nmake check # optionally run tests, recommended.\nsudo make install\n```\n\n## Contributing\n\nFork, code, and PR! See build instructions above.\n\nI'm happy to review any PRs. Any bug reports are also welcome.\n\n### Debugging\n\n#### ASan\n\nThe module can also be built with [`AddressSanitizer`](https://github.com/google/sanitizers/wiki/AddressSanitizer) support.\n\nIt is recommended that when developing on the module, you build with `AddressSanitizer` support enabled in order to help identify any memory issues with the VMOD.\n\nIn order to build the module with this enabled, run the `bootstrap` script with `--enable-asan`. \n\n```\n./bootstrap --enable-asan\n```\n\nThere are also some scripts in the `debug` directory to assist. Navigate to the `debug` directory and run `docker compose up --build` in order to build the module with ASan support as well as with a backend `nginx` to field example requests.\n\n_Note_: Do not use the module built with ASan support in production. This is meant for development purposes only.\n\n#### gdb\n\n`gdb` is also included in the debug Dockerfile for your convenience.\n\n- After you've brought up Docker Compose, exec into the Varnish container.\n\n```bash\ndocker compose exec varnish\n```\n\n- Attach `gdb` to the Varnish child process. You can either get the PID with `ps` or Varnish will print the child PID to the console like `varnish-1  | Debug: Child (31) Started`.\n\n```bash\n(gdb) attach 31\n```\n\n- Set a breakpoint, for example on the `vmod_modifyparams` function. A `.gdbinit` file is included in the Docker container to instruct `gdb` where to find the VMOD shared libraries.\n\n```bash\n(gdb) b vmod_modifyparams\nBreakpoint 1 at 0xffff7e0b14cc: file vmod_querymodifier.c, line 219.\n```\n\n- Send a request to `http://localhost:8080` that exercises the VMOD.\n\n- Continue the debugger and then use `gdb` as you normally would.\n\n```bash\n(gdb) c\nContinuing.\n[Switching to Thread 0xffff855cf140 (LWP 372)]\n\nThread 101 \"cache-worker\" hit Breakpoint 1, vmod_modifyparams (ctx=0xffff855cd9b8, uri=0xffff79a3d8ac \"/?blah=1\u0026ts=1\", params_in=0xffff7e0e7610 \"ts,v,cacheFix,date\",\n    exclude_params=1) at vmod_querymodifier.c:219\n219         CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);\n```\n\n## Acknowledgements\n\n- The NY Times [`libvmod-queryfilter` VMOD](https://github.com/nytimes/libvmod-queryfilter/) for insipiration.\n- dridi [`vmod-querystring` VMOD](https://git.sr.ht/~dridi/vmod-querystring) for insipiration.\n- [`vcdk`](https://github.com/nigoroll/vcdk/) for the project structure.\n- Guillaume Quintard for the [VMOD tutorial](https://info.varnish-software.com/blog/creating-a-vmod-vmod-str).\n\n## License\n\n[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduffn%2Flibvmod-querymodifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduffn%2Flibvmod-querymodifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduffn%2Flibvmod-querymodifier/lists"}