-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax for removing elements from JSON responses #1447
Comments
@ameshkov How about this for a rule spec:
|
@ameshkov For the JS side of things, there are at least two possibilities:
|
I think that we should provide a full list of supported functions, if it is possible. For example, we definitely will not support |
@sfionov I didn't want to commit to a specific list until we have the JavaScript implementation. Also, we might remove something during further testing :) By the way, |
Here's what bothers me about We need to find a query language that is:
Note that on the extension side most likely we'll need to run this code in the content script (i.e. hook JSON.parse) and the code size & performance is really important there. Maybe instead of that we may agree on a limited subset of syntax and implement it ourselves in JS? Here's what we need:
|
This native JS implementation is 33K minified:
|
This is still a lot. We may use it as a "base" implementation, but to strip it we need to figure out what subset is okay. |
JMESPath is 18K minified: https://github.com/jmespath/jmespath.js/blob/master/artifacts/jmespath.min.js Probably still too fat :) |
Btw, it looks like WebAssembly should be allowed in manifest v3 extensions: https://bugs.chromium.org/p/chromium/issues/detail?id=1173354#c60 |
@ameshkov I've been thinking: if we really want an extremely small implementation, then isn't it gonna be simpler to just extend the existing I presume, we'll still want to implement the same functionality as a native CoreLibs rule? If yes, then how about extending the
or even a conditional that itself accepts a path expression (this one will be a pain to parse):
This should solve the two issues from AdguardTeam/Scriptlets#183 and shouldn't be too hard to implement in both the scriptlet and CoreLibs. The problem I see with this solution is that we'll most probably want more and more features down the line, which will be increasingly more difficult to implement. While with |
This is also a solution, but in this case we'll need to provide a web-based debug tool. In theory, this is doable. The cons:
What if we use a subset of JSONPath instead, strip it of unnecessary functions and extend it if needed with necessary functions (has-key, value-equals, etc)? Here's the original JSONPath implementation in Javascript (taken from here: https://code.google.com/archive/p/jsonpath/)
Here's an example of using it: |
@ameshkov How about this for a rule spec:
|
Looks good. One more thing to add to Notes is a link to a web app to debug JSONPath expressions. Just mention that it does not support our custom functions. |
I actually don't think we need this limitation for |
Well, we do have it for |
$replace is much more powerful though, |
Hypothetically, a malicius filter could remove some kind of hash/signature/checksum and then the client would not check it, and could potentially load and execute a malicius resource. Seems far fetched, ofc, but one can not be too careful. |
It's just not consistent with the scriptlets, |
We often face issues when we need to modify JSON strings. Usually, we use $replace for that, but it is FAR from ideal.
What we really need is a new modifier similar to
$replace
that will work with JSON's specifically.Now, the question is what syntax should we use that can be understood and can be tested/debugged as easy as a regular expression.
I suggest using
jq
syntax for that: https://stedolan.github.io/jq/Here's why:
jq
is written in C under a permissive license and we can use it as a library: https://github.com/stedolan/jq/blob/master/COPYINGjq
can be used in conjunction withcurl
to test the jq expressions: https://stedolan.github.io/jq/tutorial/jq
expressions can also be tested online: https://jqplay.org/@sfionov @sxgunchenko any ideas on what syntax of this modifier could be?
@AdguardTeam/filters-maintainers what do you think about this idea?
edit: relevant: AdguardTeam/Scriptlets#183 (comment)
Maybe using jq is not that sane, we'd better find something that has implementations in both JS and C/C++
The text was updated successfully, but these errors were encountered: