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

contains_similar method #10

Open
seisvelas opened this issue Feb 26, 2021 · 1 comment
Open

contains_similar method #10

seisvelas opened this issue Feb 26, 2021 · 1 comment

Comments

@seisvelas
Copy link
Contributor

It would be interesting to have a method "contains_similar". That would also catch something like f1owcrypt-security.com

Originally posted by @tomholub in https://github.com/FlowCrypt/flowcrypt-backend/pull/290#discussion_r582715348

@seisvelas
Copy link
Contributor Author

seisvelas commented Feb 26, 2021

Something like:

def contains_similar(domain1, domain2):
    small = min(domain1, domain2, key=len)
    big = max(domain1, domain2, key=len)

    for i in range(0, len(big) - len(small)):
        if looks_similar(small, big[i:i+len(small)]):
            return True

    return False

# Use like this
contains_similar('flowcrypt-security', 'f1owcrypt') == True

Haven't tried it out, just threw that together here in this comment (so probably glaring errors all over the place). I'll look at it more tomorrow.

Note - the for loop here increments the exponent of the time complexity. I'll perform some metrics to see how slow this is on big strings to see if it's realistic for running in production (don't want to harden our homograph defense only to open up an even more severe DoS vector)

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

No branches or pull requests

1 participant