Skip to content

Limit page size to prevent integer overflow #1386

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

Merged
merged 1 commit into from
Dec 30, 2022

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Dec 30, 2022

The $param is typed int. So if the routing param does not fit into an int, PHP will throw a TypeError. This in turn would trigger an 500 internal server error. So by requesting a too big page, e.g. /de/blog/page/147483647147483647147483647, one can trigger internal errors which should not be possible.

I don't think there is an easy solution to this general problem that Symfony could automatically provide. So the best solution seems to be to limit the size of the routing placeholder. With this limit the page will always fit into an int even on a 32-bit platform.

@javiereguiluz
Copy link
Member

It looks like an edge-case, but let's fix it because this Demo application is studied and used by many. Thanks Tobias!

@javiereguiluz javiereguiluz merged commit 1391d41 into symfony:main Dec 30, 2022
@Tobion Tobion deleted the fix-int-overflow branch December 30, 2022 12:18
@@ -46,7 +46,7 @@ class BlogController extends AbstractController
*/
#[Route('/', defaults: ['page' => '1', '_format' => 'html'], methods: ['GET'], name: 'blog_index')]
#[Route('/rss.xml', defaults: ['page' => '1', '_format' => 'xml'], methods: ['GET'], name: 'blog_rss')]
#[Route('/page/{page<[1-9]\d*>}', defaults: ['_format' => 'html'], methods: ['GET'], name: 'blog_index_paginated')]
#[Route('/page/{page<[1-9]\d{0,8}>}', defaults: ['_format' => 'html'], methods: ['GET'], name: 'blog_index_paginated')]
Copy link

@bendavies bendavies Mar 1, 2023

Choose a reason for hiding this comment

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

max int on 32 bit is 2147483647 (length 10), so {0,10} ?

Choose a reason for hiding this comment

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

sorry {0,9}?

Choose a reason for hiding this comment

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

i guess {0,9} would still allow an int overflow

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

Successfully merging this pull request may close these issues.

3 participants