Skip to content

sign in to desktop app - #2300

Merged
abose merged 13 commits into
mainfrom
ker
Jun 18, 2025
Merged

sign in to desktop app#2300
abose merged 13 commits into
mainfrom
ker

Conversation

@abose

@abose abose commented Jun 17, 2025

Copy link
Copy Markdown
Member

No description provided.

Comment thread src-node/index.js
return;
}
if (req.method === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', origin);

Check failure

Code scanning / CodeQL

CORS misconfiguration for credentials transfer

[Credential](1) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](3) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](4) leak vulnerability due to a [misconfigured CORS header value](2).

Copilot Autofix

AI about 1 year ago

To fix the issue, the Access-Control-Allow-Origin header must only be set to trusted origins. This can be achieved by validating the origin header against a whitelist of allowed origins before setting it. If the origin is not in the whitelist, the header should not be set, and the request should be rejected.

Steps to fix:

  1. Introduce a whitelist of allowed origins.
  2. Validate the origin header against the whitelist before setting the Access-Control-Allow-Origin header.
  3. Ensure that the validation logic applies to all request types, including OPTIONS preflight requests.

Required changes:

  • Add a whitelist of allowed origins.
  • Update the autoAuth function to validate the origin header against the whitelist before setting the Access-Control-Allow-Origin header.

Suggested changeset 1
src-node/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src-node/index.js b/src-node/index.js
--- a/src-node/index.js
+++ b/src-node/index.js
@@ -221,3 +221,3 @@
 
-const ALLOWED_ORIGIN = 'https://account.phcode.io';
+const ALLOWED_ORIGINS = ['https://account.phcode.io'];
 function autoAuth(req, res) {
@@ -226,4 +226,4 @@
     // dev builds.
-    const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
-    if(!isAllowedOrigin){
+    const isAllowedOrigin = origin && ALLOWED_ORIGINS.includes(origin);
+    if (!isAllowedOrigin) {
         res.writeHead(403, { 'Content-Type': 'text/plain' });
EOF
@@ -221,3 +221,3 @@

const ALLOWED_ORIGIN = 'https://account.phcode.io';
const ALLOWED_ORIGINS = ['https://account.phcode.io'];
function autoAuth(req, res) {
@@ -226,4 +226,4 @@
// dev builds.
const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
if(!isAllowedOrigin){
const isAllowedOrigin = origin && ALLOWED_ORIGINS.includes(origin);
if (!isAllowedOrigin) {
res.writeHead(403, { 'Content-Type': 'text/plain' });
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread src-node/index.js
const cleanPath = url.pathname.replace(PHOENIX_AUTO_AUTH_URL, '');
// Check if the request is for the autoVerifyCode endpoint
if (cleanPath === `/autoVerifyCode` && req.method === 'GET') {
origin && res.setHeader('Access-Control-Allow-Origin', origin);

Check failure

Code scanning / CodeQL

CORS misconfiguration for credentials transfer

[Credential](1) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](3) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](4) leak vulnerability due to a [misconfigured CORS header value](2).

Copilot Autofix

AI about 1 year ago

To fix the issue, we will implement a whitelist of allowed origins and validate the req.headers.origin against this whitelist before setting the Access-Control-Allow-Origin header. This ensures that only trusted origins are allowed, and prevents attackers from exploiting the dynamic computation of the header.

Steps to fix:

  1. Define a whitelist of allowed origins as a constant.
  2. Validate the req.headers.origin against the whitelist.
  3. Set the Access-Control-Allow-Origin header only if the origin is in the whitelist.
  4. Remove redundant checks and ensure consistent validation logic.

Suggested changeset 1
src-node/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src-node/index.js b/src-node/index.js
--- a/src-node/index.js
+++ b/src-node/index.js
@@ -221,3 +221,3 @@
 
-const ALLOWED_ORIGIN = 'https://account.phcode.io';
+const ALLOWED_ORIGINS = ['https://account.phcode.io'];
 function autoAuth(req, res) {
@@ -226,4 +226,4 @@
     // dev builds.
-    const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
-    if(!isAllowedOrigin){
+    const isAllowedOrigin = ALLOWED_ORIGINS.includes(origin);
+    if (!isAllowedOrigin) {
         res.writeHead(403, { 'Content-Type': 'text/plain' });
@@ -247,4 +247,4 @@
     if (cleanPath === `/autoVerifyCode` && req.method === 'GET') {
-        origin && res.setHeader('Access-Control-Allow-Origin', origin);
-        if(!verificationCode) {
+        res.setHeader('Access-Control-Allow-Origin', origin);
+        if (!verificationCode) {
             res.setHeader('Content-Type', 'text/plain');
@@ -261,3 +261,3 @@
         nodeConnector.triggerPeer(EVENT_CONNECTED, "ok");
-        origin && res.setHeader('Access-Control-Allow-Origin', origin);
+        res.setHeader('Access-Control-Allow-Origin', origin);
         res.setHeader('Access-Control-Allow-Credentials', 'true');
EOF
@@ -221,3 +221,3 @@

const ALLOWED_ORIGIN = 'https://account.phcode.io';
const ALLOWED_ORIGINS = ['https://account.phcode.io'];
function autoAuth(req, res) {
@@ -226,4 +226,4 @@
// dev builds.
const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
if(!isAllowedOrigin){
const isAllowedOrigin = ALLOWED_ORIGINS.includes(origin);
if (!isAllowedOrigin) {
res.writeHead(403, { 'Content-Type': 'text/plain' });
@@ -247,4 +247,4 @@
if (cleanPath === `/autoVerifyCode` && req.method === 'GET') {
origin && res.setHeader('Access-Control-Allow-Origin', origin);
if(!verificationCode) {
res.setHeader('Access-Control-Allow-Origin', origin);
if (!verificationCode) {
res.setHeader('Content-Type', 'text/plain');
@@ -261,3 +261,3 @@
nodeConnector.triggerPeer(EVENT_CONNECTED, "ok");
origin && res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread src-node/index.js
verificationCode = null; // verification code is only returned once
} else if (cleanPath === `/appVerified` && req.method === 'GET') {
nodeConnector.triggerPeer(EVENT_CONNECTED, "ok");
origin && res.setHeader('Access-Control-Allow-Origin', origin);

Check failure

Code scanning / CodeQL

CORS misconfiguration for credentials transfer

[Credential](1) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](3) leak vulnerability due to a [misconfigured CORS header value](2). [Credential](4) leak vulnerability due to a [misconfigured CORS header value](2).

Copilot Autofix

AI about 1 year ago

To fix the issue, we need to ensure that the Access-Control-Allow-Origin header is set to a safe and validated value. This can be achieved by using a whitelist of allowed origins and ensuring that the origin header is explicitly validated against this whitelist before being used. Additionally, we should handle edge cases like the null origin to prevent misuse.

Steps to fix:

  1. Introduce a whitelist of allowed origins, including ALLOWED_ORIGIN.
  2. Validate the origin header against the whitelist before setting the Access-Control-Allow-Origin header.
  3. Reject requests with invalid or unsafe origins, including the null origin.
  4. Update the logic in the autoAuth function to use the validated origin.
Suggested changeset 1
src-node/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src-node/index.js b/src-node/index.js
--- a/src-node/index.js
+++ b/src-node/index.js
@@ -221,3 +221,3 @@
 
-const ALLOWED_ORIGIN = 'https://account.phcode.io';
+const ALLOWED_ORIGINS = ['https://account.phcode.io'];
 function autoAuth(req, res) {
@@ -226,4 +226,4 @@
     // dev builds.
-    const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
-    if(!isAllowedOrigin){
+    const isAllowedOrigin = origin && ALLOWED_ORIGINS.includes(origin);
+    if (!isAllowedOrigin || origin === 'null') {
         res.writeHead(403, { 'Content-Type': 'text/plain' });
@@ -247,3 +247,3 @@
     if (cleanPath === `/autoVerifyCode` && req.method === 'GET') {
-        origin && res.setHeader('Access-Control-Allow-Origin', origin);
+        res.setHeader('Access-Control-Allow-Origin', origin);
         if(!verificationCode) {
@@ -261,3 +261,3 @@
         nodeConnector.triggerPeer(EVENT_CONNECTED, "ok");
-        origin && res.setHeader('Access-Control-Allow-Origin', origin);
+        res.setHeader('Access-Control-Allow-Origin', origin);
         res.setHeader('Access-Control-Allow-Credentials', 'true');
EOF
@@ -221,3 +221,3 @@

const ALLOWED_ORIGIN = 'https://account.phcode.io';
const ALLOWED_ORIGINS = ['https://account.phcode.io'];
function autoAuth(req, res) {
@@ -226,4 +226,4 @@
// dev builds.
const isAllowedOrigin = !origin || (ALLOWED_ORIGIN === origin);
if(!isAllowedOrigin){
const isAllowedOrigin = origin && ALLOWED_ORIGINS.includes(origin);
if (!isAllowedOrigin || origin === 'null') {
res.writeHead(403, { 'Content-Type': 'text/plain' });
@@ -247,3 +247,3 @@
if (cleanPath === `/autoVerifyCode` && req.method === 'GET') {
origin && res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Origin', origin);
if(!verificationCode) {
@@ -261,3 +261,3 @@
nodeConnector.triggerPeer(EVENT_CONNECTED, "ok");
origin && res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
Copilot is powered by AI and may make mistakes. Always verify output.
@sonarqubecloud

Copy link
Copy Markdown

@abose
abose merged commit d45757e into main Jun 18, 2025
@abose
abose deleted the ker branch June 18, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants