-
Notifications
You must be signed in to change notification settings - Fork 30
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
WIP/POC: crossword page in DCR #12511
base: main
Are you sure you want to change the base?
Conversation
|{' '} | ||
{!!crossword.pdf && ( | ||
<> | ||
<a target="_blank" href={crossword.pdf} rel="noreferrer"> |
Check failure
Code scanning / CodeQL
Client-side cross-site scripting High
user-provided value
Cross-site scripting vulnerability due to
user-provided value
Cross-site scripting vulnerability due to
user-provided value
Cross-site scripting vulnerability due to
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 25 days ago
To fix the problem, we need to ensure that the crossword.pdf
value is properly sanitized before being used in the href
attribute. This can be achieved by using a library like DOMPurify
to sanitize the URL.
- Import the
DOMPurify
library. - Use
DOMPurify.sanitize
to clean thecrossword.pdf
value before using it in thehref
attribute.
-
Copy modified line R4 -
Copy modified line R25 -
Copy modified line R36 -
Copy modified line R38
@@ -3,2 +3,3 @@ | ||
import { palette } from '../palette'; | ||
import DOMPurify from 'dompurify'; | ||
|
||
@@ -23,2 +24,3 @@ | ||
}) => { | ||
const sanitizedPdf = crossword.pdf ? DOMPurify.sanitize(crossword.pdf) : null; | ||
return ( | ||
@@ -33,5 +35,5 @@ | ||
|{' '} | ||
{!!crossword.pdf && ( | ||
{!!sanitizedPdf && ( | ||
<> | ||
<a target="_blank" href={crossword.pdf} rel="noreferrer"> | ||
<a target="_blank" href={sanitizedPdf} rel="noreferrer"> | ||
PDF version |
|{' '} | ||
{!!crossword.pdf && ( | ||
<> | ||
<a target="_blank" href={crossword.pdf} rel="noreferrer"> |
Check warning
Code scanning / CodeQL
Client-side URL redirect Medium
user-provided value
Untrusted URL redirection depends on a
user-provided value
Untrusted URL redirection depends on a
user-provided value
Untrusted URL redirection depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 25 days ago
To fix the problem, we need to ensure that the URL in crossword.pdf
is validated against a list of trusted URLs or domains before it is used in the href
attribute. This can be achieved by creating a function that checks if the URL belongs to a trusted domain and only then allows it to be used.
- Create a function to validate the URL.
- Use this function to check
crossword.pdf
before setting it in thehref
attribute.
-
Copy modified lines R17-R26 -
Copy modified line R44
@@ -16,2 +16,12 @@ | ||
|
||
const isValidUrl = (url: string) => { | ||
try { | ||
const trustedDomains = ['theguardian.com', 'guim.co.uk']; | ||
const parsedUrl = new URL(url); | ||
return trustedDomains.includes(parsedUrl.hostname); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export const CrosswordLinks = ({ | ||
@@ -33,3 +43,3 @@ | ||
|{' '} | ||
{!!crossword.pdf && ( | ||
{!!crossword.pdf && isValidUrl(crossword.pdf) && ( | ||
<> |
Size Change: +101 kB (+10.96%) Total Size: 1.02 MB
ℹ️ View Unchanged
|
What does this change?
Add a crossword page and layout into DCR; uses https://github.com/t-blackwell/mycrossword for the crossword player.
Written by a first-time DCR contributor, and at-best novice frontend person trying to find the least-effort way to get the player to render on the frontend; probably needs many many changes to bring into good practice!
Why?
Screenshots