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

Parsoid: Rate limit stashing requests #1140

Merged
merged 1 commit into from
May 23, 2019

Conversation

d00rman
Copy link
Contributor

@d00rman d00rman commented May 23, 2019

Stashing requests are expensive and take up storage, so make sure they are rate-limited. We check the rates only for external requests that explicitly request stashing. By default, at most 5 requests per second per client IP are allowed, but that can be adjusted by setting the stash_ratelimit in the module's configuration options.

Bug: T224055

sys/parsoid.js Outdated
@@ -125,6 +122,51 @@ class ParsoidService {
};
}

_initOpts(opts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use a default parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

sys/parsoid.js Outdated
if (!((req.query && req.query.stash) || (req.body && req.body.stash))) {
return;
}
if (hyper._rootReq.headers['x-stash-rate-checked']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this? I don't think it would be called recursively and if it does, it's an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are cases where parsoid calls itself via the URI, such as

const path = [rp.domain, 'sys', 'parsoid', 'transform', from, 'to', to];
(there are others too), so this ensures the rate is checked only once.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes and no. Actually that particular line you have shown is not calling itself, it's actually constructing an artificial request for code sharing. I wanna refactor it out. The only other case is calling the pagebundle endpoint, which I wanna get rid of too. So this is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you are correct. Ok, removing.

sys/parsoid.js Outdated
}
hyper._rootReq.headers['x-stash-rate-checked'] = true;
const key = `${hyper.config.service_name}.parsoid_stash.${req.params.domain}.` +
`${req.params.title || 'Transform'}.${req.params.revision || 0}|` +
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm... do we really wanna include title/revision in a key? This doesn't really limit anything, a malicious client can just iterate over all revisions of all pages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will remove.

@Pchelolo
Copy link
Contributor

2 comments inlined. Plus need to update the docs.

Stashing requests are expensive and take up storage, so make sure they
are rate-limited. We check the rates only for external requests that
explicitly request stashing. By default, at most 5 requests per second
per client IP are allowed, but that can be adjusted by setting the
`stash_ratelimit` in the module's configuration options.

Bug: T224055
@d00rman
Copy link
Contributor Author

d00rman commented May 23, 2019

Ok, @Pchelolo addressed all the comments and added the rate limits to the spec docs.

@Pchelolo
Copy link
Contributor

Waiting gor travis

@Pchelolo Pchelolo merged commit fdf90a2 into wikimedia:master May 23, 2019
@d00rman d00rman deleted the parsoid/stash-ratelimit branch May 23, 2019 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants