-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-hfgf-99p3-6fjj
* More secure OAuth, fixed frame ancestors * Change generateRandomString to return base64-encoded entropy While the old implementation also seems to yield correct results, it is (at least in my opinion) not obvious that it is correct and sufficiently secure for the following reasons: 1. It takes the output string length as a parameter instead of the required amount of entropy. For cryptographic applications, it is important to know how much entropy any generated secret contains. Therefore, the input to the function should be the required bytes of entropy instead of the output string length. 2. While it uses a rather simple algorithm to convert the entropy bytes to a string, using a well-known and dead simple encoding such as base64 (or hexadecimal, but base64 is more compact) is even easier to verify as "obviously correct". In this case URL-safe base64 is chosen because the values are also used in URLs. All usages of the function were also changed to accomodate the parameter change to requested bytes of entropy. For all of them 32 bytes (256 bits) of entropy were chosen, which nicely fits the purpose of being used for SHA256 and is definitely enough entropy for things like OAuth 'state'. * Apply more restrictive CSP and prevent MIME sniffing for backend As the backend doesn't show HTML pages to users, a very restrictive CSP can be used. I'm currently not aware of any active issues, but being as restrictive as possible doesn't hurt, which is what default-src 'none' does. Also, set "X-Content-Type-Options: nosniff" to prevent MIME sniffing in browsers, which can also be an issue in certain circumstances. * Implement a basic Content-Security-Policy in the client This commit implements a basic CSP in the client by setting it as a <meta> tag in index.html. Normally it would be preferred to set the CSP in a HTTP header, but the react dev server does not seem to support that. However, it is very important to have the CSP active during development to catch errors caused by a restrictive CSP before deploying to production. Note that a header-based CSP is still required to set "frame-ancestors 'none'" to prevent clickjacking. It is perfectly fine to set the CSP both in the <meta> tag and in the HTTP header, both CSPs will be applied. There is still room for improvement in the CSP. With some effort, the script-src could be further restricted using a combination of hashes or nonces and 'strict-dynamic' to get rid of 'self'. The connect-src could also be restricted to only the backend origin. That being said, this is still a very good starting point and much better than not having a CSP at all. * Prevent MIME sniffing for the client in production Prevent MIME sniffing for the client in production by setting the header "X-Content-Type-Options: nosniff". * Use only the origin of CLIENT_ENDPOINT for CORS policy When the full CLIENT_ENDPOINT is used to set the CORS policy, the policy does not get applied correctly when the client is served under a subdirectory. Always using the origin fixes this. * removed pkce, connect-src is dynamic * ensuring API_ENDPOINT ends with a / * make sure api endpoint ends with a slash, updated CORS notice * fixed comment on index.html --------- Co-authored-by: Marius Renner <[email protected]>
- Loading branch information
1 parent
cd83dda
commit c3ae876
Showing
14 changed files
with
242 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<script src="%PUBLIC_URL%/variables.js"></script> | ||
|
||
<title>Your Spotify</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
|
||
<meta name="title" content="Your Spotify"> | ||
<meta name="description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
|
||
<meta property="og:type" content="image/png"> | ||
<meta property="og:title" content="Your Spotify"> | ||
<meta property="og:image:width" content="1200"> | ||
<meta property="og:image:height" content="628"> | ||
<meta property="og:description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
<meta property="og:image" content="http://localhost:8080/static/your_spotify_1200.png"> | ||
|
||
<meta property="twitter:card" content="summary"> | ||
<meta property="twitter:title" content="Your Spotify"> | ||
<meta property="twitter:description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
<meta property="twitter:image" content="http://localhost:8080/static/your_spotify_1200.png"> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
|
||
<!-- | ||
While setting the CSP in HTTP headers is preferred, there does not seem to | ||
be a good way to do this in the react dev environment, so it is set here as | ||
a meta tag. Note that frame-ancestors CANNOT be set in the meta tag and | ||
MUST be set as a HTTP header in production! | ||
Restricting connect-src is done at start of the client server. | ||
--> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; object-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https://i.scdn.co; connect-src *;" /> | ||
|
||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<script src="%PUBLIC_URL%/variables.js"></script> | ||
|
||
<title>Your Spotify</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
|
||
<meta name="title" content="Your Spotify"> | ||
<meta name="description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
|
||
<meta property="og:type" content="image/png"> | ||
<meta property="og:title" content="Your Spotify"> | ||
<meta property="og:image:width" content="1200"> | ||
<meta property="og:image:height" content="628"> | ||
<meta property="og:description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
<meta property="og:image" content="http://localhost:8080/static/your_spotify_1200.png"> | ||
|
||
<meta property="twitter:card" content="summary"> | ||
<meta property="twitter:title" content="Your Spotify"> | ||
<meta property="twitter:description" content="Keep track of your Spotify listening habits with Your Spotify."> | ||
<meta property="twitter:image" content="http://localhost:8080/static/your_spotify_1200.png"> | ||
</head> | ||
|
||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"headers": [ | ||
{ | ||
"source": "*", | ||
"headers": [ | ||
{ | ||
"key": "Content-Security-Policy", | ||
"value": "frame-ancestors 'none';" | ||
}, | ||
{ | ||
"key": "X-Content-Type-Options", | ||
"value": "nosniff" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.