-
Notifications
You must be signed in to change notification settings - Fork 1
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
File upload improvements #2919
base: develop
Are you sure you want to change the base?
File upload improvements #2919
Conversation
e775467
to
43cca7d
Compare
38918a4
to
0bdf9cc
Compare
<ul className="m-0 py-0 flex flex-col justify-start"> | ||
<li> | ||
<Link | ||
download={fileName} |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 19 days ago
To fix the problem, we need to ensure that the fileName
is properly escaped before being used in the Link
component. This can be achieved by using a library like he
(HTML entities) to encode the fileName
, which will prevent any HTML or script content from being interpreted by the browser.
- Install the
he
library to handle HTML entity encoding. - Import the
he
library in the file. - Encode the
fileName
before using it in theLink
component.
-
Copy modified line R7 -
Copy modified line R101 -
Copy modified line R106
@@ -6,2 +6,3 @@ | ||
import Link from "next/link"; | ||
import he from 'he'; | ||
|
||
@@ -99,3 +100,3 @@ | ||
<Link | ||
download={fileName} | ||
download={he.encode(fileName)} | ||
href={downloadUrl} | ||
@@ -104,3 +105,3 @@ | ||
> | ||
{fileName} | ||
{he.encode(fileName)} | ||
</Link> |
-
Copy modified lines R107-R108
@@ -106,3 +106,4 @@ | ||
"vite-require": "^0.2.3", | ||
"vitest": "^3.0.5" | ||
"vitest": "^3.0.5", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
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.
CodeQL has raised an interesting point here. I'm looking into this more to see if it can actually be exploited.
) -> Tuple[Literal[200], Operation]: | ||
payload = OperationNewEntrantApplicationInWithDocuments( | ||
date_of_first_shipment=details.date_of_first_shipment, |
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.
Doing it like this instead of **details.dict() was to make mypy happy
naics_code_id: Optional[int] = None | ||
opt_in: Optional[bool] = False |
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 are optional and None so I'm not sure why I'm getting mypy errors
06b749b
to
6a71ad4
Compare
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 wasn't able to get past the first step of the Registration workflow. Getting this error in the backend:
File "/Users/awilliam/Documents/cas-registration/bc_obps/service/document_service_v2.py", line 29, in create_or_replace_operation_document
existing_document = cls.get_operation_document_by_type_if_authorized(user_guid, operation_id, document_type)
^^^^^^^^^^^^
NameError: name 'operation_id' is not defined
---------------------------------------------ERROR END-------------------------------------------------
Bad Request: /api/registration/operations/df62d793-8cfe-4272-a93e-ea9c9139ff82/registration/operation
[11/Mar/2025 22:07:41] "PUT /api/registration/operations/df62d793-8cfe-4272-a93e-ea9c9139ff82/registration/operation HTTP/1.1" 400 49
@router.get( | ||
"/operations/{uuid:operation_id}/documents/{uuid:document_type}", | ||
response={200: DocumentOut, custom_codes_4xx: Message}, | ||
tags=OPERATOR_TAGS, |
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.
OPERATION_TAGS
instead?
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 ended up not using this endpoint because we can use a GCS download link instead
bc_obps/registration/api/v2/_operations/_operation_id/documents/document_id.py
Outdated
Show resolved
Hide resolved
bc_obps/registration/api/v2/_operations/_operation_id/documents/document_id.py
Outdated
Show resolved
Hide resolved
""" | ||
existing_document = cls.get_operation_document_by_type_if_authorized(user_guid, operation_id, document_type) | ||
# if there is an existing document, check if the new one is different | ||
existing_document = DocumentDataAccessService.get_operation_document_by_type(operation_id, type) |
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.
why did get_operation_document_by_type_if_authorized
get replaced with this? We're no longer checking whether the user is authorized to access the document
bciers/apps/administration/tests/components/operations/OperationInformationForm.test.tsx
Outdated
Show resolved
Hide resolved
- DocumentServiceV2.create_or_replace_operation_document | ||
- DocumentDataAccessServiceV2.create_document |
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.
- DocumentServiceV2.create_or_replace_operation_document | |
- DocumentDataAccessServiceV2.create_document | |
- DocumentService.create_or_replace_operation_document | |
- DocumentDataAccessService.create_document |
// this removes the file keys if no new file has been uploaded | ||
if ( | ||
(key === "boundary_map" || | ||
key === "process_flow_diagram" || | ||
key === "new_entrant_application") && | ||
typeof rjsfFormData[key] === "string" |
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.
please help this idiot understand - where does the check for "no new file has been uploaded" happen?
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.
If a new file has been uploaded, the value is a File
. If the value is a string, it means there's no new file. There's some info about this in the file_uploads.md
(feel free to suggest improvements), and I'll update this comment to make it clearer too
<ul className="m-0 py-0 flex flex-col justify-start"> | ||
<li> | ||
<Link | ||
download={fileName} |
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.
CodeQL has raised an interesting point here. I'm looking into this more to see if it can actually be exploited.
I think this is on old version of the branch--the attachment filename is displaying as the id in the screenshot, and I fixed that in a later commit |
Co-authored-by: Andrea Williams <[email protected]> Signed-off-by: Brianna Cerkiewicz <[email protected]>
Co-authored-by: Andrea Williams <[email protected]> Signed-off-by: Brianna Cerkiewicz <[email protected]>
9c912b2
to
8baa162
Compare
8baa162
to
a7f8c44
Compare
#2123
This PR