chusopr / casimir

Yet Another URL Shortener
http://casim.ir/
MIT License
18 stars 11 forks source link

API breaks when reCaptcha enabled. #19

Closed benjaminarthurt closed 9 years ago

benjaminarthurt commented 9 years ago

API breaks when reCaptcha enabled. returning "Error: Input provided by user is not valid". Perhaps this could be fixed by having an API key config option that allows reCaptcha to be bypassed when using the API.

chusopr commented 9 years ago

I know this happens. We can say that this is by design: allowing API requests bypassing CAPTCHA will make CAPTCHA useless. I see no simple solution.

benjaminarthurt commented 9 years ago

What about implementing a private key pair that is stored in the config file, when an API request comes in both values are checked against the config values, so if the request used the API url, and contains a valid key pair the captcha is bypassed, allowing for a secure front end form (still using captcha) and a secure API. The two don't need to be mutually exclusive. If I have some time in the coming days I'll fork and see if I can contribute something in this direction.

benjaminarthurt commented 9 years ago

https://github.com/benjaminarthurt/casimir I forked and fixed. A little hacky but functional.

edited: api.php, inc/Casimir.php, casimir-conf.php.example

only a few additional lines required and maintains functionality of both a public form with recaptcha and a private API with private key.

when API_KEY is defined as something other than '' API requests will fail if they don't contain the proper key with message: "Unauthorized: Invalid API Key"

requests containing the correct key such as: http://l.copy.mx/api.php?long=http://bentownsend.com&format=text&key=1234567891346792589764318520102030405060708099876543210 will complete without issue.

Requests through the form complete normally always

Feel free to take a look at my changes, I can submit a pull request if you like.

chusopr commented 9 years ago

Thanks, I will review it tomorrow. Can you send a pull request?

benjaminarthurt commented 9 years ago

Done: https://github.com/chusopr/casimir/pull/20 Thanks!

chusopr commented 9 years ago

Fixed after merging #20.

benjaminarthurt commented 9 years ago

looks great, thanks. This helps fix an issue over on Stikked... https://github.com/claudehohl/Stikked/issues/236