Skip to content
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

AccessChecker: exact-match rules not found in single-line ACLJ file, fixes #628 #629

Merged

Conversation

sebastian-nagel
Copy link
Contributor

Motivation and Context

This PR addresses #628.

Description

Problem Analysis

The key used to search for a ACL rule is the SURT URL followed by ###, e.g.

org,iana)/path/###

The exact-match rule in the ACLJ file consists of the SURT URL followed by ###, a white space, the timestamp and the JSON data:

org,iana)/path### - {"access": "allow", "url": "http://www.iana.org/path/"}

Because the rule line sorts before (in reverse alphabetical order) the search key, the "search cursor" is then positioned just after the rule line and not before it. Although AccessChecker requests one additional line (prev_size=1) before the search position line 41, this has no effect in a single-line file because we reach EOF just after this line, see binsearch.py, line 78. Consequently, AccessChecker cannot match the single rule in the ACLJ file.

Proposed Solution

As a solution we could extend the search key suffix by one more number sign # (U+0023). The search key then compares properly to the key followed by a white space character (U+0020) in the rule file.

Note: Afaics, the above solution would allow to search with prev_size=0.

Proof of sort order using the Unix sort command:

LC_ALL=C sort -r <<HERE
# rules.aclj:
org,iana)/path/### - {...}
org,iana)/path/ - {...}
# search key equal to SURT key in rule file:
org,iana)/path/###
# search key which sorts/compares properly:
org,iana)/path/####
HERE

The "new" search key sorts before the exact match rule (and also before any prefix rules):

org,iana)/path/####
org,iana)/path/### - {...}
org,iana)/path/###
org,iana)/path/ - {...}
# search key which sorts/compares properly:
# search key equal to SURT key in rule file:
# rules.aclj:

Types of changes

  • Replay fix (fixes a replay specific issue)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added or updated tests to cover my changes.
  • All new and existing tests passed.

@ikreymer
Copy link
Member

That's a clever workaround, thanks for adding a test also!

@ikreymer ikreymer merged commit ca14bdd into webrecorder:master Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants