Skip to content

Commit

Permalink
fix(auth-server): handle preflight requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Mar 21, 2024
1 parent 873b4c9 commit adbc25f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/webOAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
const errMessage = messages.getMessage(errName, [url.pathname]);
reject(new SfError(errMessage, errName));
}
} else if (
request.method === 'OPTIONS' &&
request.headers['access-control-request-private-network'] === 'true' &&
request.headers['access-control-request-method']
) {
this.webServer.handlePreflightRequest(response);
} else {
this.webServer.sendError(405, 'Unsupported http methods', response);
const errName = 'invalidRequestMethod';
Expand Down Expand Up @@ -399,6 +405,22 @@ export class WebServer extends AsyncCreatable<WebServer.Options> {
this.redirectStatus.emit('complete');
}

/**
* Preflight request:
*
* https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
* https://www.w3.org/TR/2020/SPSD-cors-20200602/#resource-preflight-requests
*/
public handlePreflightRequest(response: http.ServerResponse): void {
// We don't validate the origin here because:
// 1. The default login URL (login.salesforce.com) will not match after a redirect or if user choose a custom domain in login.
// 2. There's no fixed list of auth URLs we could check against.
response.statusCode = 204; // No Content response
response.setHeader('Access-Control-Allow-Methods', 'GET');
response.setHeader('Access-Control-Request-Headers', 'GET');
response.end();
}

public async handleSuccess(response: http.ServerResponse): Promise<void> {
return this.handleRedirect(response, '/OauthSuccess');
}
Expand Down

2 comments on commit adbc25f

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: adbc25f Previous: 33784c6 Ratio
Child logger creation 470064 ops/sec (±2.33%) 458094 ops/sec (±2.12%) 0.97
Logging a string on root logger 814225 ops/sec (±7.51%) 797808 ops/sec (±8.27%) 0.98
Logging an object on root logger 646849 ops/sec (±6.66%) 641180 ops/sec (±8.47%) 0.99
Logging an object with a message on root logger 4901 ops/sec (±217.88%) 6102 ops/sec (±214.66%) 1.25
Logging an object with a redacted prop on root logger 461432 ops/sec (±7.36%) 436492 ops/sec (±8.89%) 0.95
Logging a nested 3-level object on root logger 391701 ops/sec (±8.24%) 395672 ops/sec (±7.85%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: adbc25f Previous: 33784c6 Ratio
Child logger creation 339507 ops/sec (±0.34%) 339908 ops/sec (±2.96%) 1.00
Logging a string on root logger 759702 ops/sec (±5.85%) 831234 ops/sec (±13.50%) 1.09
Logging an object on root logger 580922 ops/sec (±4.24%) 646790 ops/sec (±8.25%) 1.11
Logging an object with a message on root logger 10866 ops/sec (±189.68%) 2949 ops/sec (±228.70%) 0.27
Logging an object with a redacted prop on root logger 369307 ops/sec (±9.30%) 477003 ops/sec (±6.99%) 1.29
Logging a nested 3-level object on root logger 275550 ops/sec (±6.29%) 339437 ops/sec (±6.25%) 1.23

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.