Skip to content
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

feat: selectively enable / disable default authentication adapters #7953

Merged
merged 7 commits into from
May 28, 2022

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Apr 26, 2022

New Pull Request Checklist

Issue Description

I would say 100% of configurations use none, or a couple of the internal auth adaptors. However, by default, any auth type is enabled. This can lead to

Related issue: #7952

Approach

Adds enabled option to auth options. If enabled === false, the auth won't be able to be used.

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK
  • A changelog entry is created automatically using the pull request title (do not manually add a changelog entry)

@parse-github-assistant
Copy link

parse-github-assistant bot commented Apr 26, 2022

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@codecov
Copy link

codecov bot commented Apr 26, 2022

Codecov Report

Merging #7953 (3aadb58) into alpha (88b4d9d) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            alpha    #7953      +/-   ##
==========================================
- Coverage   94.13%   94.13%   -0.01%     
==========================================
  Files         182      182              
  Lines       13630    13635       +5     
==========================================
+ Hits        12831    12835       +4     
- Misses        799      800       +1     
Impacted Files Coverage Δ
src/Options/index.js 100.00% <ø> (ø)
src/Options/Definitions.js 100.00% <100.00%> (ø)
src/RestWrite.js 94.56% <100.00%> (+0.18%) ⬆️
src/batch.js 92.98% <0.00%> (-1.76%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 95.46% <0.00%> (-0.16%) ⬇️
src/ParseServerRESTController.js 98.48% <0.00%> (+1.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88b4d9d...3aadb58. Read the comment docs.

@dblythy dblythy changed the title feat: allow disabling of auth feat: allow disabling of authentication provider Apr 26, 2022
@dblythy dblythy changed the title feat: allow disabling of authentication provider feat: allow disabling of default authentication provider Apr 26, 2022
Copy link
Member

@Moumouls Moumouls left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Moumouls Moumouls left a comment

Choose a reason for hiding this comment

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

LGTM

@Moumouls Moumouls self-requested a review April 29, 2022 06:57
Moumouls
Moumouls previously approved these changes Apr 29, 2022
Copy link
Member

@Moumouls Moumouls left a comment

Choose a reason for hiding this comment

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

LGTM (this is the good one ahha)

@dblythy dblythy requested a review from Moumouls April 29, 2022 06:59
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Should we already add a deprecation warning to this that adapters will be disabled by default in the future?

@mtrezza mtrezza force-pushed the alpha branch 2 times, most recently from 59215e6 to e6d7d8f Compare May 1, 2022 02:29
@mtrezza
Copy link
Member

mtrezza commented May 13, 2022

@dblythy Could you resolve the conflicts so this can be reviewed?

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Look good! Anything you want to add before merge?

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

This is missing the parameter definition. We don't have any adapter definitions strangely, so you can only do it like this:

Add to src/Options/index.js:

auth: ?(AuthAdapter[]);
// ...
export interface AuthAdapter {
  /* Is `true` if the auth adapter is enabled, `false` otherwise.
  :DEFAULT: true */
  enabled: ?boolean;
}

@dblythy
Copy link
Member Author

dblythy commented May 27, 2022

Thanks for that @mtrezza 😊

@dblythy dblythy requested a review from a team May 27, 2022 02:31
src/Options/Definitions.js Outdated Show resolved Hide resolved
@mtrezza
Copy link
Member

mtrezza commented May 28, 2022

Looks good! So we have the new option documented in the API reference at least. If you add a short note to the auth adapter docs in the Parse Server guide when you have some time, that would be great. In the meantime I think we can go ahead and merge.

@mtrezza mtrezza changed the title feat: allow disabling of default authentication provider feat: allow disabling of default authentication providers May 28, 2022
@mtrezza mtrezza changed the title feat: allow disabling of default authentication providers feat: selectively enable / disable default authentication providers May 28, 2022
@mtrezza mtrezza changed the title feat: selectively enable / disable default authentication providers feat: selectively enable / disable default authentication adapters May 28, 2022
@mtrezza mtrezza merged commit c1e808f into parse-community:alpha May 28, 2022
@mtrezza mtrezza linked an issue May 28, 2022 that may be closed by this pull request
3 tasks
parseplatformorg pushed a commit that referenced this pull request May 28, 2022
# [5.3.0-alpha.13](5.3.0-alpha.12...5.3.0-alpha.13) (2022-05-28)

### Features

* selectively enable / disable default authentication adapters ([#7953](#7953)) ([c1e808f](c1e808f))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.3.0-alpha.13

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label May 28, 2022
parseplatformorg pushed a commit that referenced this pull request Jun 17, 2022
# [5.3.0-beta.1](5.2.1...5.3.0-beta.1) (2022-06-17)

### Bug Fixes

* afterSave trigger removes pointer in Parse object ([#7913](#7913)) ([47d796e](47d796e))
* auto-release process may fail if optional back-merging task fails ([#8051](#8051)) ([cf925e7](cf925e7))
* custom database options are not passed to MongoDB GridFS ([#7911](#7911)) ([b1e5565](b1e5565))
* depreciate allowClientClassCreation defaulting to true ([#7925](#7925)) ([38ed96a](38ed96a))
* errors in GraphQL do not show the original error but a general `Unexpected Error` ([#8045](#8045)) ([0d81887](0d81887))
* interrupted WebSocket connection not closed by LiveQuery server ([#8012](#8012)) ([2d5221e](2d5221e))
* live query role cache does not clear when a user is added to a role ([#8026](#8026)) ([199dfc1](199dfc1))
* peer dependency mismatch for GraphQL dependencies ([#7934](#7934)) ([0a6faa8](0a6faa8))
* return correct response when revert is used in beforeSave ([#7839](#7839)) ([19900fc](19900fc))
* security upgrade @parse/fs-files-adapter from 1.2.1 to 1.2.2 ([#7948](#7948)) ([3a70fda](3a70fda))
* security upgrade moment from 2.29.1 to 2.29.2 ([#7931](#7931)) ([731c550](731c550))
* security upgrade parse push adapter from 4.1.0 to 4.1.2 ([#7893](#7893)) ([93667b4](93667b4))
* websocket connection of LiveQuery interrupts frequently ([#8048](#8048)) ([03caae1](03caae1))

### Features

* add MongoDB 5.1 compatibility ([#7682](#7682)) ([022a856](022a856))
* add MongoDB 5.2 support ([#7894](#7894)) ([5bfa716](5bfa716))
* add support for Node 17 and 18 ([#7896](#7896)) ([3e9f292](3e9f292))
* align file trigger syntax with class trigger; use the new syntax `Parse.Cloud.beforeSave(Parse.File, (request) => {})`, the old syntax `Parse.Cloud.beforeSaveFile((request) => {})` has been deprecated ([#7966](#7966)) ([c6dcad8](c6dcad8))
* replace GraphQL Apollo with GraphQL Yoga ([#7967](#7967)) ([1aa2204](1aa2204))
* selectively enable / disable default authentication adapters ([#7953](#7953)) ([c1e808f](c1e808f))
* upgrade mongodb from 4.4.1 to 4.5.0 ([#7991](#7991)) ([e692b5d](e692b5d))

### Performance Improvements

* reduce database operations when using the constant parameter in Cloud Function validation ([#7892](#7892)) ([041197f](041197f))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.3.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 17, 2022
parseplatformorg pushed a commit that referenced this pull request Oct 29, 2022
# [5.3.0](5.2.8...5.3.0) (2022-10-29)

### Bug Fixes

* afterSave trigger removes pointer in Parse object ([#7913](#7913)) ([47d796e](47d796e))
* authentication adapter app ID validation may be circumvented; this fixes a vulnerability that affects configurations which allow users to authenticate using the Parse Server authentication adapter for *Facebook* or *Spotify* and where the server-side authentication adapter configuration `appIds` is set as a string (e.g. `abc`) instead of an array of strings (e.g. `["abc"]`) ([GHSA-r657-33vp-gp22](GHSA-r657-33vp-gp22)) [skip release] ([#8188](#8188)) ([1a2b1b9](1a2b1b9))
* auto-release process may fail if optional back-merging task fails ([#8051](#8051)) ([cf925e7](cf925e7))
* brute force guessing of user sensitive data via search patterns (GHSA-2m6g-crv8-p3c6) ([#8145](#8145)) [skip release] ([f0db4ca](f0db4ca))
* certificate in Apple Game Center auth adapter not validated [skip release] ([#8055](#8055)) ([4c2aa63](4c2aa63))
* custom database options are not passed to MongoDB GridFS ([#7911](#7911)) ([b1e5565](b1e5565))
* depreciate allowClientClassCreation defaulting to true ([#7925](#7925)) ([38ed96a](38ed96a))
* errors in GraphQL do not show the original error but a general `Unexpected Error` ([#8045](#8045)) ([0d81887](0d81887))
* interrupted WebSocket connection not closed by LiveQuery server ([#8012](#8012)) ([2d5221e](2d5221e))
* invalid file request not properly handled [skip release] ([#8061](#8061)) ([1a04a34](1a04a34))
* live query role cache does not clear when a user is added to a role ([#8026](#8026)) ([199dfc1](199dfc1))
* peer dependency mismatch for GraphQL dependencies ([#7934](#7934)) ([0a6faa8](0a6faa8))
* protected fields exposed via LiveQuery (GHSA-crrq-vr9j-fxxh) [skip release] ([#8075](#8075)) ([636d16e](636d16e))
* return correct response when revert is used in beforeSave ([#7839](#7839)) ([19900fc](19900fc))
* security upgrade @parse/fs-files-adapter from 1.2.1 to 1.2.2 ([#7948](#7948)) ([3a70fda](3a70fda))
* security upgrade moment from 2.29.1 to 2.29.2 ([#7931](#7931)) ([731c550](731c550))
* security upgrade parse push adapter from 4.1.0 to 4.1.2 ([#7893](#7893)) ([93667b4](93667b4))
* server crashes when receiving file download request with invalid byte range; this fixes a security vulnerability that allows an attacker to impact the availability of the server instance; the fix improves parsing of the range parameter to properly handle invalid range requests ([GHSA-h423-w6qv-2wj3](GHSA-h423-w6qv-2wj3)) [skip release] ([#8237](#8237)) ([4c1befa](4c1befa))
* session object properties can be updated by foreign user; this fixes a security vulnerability in which a foreign user can write to the session object of another user if the session object ID is known; the fix prevents writing to foreign session objects ([GHSA-6w4q-23cf-j9jp](GHSA-6w4q-23cf-j9jp)) [skip release] ([#8181](#8181)) ([83cdc89](83cdc89))
* websocket connection of LiveQuery interrupts frequently ([#8048](#8048)) ([03caae1](03caae1))

### Features

* add MongoDB 5.1 compatibility ([#7682](#7682)) ([022a856](022a856))
* add MongoDB 5.2 support ([#7894](#7894)) ([5bfa716](5bfa716))
* add support for Node 17 and 18 ([#7896](#7896)) ([3e9f292](3e9f292))
* align file trigger syntax with class trigger; use the new syntax `Parse.Cloud.beforeSave(Parse.File, (request) => {})`, the old syntax `Parse.Cloud.beforeSaveFile((request) => {})` has been deprecated ([#7966](#7966)) ([c6dcad8](c6dcad8))
* replace GraphQL Apollo with GraphQL Yoga ([#7967](#7967)) ([1aa2204](1aa2204))
* selectively enable / disable default authentication adapters ([#7953](#7953)) ([c1e808f](c1e808f))
* upgrade mongodb from 4.4.1 to 4.5.0 ([#7991](#7991)) ([e692b5d](e692b5d))

### Performance Improvements

* reduce database operations when using the constant parameter in Cloud Function validation ([#7892](#7892)) ([041197f](041197f))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.3.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Oct 29, 2022
@dblythy dblythy deleted the disable-auth branch December 4, 2022 14:59
@FransGH
Copy link
Contributor

FransGH commented Jun 24, 2023

Hi @dblythy, hope you can help. I'm using a custom auth adapter and just stumbled on this (breaking?) change after updating to the latest 5.x (5.1.1).

On my dev-system, where a config json is passed via API, all works well with a custom auth adaptor (as described in http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication).

On staging (and production), when passing the same config via CLI in a docker, the log just shows "Error: [object Object] should be a comma separated string or an array". Took some time but finally figured out that the auth parameter was the cause:

auth: {
   env: 'PARSE_SERVER_AUTH_PROVIDERS',
   help: 'Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication',
   action: parsers.arrayParser
 },

I'm probably missing something but what is currently (as of 5.5.x and 6.x) the recommend way to install/configure a custom auth adapter?

@dblythy
Copy link
Member Author

dblythy commented Jun 25, 2023

Can you share your auth config?

@FransGH
Copy link
Contributor

FransGH commented Jun 25, 2023

Sure, here's a simple config that reproduces the issue with a standard auth-config (same happens with a custom auth-adapter as it basically just adds a custom module path):

{
  "appName": "test",
  "appId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "masterKey": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
  "logLevel": "error",
  "auth": {
    "facebook": {
      "appIds": "FACEBOOK APP ID"
    }
  }
}

I get the following error with parse server 5.5.1 CLI:

Error: [object Object] should be a comma separated string or an array

Passing the exact same config.json via API works.

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const fs = require('fs');

let api = new ParseServer(JSON.parse(fs.readFileSync('config.json')));

let app = express();
app.use('/parse', api);
app.listen(1337, () => console.log('parse-server running on port 1337.'));

Looking at the code it appears that the main issue is that 'auth' parameter definition was changed from an "parsers.objectParser" to "parsers.arrayParser". The auth parameter is however an object, not an object array. The test confirms this as it also passes in an object:

await reconfigureServer({
       auth: {
         myoauth: {
           enabled: false,
           module: path.resolve(__dirname, 'support/myoauth'), // relative path as it's run from src
         },
       },
     });

@mtrezza adding you to the discussion as it seems you where involved in changing the parameter definition. Any idea how this can be best fixed?

I'm meanwhile looking into using Parse.User._registerAuthenticationProvider to dynamically load a custom auth-adapter, bypassing the need to configure via the auth option.

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2023

@FransGH Just to reiterate on what has already been said at some other place of discussion; if you encounter an issue, please open a new issue to discuss. This makes it easier to follow for others and increases the chances that an issue will be fixed, as the discussion is not fragmented over multiple issues / PRs. If you comment on closed PRs or issue, chances are it won't be followed up or tracked properly.

@FransGH
Copy link
Contributor

FransGH commented Jun 26, 2023

Sure, no problem. Creating an issue was the next thing I would have done if there was no further followup. But I'm thankful for how quickly this was picked up and look forward testing it on 5.5.1.

@mtrezza
Copy link
Member

mtrezza commented Jun 26, 2023

Great, thanks for reporting the issue and testing the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to disable authentication adapter
5 participants