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

Use CSRF token on forms to trigger a new builds #3260

Merged
merged 3 commits into from
Nov 15, 2017

Conversation

humitos
Copy link
Member

@humitos humitos commented Nov 14, 2017

Avoid "This endpoint is deprecated" raised when hitting and old
endpoint with security issues.

Now, each view that shows a form with the "Build" button uses the
BuildTriggerMixin to handle the POST request and trigger the new build.

Closes #3253

Avoid "This endpoint is deprecated" raised when hitting and old
endpoint with security issues.

Now, each view that shows a form with the "Build" button uses the
BuildTriggerMixin to handle the POST request and trigger the new build.

Closes #3253
Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

Looks good! I noted a queryset that will need to change first, but otherwise this seems to be what we need.

class BuildTriggerMixin(object):
def post(self, request, project_slug):
project = get_object_or_404(
Project.objects.protected(self.request.user),
Copy link
Contributor

Choose a reason for hiding this comment

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

These queryset methods are not documented at all, which we should probably fix, but protected is not the method we want here. This queryset will return projects with the public or protected privacy state, adding projects the user can view, from Project.objects._add_user_repos.

Instead, this should probably be Project.objects.for_admin_user(self.request.user), as we only want to surface the form posting ability for users that are authenticated and own the project.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I use the same than in BuildBase.

If I use for_admin_user, who will be able to trigger the builds? Just the owner?

If that's the case, we will need to remove/hide the Build button if the user doesn't own the project, right?

@@ -33,7 +34,24 @@ def get_queryset(self):
return queryset


class BuildList(BuildBase, ListView):
class BuildTriggerMixin(object):
def post(self, request, project_slug):
Copy link
Member

@safwanrahman safwanrahman Nov 14, 2017

Choose a reason for hiding this comment

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

This should not be only for logged in user?

Copy link
Member

Choose a reason for hiding this comment

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

login_required decorator can be used here

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, we do need to check for a proper request.user here.

Copy link
Member Author

Choose a reason for hiding this comment

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

we do need to check for a proper request.user here

what do you mean with this?

The user must be logged in to trigger a build.
@agjohnson agjohnson merged commit 4de678e into master Nov 15, 2017
@agjohnson agjohnson deleted the humitos/build/trigger-no-api branch November 15, 2017 20:30
@humitos humitos mentioned this pull request Nov 29, 2017
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