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

Stricter route parsing (+ CODEOWNERS update) #63

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

vdye
Copy link
Collaborator

@vdye vdye commented Nov 22, 2023

This pull request adds stricter validation around user-provided routes to repositories and bundles to avoid arbitrary relative path injection (e.g., a bundle route like "../../../").

Also, update the CODEOWNERS to a group instead of a list of individuals.

vdye added 2 commits November 22, 2023 11:09
Update the required approver to the "Hubbers" group, rather than a list of
individuals, to make the repository more resilient to ownership & role
changes.

Signed-off-by: Victoria Dye <[email protected]>
Move the route parsing done in 'bundle-server.go' to a new method
'core.ParseRoute'. In addition to the removal of excess path separators the
method already does, limit the characters in each segment of the route
(owner, repo, filename) to alphanumeric characters plus '-', '_', and '.'.
Also, explicitly block '.' and '..' path components. These measures are
added to prevent serving content from arbitrary relative paths in the bundle
server. If less stringent path validation is desired in the future, the
route parsing can be updated accordingly.

Update all functions that use a user-supplied route
('bundleWebServer.serve', 'repoProvider.CreateRepository',
'repoProvider.RemoveRoute') to use the new parsing function.

Signed-off-by: Victoria Dye <[email protected]>
@vdye vdye self-assigned this Nov 22, 2023
@vdye vdye marked this pull request as ready for review November 22, 2023 19:19
Copy link

@dscho dscho left a comment

Choose a reason for hiding this comment

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

Great work!


func ParseRoute(route string, repoOnly bool) (string, string, string, error) {
elements := strings.FieldsFunc(route, func(char rune) bool { return char == '/' })
validElementPattern := regexp.MustCompile(`^[\w\.-]+$`)
Copy link

Choose a reason for hiding this comment

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

I've verified by looking at https://github.com/google/re2/wiki/Syntax that \w is equivalent to [A-Za-z0-9_], i.e. it includes the underscore. Good.

@vdye vdye merged commit 880e776 into git-ecosystem:main Nov 22, 2023
@vdye vdye deleted the vdye/stricter-route-parsing branch November 22, 2023 19:43
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.

2 participants