Conversation
… web api function to enforce it
- Add SshKey model with validation and fingerprinting - Implement UnixGroupManager service for user/group management - Create Unix users/groups automatically on course/staff creation - Add SSH key provisioning to authorized_keys - Implement FilesystemEnforcer with group-based permissions - Add SSH key management UI (restricted to staff/instructors) - Fix require paths for services in controllers - Add services directory to autoload paths - Create bootstrap script for existing courses - Add host system user setup scripts - Support BusyBox useradd (use -p '*' instead of --disabled-password) - Add comprehensive setup and testing scripts
| file.write(input_file.read) | ||
| end | ||
| dest = absolute_path.join(input_file.original_filename) | ||
| File.open(dest, 'wb') { |f| f.write(input_file.read) } |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
General approach: ensure that all paths and filenames derived from user input are (a) constrained to live under BASE_DIRECTORY, and (b) sanitized so they cannot contain directory separators, excessive dots, or other dangerous characters. We will treat params[:path] as a logical path within BASE_DIRECTORY, normalize and validate it before calling safe_expand_path, and we will sanitize both params[:name] and input_file.original_filename before using them to create folders or files. This addresses both variants CodeQL reported.
Concrete fix in this file:
- Add two helper methods in the private section:
sanitize_rel_path(path)which:- Forces the path into a relative, normalized form using
Pathname#cleanpath. - Rejects any path that is absolute or that contains
".."segments.
- Forces the path into a relative, normalized form using
sanitize_filename(name)which:- Uses a simple whitelist regex to restrict filenames to alphanumerics, underscore, dash, dot, and space.
- Optionally collapses or strips leading dots and prevents blank results.
- Use
sanitize_rel_pathinsafe_expand_pathso thatpathfrom user input is cleaned before joining withBASE_DIRECTORY. If sanitization fails, raiseActionController::RoutingError, 'Not Found'orArgumentError. - Use
sanitize_filenamefor:params[:name]when creating a directory (dir = "#{absolute_path}/#{params[:name]}").input_file.original_filenamewhen calculating the destination file (dest = absolute_path.join(input_file.original_filename)).
Keep using the sanitized versions consistently for both existence checks and path creation, so the behavior (duplicate checking, etc.) is preserved but now based on safe names.
We only touch app/controllers/file_manager_controller.rb within the provided snippets, adding the helper methods in the private section and updating a few lines in upload_file and safe_expand_path. No new external gem is necessary; we can rely on Ruby’s Pathname and simple regexes.
60c2994 to
4367517
Compare
This PR provides a way to map the current files and folders in Autolab to a specified user group associated with the instructor's email. This PR also allows users to provide SSH keys so that they can SSH to the server hosting Autolab.
Instructors should not be able to see courses that they do not manage, but they should be able to access and view courses that they do manage.
How Has This Been Tested?
Login to the gamma instance and create a course. Upload your ssh key by clicking your profile, then your account and then manage ssh keys. SSH to the instance and check that you can only access your course and not other courses.
Types of changes
Checklist:
overcommit --install && overcommit --signto use pre-commit hook for linting