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

SSL mode query param (e.g., '?sslmode=required') breaks URI parsing #6544

Closed
SpencerKaiser opened this issue Aug 10, 2020 · 5 comments
Closed

Comments

@SpencerKaiser
Copy link

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:
Use a Database URL including ?sslmode=required and Typeorm will throw an error saying databasename?sslmode=required not found

@imnotjames
Copy link
Contributor

Do you have the full URL you're passing?

@SpencerKaiser
Copy link
Author

SpencerKaiser commented Sep 29, 2020

@imnotjames here's an obfuscated version, hopefully that's helpful:
postgres://XXX_XXXXX_XXXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX.XXXXXXXXXX.databases.appdomain.cloud:31762/XXXclouddb?sslmode=verify-full

In case it's helpful, the exact string length on the non-obfuscated one is 243 characters.

Here's what I use in my app to correct for it (which is nasty, but it is what it is haha):

const vcapPostgres = vcapServices['databases-for-postgresql']?.[0]?.credentials?.connection?.postgres;
const url = vcapPostgres?.composed[0]?.replace('?sslmode=verify-full', '') as string;

const cert = vcapPostgres ? Base64.decode(vcapPostgres.certificate?.certificate_base64) : null;
const connectionOptions = {
  url,
  type: 'postgres',
  entities: [path.join(__dirname, 'entities/*')],
  migrations: [path.join(__dirname, 'migration/*')],
  migrationsRun: true,
  ssl: {
    ca: cert,
  },
};

@imnotjames
Copy link
Contributor

imnotjames commented Sep 30, 2020

Ouch! That's not a fun hack to have to implement.

I know our URL parsing is all sorts of weird & hope to shore that up sometime in the near future. It doesn't do anything with the query string values but SHOULD remove them from the URLs so the database name doesn't include them.

Unfortunately, when testing with 0.2.27 I cannot replicate the issue!

Here's the code I ran:

import {DriverUtils} from "../../../src/driver/DriverUtils";
import {expect} from "chai";

const DRIVER_URL = 'postgres://XXX_XXXXX_XXXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX.XXXXXXXXXX.databases.appdomain.cloud:31762/XXXclouddb?sslmode=verify-full';

describe('github issues > #6544 SSL mode query param (e.g., \'?sslmode=required\') breaks URI parsing', () => {
    it('should correctly parse database from the URI', async () => {
        const parameters = DriverUtils.buildDriverOptions({
            url: DRIVER_URL
        });

        expect(parameters.database).to.be.equal('XXXclouddb');
    });
});

This bypassed the connection to use the underlying DriverUtils - mostly 'cause I don't have any connectable database at that host. I though that maybe it was somewhere between Connection and DriverUtils. To test this similar to what you've got, I also attempted to create a connection with similar (albeit, slightly different) values and could not replicate the issue, either. ):

Can you confirm that this is still a problem in 0.2.27?

@imnotjames
Copy link
Contributor

Aha! I found that it was brought into 0.2.25? Or 0.2.26 - but --- This is a duplicate of issue #6389 which was fixed by #6390 !

@imnotjames
Copy link
Contributor

If you find that you're still seeing the issue in 0.2.27 please poke back here or in the linked issue. Cheers!

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

No branches or pull requests

2 participants