webrecorder / wombat

Wombat.js client-side rewriting library
GNU Affero General Public License v3.0
81 stars 31 forks source link

Provide an API for modifying URL rewriting #47

Open robertknight opened 3 years ago

robertknight commented 3 years ago

For Hypothesis's proxy service we are looking to ensure that all requests to the proxy from a browser are either top-level page fetches or requests from a proxied page. In other words, we want to prevent direct requests of subresources (scripts etc.) from outside of proxied pages.

One approach we are looking at is modifying the URL rewriting process so that subresource URLs on proxied pages include a token of some kind. For this purpose it would be useful to be able to hook into client-side URL rewriting (ie. the rewriteUrl method) and modify the generated URLs.

Although it is possible to do this with the current version of Wombat via monkey-patching it would be preferable to have a documented, public API for this. I'd be happy to help with implementation/testing, but I could use some direction on how the process of configuring Wombat to use this middleware could work.

mgautierfr commented 8 months ago

FYI, PR https://github.com/webrecorder/wombat/pull/128 allow you to provide a custom rewrite_function in the configuration. (You still have "reverse rewritting" https://github.com/webrecorder/wombat/blob/main/src/wombat.js#L942 running so your rewrite_function must be "compatible" with it)