Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 5768603836088320: Issue 1564-Fix FilterEngine::Matches for allowing request which is whitelisted in the ascendant node

Created:
Nov. 13, 2014, 12:58 p.m. by sergei
Modified:
Oct. 24, 2018, 9:55 a.m.
Reviewers:
Felix Dahlke, Oleksandr
Visibility:
Public.

Patch Set 1 #

Total comments: 6

Patch Set 2 : convert to UTF-8 #

Patch Set 3 : adjust comments #

Patch Set 4 : revert and change referrer map #

Patch Set 5 : rename BuildReferrerChain to BuildFrameStructure #

Total comments: 34

Patch Set 6 : fix according to comments and add some tests #

Total comments: 9

Patch Set 7 : fix according to comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+141 lines, -42 lines) Patch
M include/AdblockPlus/ReferrerMapping.h View 1 2 3 4 5 6 2 chunks +37 lines, -10 lines 0 comments Download
M src/ReferrerMapping.cpp View 1 2 3 4 5 6 2 chunks +25 lines, -11 lines 0 comments Download
M test/ReferrerMapping.cpp View 1 2 3 4 5 6 4 chunks +79 lines, -21 lines 0 comments Download

Messages

Total messages: 9
sergei
Nov. 13, 2014, 1:03 p.m. (2014-11-13 13:03:51 UTC) #1
Oleksandr
Assuming all types of requests should be transitive, this LGTM, with minor changes in comments. ...
Nov. 13, 2014, 1:32 p.m. (2014-11-13 13:32:18 UTC) #2
sergei
Thanks, comments are adjusted. Also I would ask whether it makes sense to comment that ...
Nov. 13, 2014, 1:58 p.m. (2014-11-13 13:58:13 UTC) #3
Wladimir Palant
No, the domain option isn't transitive. As noted in the issue, the problem actually lies ...
Nov. 13, 2014, 2:36 p.m. (2014-11-13 14:36:08 UTC) #4
sergei
Fix the building of frame structure.
Nov. 25, 2014, 12:41 p.m. (2014-11-25 12:41:52 UTC) #5
Wladimir Palant
http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/include/AdblockPlus/ReferrerMapping.h File include/AdblockPlus/ReferrerMapping.h (right): http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/include/AdblockPlus/ReferrerMapping.h#newcode71 include/AdblockPlus/ReferrerMapping.h:71: FilterEngine::ContentType type; It is unnecessary to store the actual ...
Nov. 25, 2014, 3:46 p.m. (2014-11-25 15:46:37 UTC) #6
sergei
http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/include/AdblockPlus/ReferrerMapping.h File include/AdblockPlus/ReferrerMapping.h (right): http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/include/AdblockPlus/ReferrerMapping.h#newcode71 include/AdblockPlus/ReferrerMapping.h:71: FilterEngine::ContentType type; On 2014/11/25 15:46:37, Wladimir Palant wrote: > ...
Nov. 26, 2014, 10:34 a.m. (2014-11-26 10:34:43 UTC) #7
Wladimir Palant
http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/src/ReferrerMapping.cpp File src/ReferrerMapping.cpp (right): http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/src/ReferrerMapping.cpp#newcode50 src/ReferrerMapping.cpp:50: return referrerChain; On 2014/11/26 10:34:43, sergei wrote: > Because ...
Dec. 9, 2014, 9:20 p.m. (2014-12-09 21:20:03 UTC) #8
sergei
Dec. 12, 2014, 5:07 p.m. (2014-12-12 17:07:07 UTC) #9
http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/src/...
File src/ReferrerMapping.cpp (right):

http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/src/...
src/ReferrerMapping.cpp:58: referrerChain.reserve(maxChainLength);
On 2014/12/09 21:20:03, Wladimir Palant wrote:
> On 2014/11/26 10:34:43, sergei wrote:
> > BTW, could you point to the reference where it's stated that `reserve`
rounds
> up
> > to the next power of two?
> 
> Any sane allocation approach does, to minimize memory fragmentation - but
that's
> an implementation detail of course, so it won't be mentioned in any
> documentation.

Actually on a lower level usual allocator rounds it to some granularity which
depends on the machine. But it's not the proper place to discuss it.

