Skip to content

Commit 10b52a6

Browse files
committed
remove the origin check logic
1 parent 25fd345 commit 10b52a6

File tree

3 files changed

+0
-113
lines changed

3 files changed

+0
-113
lines changed

components/server/src/auth/authenticator.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,6 @@ export class Authenticator {
189189
res.status(403).send("Authentication failed");
190190
return;
191191
}
192-
193-
// Validate origin for additional CSRF protection
194-
if (!this.nonceService.validateOrigin(req, host)) {
195-
log.error(`CSRF protection: Origin validation failed`, {
196-
url: req.url,
197-
origin: req.get("Origin"),
198-
referer: req.get("Referer"),
199-
expectedHost: host,
200-
});
201-
res.status(403).send("Invalid request");
202-
return;
203-
}
204192
}
205193

206194
// Always clear the nonce cookie

components/server/src/auth/nonce-service.spec.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { expect } from "chai";
88
import { Container } from "inversify";
9-
import express from "express";
109
import { Config } from "../config";
1110
import { NonceService } from "./nonce-service";
1211

@@ -65,76 +64,4 @@ describe("NonceService", () => {
6564
expect(nonceService.validateNonce(undefined, undefined)).to.be.false;
6665
});
6766
});
68-
69-
describe("validateOrigin", () => {
70-
it("should accept requests from expected SCM provider origin", () => {
71-
const req = {
72-
get: (header: string) => {
73-
if (header === "Origin") return "https://github.com";
74-
return undefined;
75-
},
76-
} as Partial<express.Request> as express.Request;
77-
78-
const isValid = nonceService.validateOrigin(req, "github.com");
79-
expect(isValid).to.be.true;
80-
});
81-
82-
it("should reject requests from different origin", () => {
83-
const req = {
84-
get: (header: string) => {
85-
if (header === "Origin") return "https://evil.com";
86-
return undefined;
87-
},
88-
} as Partial<express.Request> as express.Request;
89-
90-
const isValid = nonceService.validateOrigin(req, "github.com");
91-
expect(isValid).to.be.false;
92-
});
93-
94-
it("should reject requests without origin or referer", () => {
95-
const req = {
96-
get: () => undefined,
97-
} as Partial<express.Request> as express.Request;
98-
99-
const isValid = nonceService.validateOrigin(req, "github.com");
100-
expect(isValid).to.be.false;
101-
});
102-
103-
it("should accept requests with valid referer from expected host", () => {
104-
const req = {
105-
get: (header: string) => {
106-
if (header === "Referer") return "https://gitlab.com/oauth/authorize";
107-
return undefined;
108-
},
109-
} as Partial<express.Request> as express.Request;
110-
111-
const isValid = nonceService.validateOrigin(req, "gitlab.com");
112-
expect(isValid).to.be.true;
113-
});
114-
115-
it("should work with different SCM providers", () => {
116-
const testCases = [
117-
{ origin: "https://github.com", expectedHost: "github.com", shouldPass: true },
118-
{ origin: "https://gitlab.com", expectedHost: "gitlab.com", shouldPass: true },
119-
{ origin: "https://bitbucket.org", expectedHost: "bitbucket.org", shouldPass: true },
120-
{ origin: "https://github.com", expectedHost: "gitlab.com", shouldPass: false },
121-
{ origin: "https://evil.com", expectedHost: "github.com", shouldPass: false },
122-
];
123-
124-
testCases.forEach(({ origin, expectedHost, shouldPass }) => {
125-
const req = {
126-
get: (header: string) => {
127-
if (header === "Origin") return origin;
128-
return undefined;
129-
},
130-
} as Partial<express.Request> as express.Request;
131-
132-
const isValid = nonceService.validateOrigin(req, expectedHost);
133-
expect(isValid).to.equal(
134-
shouldPass,
135-
`${origin} vs ${expectedHost} should ${shouldPass ? "pass" : "fail"}`,
136-
);
137-
});
138-
});
139-
});
14067
});

components/server/src/auth/nonce-service.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,4 @@ export class NonceService {
7777

7878
return crypto.timingSafeEqual(stateBuffer, cookieBuffer);
7979
}
80-
81-
/**
82-
* Validates that the request origin is from the expected SCM provider domain
83-
*/
84-
validateOrigin(req: express.Request, expectedHost: string): boolean {
85-
const origin = req.get("Origin");
86-
const referer = req.get("Referer");
87-
88-
// For OAuth callbacks, we expect either Origin or Referer header
89-
const requestSource = origin || referer;
90-
91-
if (!requestSource) {
92-
// No origin/referer header - this could be a direct navigation or CSRF attack
93-
return false;
94-
}
95-
96-
try {
97-
const sourceUrl = new URL(requestSource);
98-
99-
// Validate that the request comes from the expected SCM provider host
100-
// expectedHost could be "github.com", "gitlab.com", etc.
101-
const expectedOrigin = `https://${expectedHost}`;
102-
return sourceUrl.origin === expectedOrigin;
103-
} catch (error) {
104-
// Invalid URL format
105-
return false;
106-
}
107-
}
10880
}

0 commit comments

Comments
 (0)