Skip to content

Add Expiring Token to Endpoint #41

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

Closed
wants to merge 15 commits into from

Conversation

Image for: Conversation
Copy link

Add a rolling token to the webmention endpoint.

A new token is generated every twelve hours, the current and previous two tokens are valid at any one time.

Native WP nonces are out as they include the session and user IDs.

Fixes #39

Peter Wilson and others added 12 commits December 5, 2014 11:09
Works like a banking fob. Three codes work:
* current
* previous
* next (this may be overreach)

The code regenerates every twelve hours. Allowing for three codes ensures that brid.gy still works as it caches for 24 hours.
This allows breaking out of the checking look to occur earlier
- never use future time, that's dumb
- allow previous two to be valid
- use logged out uid and token
- name the action

This more closely emulates how the WP nonce works.
Copy link
Owner

Hey @peterwilsoncc thanks for the changes and sorry for the late response (I am a bit busy at the moment)

I had a look at your code and was curious if it is also possible to add the feature with native nonces? http://codex.wordpress.org/WordPress_Nonces


// plain text header
header('Content-Type: text/plain; charset=' . get_option('blog_charset'));

// fail if invalide endpoint
if ( false == $is_valid ) {
status_header(400);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 403 would probably be better here, http://httpstatus.es/403, as the server understands the request, but refuses to handle it.

A 400 is more of a generic error where the server don't really understand what the client actually wanted to do: http://httpstatus.es/400

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense! 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y, update will be pushed shortly.

Copy link

voxpelli commented Feb 3, 2015

All in all: I'm a bit concerned with how a client should be able to know when an endpoint will become invalid. Imaging a big social network implementing WebMentions – you don't want them to fetch a post before every new mention of that post.

But how often should it fetch a post? Should it keep going with an endpoint until it receives a 403 and then fetch again? Should there be a cache-header set to the length of time of the token life so the client can check for that to know how long to cache the site? If the cache is set to longer than the token life, can't that make it hard for a well-behaved client to actually receive a new token? So would this effectively make it so that no blog post can be cached for longer than $time_block = 12 * HOUR_IN_SECONDS; x 3?

I guess this is more of an IndieWeb / WebMention question than a PR question but still feel it kinds of needs to be addressed.

Copy link

voxpelli commented Feb 3, 2015

Thinking about this some more: I would advise against including this as a default in a plugin like this for now – I'm not sure this route is the best way to go down to prevent DDoS attacks and it adds a lot of possibly complexity on the client side when it comes to caching etc which is not in favor of WebMention adoption etc at the moment in my opinion.

What I do however think is that it should be easy to dogfeed a mechanism like this so that it can easily be tried out.

So I would suggest adding a filter for the value of the ?webmention= query param so that another plugin can add a nonce in there rather than having it be the default endpoint, as suggested by this PR, and then add an action/filter (don't remember which is the most appropriate, was a while since I was an active WP plugin writer) in the beginning of parse_query() so that the same plugin could validate that the defined nonce was correct.

Would such a solution work for everyone? I hope I'm not sounding too harsh stumbling in here from nowhere with lots of opinions over a month after the PR was sent in.

Copy link
Author

Finally have a chance to reply to these.

Brid.gy caches end points for up to 24 hours so I am I'm using custom nonces to ensure they expire between 24 & 36 hours, current & two previous ticks. Native nonces expire between 12 & 24 hours and use session data.

Line comments I'll answer inline.

P

Copy link
Contributor

aaronpk commented Apr 19, 2015

fwiw I just removed this functionality from my own webmention endpoint, as I wasn't seeing any immediate benefit. I think there are likely other better solutions to (D)DOS attacks, and this just feels like an unnecessary complication.

Copy link
Author

I did the same when re-launching recently, for much the same reason.

I'll close this off: conflicts and needs a rethink.

Copy link
Owner

BTW: I changed some hooks and added new ones, to enable these kinds of security features as third party plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants