Better HN
topnewbestaskshowjobs
Log inSign up

onchance

22 karma · joined Dec 8, 2016 (9y ago) · 3 submissions

Submissions

comment 9y ago · link · parent

But the “fixed” monthly cost varies depending on the size of your credit line, so there is an effective interest rate of 5% or more.

https://d2ue93q3u507c2.cloudfront.net/assets/robinhood/legal...

comment 9y ago · link · parent

The lab behind this invention is led by Manu Prakash, a MacArthur Fellow [1] with a knack for unconventional solutions. He's the same guy who developed Foldscope, an ultra low cost microscope [2][3].

[1]: https://www.macfound.org/fellows/965/

[2]: https://en.wikipedia.org/wiki/Foldscope

[3]: https://www.ted.com/talks/manu_prakash_a_50_cent_microscope_...

comment 9y ago · link · parent

Would sanitizing for double underscores be enough to capture the most dangerous cases?

    import re
    
    def sanitize(user_input):
        """Sanitize user input for str.format
        
        Usage:
            sanitize("{post.title} - {post.blog.title}")
            sanitize("{post.title}: Another fine post by "{post.author}")
            sanitize("~~~ xXx {post.blog.__init__.dbconnection.__keys__.password} xXx ~~~")
        
        """
        return re.sub(r'{[^}]*__[^}]*}', '', user_input)
Even better, we could specify which variables to allow in user input:

    import re
    
    def sanitize(user_input, *allowed_variables):
        """Sanitize user input for str.format
        
        Usage:
            allowed_variables = ["post.blog.title", "post.title", "post.author"]
            sanitize("{post.title} - {post.blog.title}", *allowed_variables)
            sanitize("{post.title}: Another fine post by "{post.author}", *allowed_variables)
            sanitize("~~~ xXx {post.blog.__init__.dbconnection.__keys__.password} xXx ~~~", *allowed_variables)
        
        """
        for match in re.finditer(r'{([^}]*)}', user_input):
            if match[1] not in allowed_variables:
                user_input = user_input.replace(match[0], '')
        return user_input