Skip to content

Commit

Permalink
fix: forbid same server-port and admin-server-port
Browse files Browse the repository at this point in the history
Forbids server-port and admin-server-port from being equal altogether,
despite they might not conflict at all in case admin and app are bound
to different addresses. Implemented as per the discussion at
#3508 (comment)
  • Loading branch information
develop7 committed May 29, 2024
1 parent 82a43c2 commit 1526130
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3414, Force listener to connect to read-write instances using `target_session_attrs` - @steve-chavez
- #3255, Fix incorrect `413 Request Entity Too Large` on pg errors `54*` - @taimoorzaeem
- #3549, Remove verbosity from error logs starting with "An error occurred..." and replacing it with "Failed to..." - @laurenceisla
- #3508, Server port and admin server port can end up with the same value - @develop7
+ The app is fails to start when the server port and admin server port are the same

### Deprecated

Expand Down
11 changes: 10 additions & 1 deletion src/PostgREST/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,21 @@ readAppConfig dbSettings optPath prevDbUri roleSettings roleIsolationLvl = do
Left err ->
return . Left $ "Error in config " <> err
Right parsedConfig ->
Right <$> decodeLoadFiles parsedConfig
case processForbiddenValues parsedConfig of
Left err' ->
return . Left $ "Error in config " <> err'

Check warning on line 228 in src/PostgREST/Config.hs

View check run for this annotation

Codecov / codecov/patch

src/PostgREST/Config.hs#L228

Added line #L228 was not covered by tests
Right config ->
Right <$> decodeLoadFiles config
where
-- Both C.ParseError and IOError are shown here
loadConfig :: FilePath -> IO (Either SomeException C.Config)
loadConfig = try . C.load

processForbiddenValues :: AppConfig -> Either Text AppConfig
processForbiddenValues cfg@AppConfig{..}
| configAdminServerPort == Just configServerPort = Left "admin-server-port cannot be the same as server-port"
| otherwise = Right cfg

decodeLoadFiles :: AppConfig -> IO AppConfig
decodeLoadFiles parsedConfig =
decodeJWKS <$>
Expand Down

0 comments on commit 1526130

Please sign in to comment.