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

319 - Restrict Submitters From Accessing Things They Don't Own #323

Merged
merged 13 commits into from
Feb 15, 2024

Conversation

Janell-Huyck
Copy link
Contributor

@Janell-Huyck Janell-Huyck commented Dec 8, 2023

Fixes #319

Restricts submitters from viewing or accessing publications or submitter profiles that they did not create.

Core Changes

  • Creates a new "concern" RestrictSubmitterAccess that checks if a submitter is the creator of a publication (or the submitter profile), and returns a 404 error if they are not.
  • Updates tests to apply the concern for publication types and submitter profiles.

Additional Changes:

Correct HTTP status of failed creation and update of colleges and submitters to be status: :unprocessable_entity

resource = FactoryBot.create(model_name_underscored.to_sym)
configure_user_session(user_role, resource)
params = params_for(action, resource)
public_send(method, action, params:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change allows us to specify the individual publication or submitter profile that we are trying to log in as owners of. It's calling helper functions located in spec/support/helpers/access_authorization.rb to correctly set up the session variables and request parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

helper function used to set the session[:submitter_id] to the id of the resource sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes allow us to set the params for a specific resource rather than just a generically created one. This is needed because of the newly created restrictions where submitters can only change their own work.

@Janell-Huyck Janell-Huyck changed the title WIP - 319 - Restrict Submitters From Accessing Things They Don't Own 319 - Restrict Submitters From Accessing Things They Don't Own Dec 13, 2023
@hortongn
Copy link
Member

@Janell-Huyck Just to make sure I understand this change correctly, AAEC currently allows any submitter to visit something like http://localhost:3000/artworks/3 and view/edit a publication another submitter added. The same is true for viewing/editing another person's submitter record.

Your change blocks access if the current submitter is not the person who created those records, correct? I've verified the bug and verified your change fixes it, but is there anything else this change does that I should verify?

@hortongn
Copy link
Member

@Janell-Huyck Just to make sure I understand this change correctly, AAEC currently allows any submitter to visit something like http://localhost:3000/artworks/3 and view/edit a publication another submitter added. The same is true for viewing/editing another person's submitter record.

Your change blocks access if the current submitter is not the person who created those records, correct? I've verified the bug and verified your change fixes it, but is there anything else this change does that I should verify?

Oh I see you're also restricting submitter access for certain actions. This all seems to work correctly, but I'd like to talk through some of the code with you on Monday. Easier to chat about than having a conversation in comments.

Copy link
Member

@hortongn hortongn left a comment

Choose a reason for hiding this comment

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

@Janell-Huyck See my refactoring suggestions inline

@resource && (session[:submitter_id].to_s == @resource.submitter_id.to_s)
end

def unauthorized_access
Copy link
Member

Choose a reason for hiding this comment

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

Suggest making the name an action such as raise_unauthorized_access

controller_name.classify.constantize
end

def authorized_submitter?
Copy link
Member

Choose a reason for hiding this comment

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

Suggest a more descriptive name at will help devs know why a submitter is authorized. E.g. current_submitter_is_creator?

return
end

set_resource
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can call set_resource from within authorized_submitter? since that's the only place making use of @resource. Might not even need a separate method for it.

%w[errors pages].include? controller_name
end

def handle_submitter_special_case
Copy link
Member

Choose a reason for hiding this comment

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

"special_case" is vague. Seems like this method should just return true if submitter_logged_in?. Move the call to unauthorized access outside of this method.

unauthorized_access unless authorized_submitter?
end

def non_submitter_controller?
Copy link
Member

Choose a reason for hiding this comment

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

Avoid "non" because negatives are hard to follow mentally.

@Janell-Huyck Janell-Huyck force-pushed the security-319-restrict-submitter-to-own-items branch from 9dec236 to 55eb408 Compare January 30, 2024 20:31
@Janell-Huyck Janell-Huyck changed the title 319 - Restrict Submitters From Accessing Things They Don't Own WIP - 319 - Restrict Submitters From Accessing Things They Don't Own Jan 30, 2024
@Janell-Huyck Janell-Huyck changed the title WIP - 319 - Restrict Submitters From Accessing Things They Don't Own 319 - Restrict Submitters From Accessing Things They Don't Own Jan 31, 2024
Copy link
Member

@hortongn hortongn left a comment

Choose a reason for hiding this comment

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

@Janell-Huyck You call user_is_admin? but that method isn't defined.

Screenshot 2024-02-04 at 1 25 36 PM

@Janell-Huyck
Copy link
Contributor Author

@Janell-Huyck You call user_is_admin? but that method isn't defined.
It looks like I misplaced a few helper methods I created. I put them in a spec folder by accident. 🙀 Also looks like my tests weren't complete enough to catch that mistake. Fixing! 🛠️

@Janell-Huyck Janell-Huyck force-pushed the security-319-restrict-submitter-to-own-items branch from 5d14e45 to 5d04947 Compare February 12, 2024 22:13
@Janell-Huyck Janell-Huyck force-pushed the security-319-restrict-submitter-to-own-items branch from 5d04947 to c2790b1 Compare February 13, 2024 18:21
@Janell-Huyck
Copy link
Contributor Author

We had a flaky feature test. I've added in a line that makes the test wait for a page to load, and I expect this to clear up the problem.

Copy link
Member

@hortongn hortongn left a comment

Choose a reason for hiding this comment

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

@Janell-Huyck Looks great. Thanks for all the work you put into this. merging

@hortongn hortongn merged commit 905d988 into qa Feb 15, 2024
2 checks passed
@hortongn hortongn deleted the security-319-restrict-submitter-to-own-items branch February 15, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Security: Restrict submitter access to their own items
2 participants