-
Notifications
You must be signed in to change notification settings - Fork 60
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
Upload files using Rest #4300
Upload files using Rest #4300
Conversation
@@ -34,6 +35,7 @@ public class TestResultUpload extends AuditedEntity { | |||
|
|||
@ManyToOne(optional = false, fetch = FetchType.LAZY) | |||
@JoinColumn(name = "org_id") | |||
@JsonIgnore | |||
private Organization organization; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Json Ignoring this since we don't want to return it as part of the response object when uploading results
ff73873
to
4c7842c
Compare
|
||
/** An error thrown when CSV uploads fail for reasons other than validation */ | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since allows us to set the response status to 400 when we throw this error inside the upload controller
private final TestResultUploadService testResultUploadService; | ||
|
||
@PostMapping(PATIENT_UPLOAD) | ||
public String handlePatientsUpload(@RequestParam("file") MultipartFile file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to put some stricter typing/validation on these multipart files? Such that we can reject if it's not a CSV? In particular, I'm worried that since this won't be applying graphQL's argument limits anymore, theoretically people could try to upload massive or incorrectly formatted files - it's a bit of a security concern, even though this endpoint is only open to authenticated users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's a Spring configuration we can enable: spring.servlet.multipart.max-file-size
Great minds think alike - you fixed this in the same minute I commented 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also adding an assert on the type of the file, even though that does nothing to the security since file extensions are a syntactical sugar on files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we thought about using something like clamav for file type and virus scanning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we were using clamav for file upload scanning on a defense project and it worked pretty well, though not sure it would work for this specific use case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think I ever heard of clamav
, it could be something we can look into, doesnt seem like a quick thing to integrate with spring though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I wasn't suggesting it for this PR 😄 maybe just a future thing if we want to bump up our security
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also from what I remember it was not too bad to integrate with java/spring but not a quick add
f45092f
to
451e7fe
Compare
451e7fe
to
db00372
Compare
max-file-size: 50MB | ||
server: | ||
error: | ||
include-stacktrace: never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes the trace from any exceptions returned to the frontend
@@ -49,6 +49,12 @@ spring: | |||
jdbc: | |||
initialize-schema: never | |||
table-name: ${spring.jpa.properties.hibernate.default_schema}.spring_session | |||
servlet: | |||
multipart: | |||
max-file-size: 50MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is set to the same max file limit enforced by the frontend for result upload
assertThrows(IllegalGraphqlArgumentException.class, () -> sut.uploadPatients(input)); | ||
assertThat(caught).hasMessage("PANIC"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests have been replaced by FileUploadControllerTest
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks Zedd! I had a question about how we scan files for upload and like 2 tiny things, but nothing blocking 😄
backend/src/main/java/gov/cdc/usds/simplereport/api/patient/PatientMutationResolver.java
Show resolved
Hide resolved
private final TestResultUploadService testResultUploadService; | ||
|
||
@PostMapping(PATIENT_UPLOAD) | ||
public String handlePatientsUpload(@RequestParam("file") MultipartFile file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we thought about using something like clamav for file type and virus scanning?
private final TestResultUploadService testResultUploadService; | ||
|
||
@PostMapping(PATIENT_UPLOAD) | ||
public String handlePatientsUpload(@RequestParam("file") MultipartFile file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we were using clamav for file upload scanning on a defense project and it worked pretty well, though not sure it would work for this specific use case)
backend/src/main/java/gov/cdc/usds/simplereport/service/TestResultUploadService.java
Show resolved
Hide resolved
backend/src/test/java/gov/cdc/usds/simplereport/api/patient/PatientMutationResolverTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for getting to these Spring cleanup tickets so quickly 😄
* upload files via rest * update frontend tests * add file upload controller test and remove unused resolvers * remove unused code * add tests and enable cors * add Patient Upload tests * adding sonar feedback * add access-token to FileUploadService * update patient upload error alert title * update uploads error checking * limit upload file size to 50MB in the backend to match frontend * only accept csv files and dont send back exception traces
BACKEND PULL REQUEST
Related Issue
Changes Proposed
Additional Information
Testing
Checklist for Primary Reviewer
test
,dev
, orpentest
and smoke tested