http://codereview.adblockplus.org/5768603836088320/diff/5738600293466112/src/...
src/ReferrerMapping.cpp:82: referrerChain.push_back(url);
On 2014/12/09 21:20:03, Wladimir Palant wrote:
> I just realized that this was designed to work differently from what I
expected
> :-( I thought that one would call this function with the URL of a request, but
> apparently it is supposed to be called with the URL of its referrer - and that
> referrer will always be listed in the frame structure. Given your changes
here,
> the current design seems wrong. What do you think?

I also misunderstood it the same way initially and there was even the issue
1160. So it's definitely a tricky point, feel free to suggest the fix of the
documentation or API.
Eventually, I actually came with the conclusion that it's done the correct way
because we should not and we don't have to modify ReferrerMapping to get the
frame structure for new request. It's very good from the design point of view.

What concerns the current design, let's consider the following example
Resource relation structure ;requestType; referrer
http://root-page/
 +http://some-frame/        ;subdocument; http://root-page/
   +http://flash/player.swf ;object     ; http://some-frame/
   | +http://cdn/img        ;image      ; http://flash/player.swf
   +http://some-frame/script;script     ; http://some-frame/

For the call matches(url: "http://some-frame/", subdocument, referrer:
"http://root-page/") or matches(url: "http://some-frame/script", script,
referrer: "http://some-frame/") we should build the frame structure based on
"http://root-page/" or "http://some-frame/" respectively and it seems we need
*always* include it into the frame structure. But for the call matches(url:
"http://cdn/img", image, referrer: "http://flash/player.swf") we should not
include "http://flash/player.swf" into the frame structure, the frame structure
is "http://root-page/" -> "http://some-frame/".
So, yes, it's wrong and the aim of this fix is to adjust it.

http://codereview.adblockplus.org/5768603836088320/diff/5743114304094208/incl...
File include/AdblockPlus/ReferrerMapping.h (right):

http://codereview.adblockplus.org/5768603836088320/diff/5743114304094208/incl...
include/AdblockPlus/ReferrerMapping.h:46: FRAME_INDICATOR_NOT_A_FRAME = 0,
FRAME_INDICATOR_FRAME= 1
On 2014/12/09 21:20:03, Wladimir Palant wrote:
> Extreme nit: articles seem wrong in constant names, FRAME_INDICATOR_NOT_FRAME?

I know, I thought about it but don't remember the reason I decided to add the
article.
fixed

http://codereview.adblockplus.org/5768603836088320/diff/5743114304094208/incl...
include/AdblockPlus/ReferrerMapping.h:77: FrameIndicator frameIndicatorArg =
FrameIndicator::FRAME_INDICATOR_NOT_A_FRAME)
On 2014/12/09 21:20:03, Wladimir Palant wrote:
> Shouldn't you have that default value in method Add() rather than here? Add()
is
> being called by all kind of code, this constructor on the other hand is for
> internal use only and never called without the second parameter.
> 
> Also, I'm pretty sure that the default should be FRAME_INDICATOR_FRAME -
that's
> what we have to assume for referrers if we don't have any further information.

These default arguments are required by std::map, in particular if
`ReferrerMapping::mapping` does not contain `url` then the statement
`mapping[url] = RequestInfo(referrer, isFrame);` firstly creates `RequestInfo`
using default ctr and then calls `RequestInfo::operator=`. It's a question
whether we want `mapping[url] = ...` and internal class with default ctr or a
little bit more of additional logic but without default ctr.

What concerns Add(), that's exactly because it is called by all kind of code
it's difficult to assume what should be the default there and even more, do we
really need something default there?

http://codereview.adblockplus.org/5768603836088320/diff/5743114304094208/src/...
File src/ReferrerMapping.cpp (right):

http://codereview.adblockplus.org/5768603836088320/diff/5743114304094208/src/...
src/ReferrerMapping.cpp:71: }
On 2014/12/09 21:20:03, Wladimir Palant wrote:
> Can't we check prevEntry after the loop instead of duplicating its content?
> Something along these lines:
> 
>   auto currentEntry = mapping.find(url);
>   auto prevEntry = mapping.end();
>   for (...)
>   {
>     ...
>   }
>   if (prevEntry == mapping.end())
>   {
>     // No data, just assume that the url is a frame.
>     frames.push_back(url);
>   }
>   else if (!prevEntry->second.referrer.empty())
>   {
>     ...
>   }

That does work, please check the updated version. Although I would say that the
complexity of the algorithm is higher despite the amount of code is less and
there is no repeating.

Powered by Google App Engine
This is Rietveld