Skip to content

refactor: reject JWT expiration value at startup if less than 1 sec - #1172

Merged
graikhel-intel merged 3 commits into
mainfrom
fix-CM-334-jwt-expiration
Aug 20, 2026
Merged

refactor: reject JWT expiration value at startup if less than 1 sec #1172
graikhel-intel merged 3 commits into
mainfrom
fix-CM-334-jwt-expiration

Conversation

@ShradhaGupta31

@ShradhaGupta31 ShradhaGupta31 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Changes Done:

  • Modified config.go to validate jwtExpiration while console startup
  • Reject non-positive values of jwtExpiration

Description:
config.yml accepts jwtExpiration: 0s which is a syntactically valid zero duration that the YAML parser accepts without error. At runtime, every issued JWT has exp = time.Now(), so all tokens expire at the moment of issuance and every subsequent API call is rejected.

Before fix : Server starts silently with jwtExpiration 0s, login returns an already-expired token:

$ curl -s -X POST http://localhost:8181/api/v1/authorize -H 'Content-Type: application/json' -d '{"username":<USER_NAME>,"password":<PASSWORD>}'
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."} 

$ curl -s http://localhost:8181/api/v1/devices -H "Authorization: Bearer <token>"
{"error":"invalid access token"} # immediately rejected

After fix : Server would fail to start if jwtExpiration is set to 0s

$ GIN_MODE=debug go run ./cmd/app --config config.yml
Config error: config: auth.jwtExpiration must be positive (e.g. 24h) — zero causes tokens to expire on issuance
exit status 1

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.30%. Comparing base (365531d) to head (c24ab98).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
config/config.go 58.33% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1172      +/-   ##
==========================================
+ Coverage   50.24%   50.30%   +0.05%     
==========================================
  Files         147      147              
  Lines       13656    13668      +12     
==========================================
+ Hits         6862     6876      +14     
+ Misses       6199     6194       -5     
- Partials      595      598       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents a misconfigured auth.jwtExpiration / auth.redirectionJWTExpiration (zero or negative durations) from allowing the server to start and then immediately issuing already-expired JWTs, which effectively denies access to legitimate users.

Changes:

  • Adds startup-time config validation for JWT expiration durations.
  • Introduces sentinel errors for invalid JWT expiration settings.
  • Adds unit tests covering zero/negative durations and valid defaults.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
config/config.go Adds Config.validate() and calls it from NewConfig() to fail fast on non-positive JWT expirations.
config/config_test.go Adds tests ensuring validation rejects zero/negative expirations and accepts defaults.
Suppressed comments (3)

config/config_test.go:133

  • The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
	err := cfg.validate()
	require.Error(t, err)
	assert.Contains(t, err.Error(), "auth.jwtExpiration")
}

config/config_test.go:144

  • The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
	err := cfg.validate()
	require.Error(t, err)
	assert.Contains(t, err.Error(), "auth.redirectionJWTExpiration")
}

config/config_test.go:155

  • The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
	err := cfg.validate()
	require.Error(t, err)
	assert.Contains(t, err.Error(), "auth.redirectionJWTExpiration")
}

Comment thread config/config_test.go
Comment thread config/config.go
@ShradhaGupta31
ShradhaGupta31 force-pushed the fix-CM-334-jwt-expiration branch 2 times, most recently from b8d9299 to e990ba4 Compare August 4, 2026 15:42
Comment thread config/config.go Outdated

@sudhir-intc sudhir-intc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, check if wee need to keep a minimum value of atleast 1m

sudhir-intc
sudhir-intc previously approved these changes Aug 5, 2026
@ShradhaGupta31
ShradhaGupta31 requested a review from rsdmike August 6, 2026 15:03
@madhavilosetty-intel

madhavilosetty-intel commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@ShradhaGupta31 The current validation rejects anything under 1 minute, but the commit says it’s rejecting zero/negative expirations. Please change it to <= 0.

ConsoleConfig is set to nil config.go line:353 only on validation failure, while earlier config errors leave it populated. Please keep the behavior consistent across all error paths.

@ShradhaGupta31 ShradhaGupta31 changed the title fix: reject zero/negative JWT expiration at startup fix: reject JWT expiration value at startup if less than 1 sec Aug 17, 2026
@ShradhaGupta31 ShradhaGupta31 changed the title fix: reject JWT expiration value at startup if less than 1 sec refactor: reject JWT expiration value at startup if less than 1 sec Aug 17, 2026
@ShradhaGupta31
ShradhaGupta31 force-pushed the fix-CM-334-jwt-expiration branch from f6ab15d to 365da3f Compare August 17, 2026 03:52
@ShradhaGupta31
ShradhaGupta31 force-pushed the fix-CM-334-jwt-expiration branch 2 times, most recently from ff50cb2 to df465df Compare August 17, 2026 05:21
@ShradhaGupta31

Copy link
Copy Markdown
Contributor Author

@ShradhaGupta31 The current validation rejects anything under 1 minute, but the commit says it’s rejecting zero/negative expirations. Please change it to <= 0.

ConsoleConfig is set to nil config.go line:353 only on validation failure, while earlier config errors leave it populated. Please keep the behavior consistent across all error paths.

@madhavilosetty-intel - Updated title & config.go as well.

- Modified config.go to validate jwtExpiration while console startup
- Reject non-positive values of jwtExpiration

Signed-off-by: ShradhaGupta31 <shradha.gupta@intel.com>
@ShradhaGupta31
ShradhaGupta31 force-pushed the fix-CM-334-jwt-expiration branch from df465df to 8526529 Compare August 18, 2026 05:39

@sudhir-intc sudhir-intc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.
Please ensure the CI passes before the merge

@graikhel-intel
graikhel-intel merged commit fe0cf5c into main Aug 20, 2026
19 checks passed
@graikhel-intel
graikhel-intel deleted the fix-CM-334-jwt-expiration branch August 20, 2026 22:44
@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

1 similar comment
@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

sudhir-intc added a commit that referenced this pull request Aug 25, 2026
commit 7e5511e
Merge: 86d029f c28d7a3
Author: Sudhir Pola <sudhir.pola@intel.com>
Date:   Tue Aug 25 10:10:48 2026 +0530

    Merge branch 'main' into feat/http-tenant-header

commit c28d7a3
Author: Madhavi Losetty <madhavi.losetty@intel.com>
Date:   Mon Aug 24 10:16:23 2026 -0700

    refactor(config): check admin password strength at startup (#1193)

    Warn when the configured admin password is shorter than 8 characters
    or misses a lowercase letter, uppercase letter, digit, or symbol.
    Startup continues either way.

    Generated passwords now draw one character from each required class
    and shuffle with crypto/rand, so a fresh install satisfies the same
    rule the warning describes.

    The generator draws its symbols from @ and * only, because the value
    gets pasted verbatim into files that mangle punctuation: $ and !
    expand in sh, # truncates the value in make (the Makefile does
    -include .env, where quoting does not help), and % ^ & break
    cmd.exe's set. Operators may still use any of those themselves.

    There is no upper length bound, and any non-alphanumeric counts as a
    symbol: this password is only compared against the login request, so
    a long passphrase or one using - or _ must not be called weak.

    Existing passwords are untouched: the generator only runs when no
    password is configured, and a weak value only warns.

    Co-authored-by: Ganesh Raikhelkar <ganesh.raikhelkar@intel.com>

commit 374987e
Author: Amarnath C <amarnath.c@intel.com>
Date:   Mon Aug 24 22:21:20 2026 +0530

    fix: align timeout budget with wsman client for slow devices (#1082) (#1153)

    1. httpserver read/write timeout 15s to 40s so the wsman client
      (30s) times out first with a clean 504.
    2. waitForAuth 3s to 30s so concurrent handlers share one Target
       instead of forking, preserving the library concurrency cap.
    3. expireAfter 30s to 60s to keep the authenticated Target cached
       across rapid page refreshes.

commit cc951f4
Author: Amarnath C <amarnath.c@intel.com>
Date:   Mon Aug 24 22:06:36 2026 +0530

    build(deps): bump go-wsman-messages to v2.50.2 (#1219)

    Bumps go-wsman-messages from v2.50.1 to v2.50.2.

commit 3022f37
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Aug 24 06:41:41 2026 -0700

    build(deps): bump golang from 1.26-alpine to 1.27-alpine (#1215)

    Bumps golang from 1.26-alpine to 1.27-alpine.

    ---
    updated-dependencies:
    - dependency-name: golang
      dependency-version: 1.27-alpine
      dependency-type: direct:production
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Madhavi Losetty <madhavi.losetty@intel.com>

commit f455536
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Aug 24 06:27:30 2026 -0700

    build(deps): bump github.com/getkin/kin-openapi from 0.146.0 to 0.147.0 (#1216)

    Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.146.0 to 0.147.0.
    - [Release notes](https://github.com/getkin/kin-openapi/releases)
    - [Commits](getkin/kin-openapi@v0.146.0...v0.147.0)

    ---
    updated-dependencies:
    - dependency-name: github.com/getkin/kin-openapi
      dependency-version: 0.147.0
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Madhavi Losetty <madhavi.losetty@intel.com>

commit 4cfb69f
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Aug 24 06:17:22 2026 -0700

    build(deps): bump modernc.org/sqlite from 1.56.0 to 1.57.0 (#1217)

    Bumps [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) from 1.56.0 to 1.57.0.
    - [Changelog](https://gitlab.com/cznic/sqlite/blob/master/CHANGELOG.md)
    - [Commits](https://gitlab.com/cznic/sqlite/compare/v1.56.0...v1.57.0)

    ---
    updated-dependencies:
    - dependency-name: modernc.org/sqlite
      dependency-version: 1.57.0
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 356828b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Aug 24 06:12:50 2026 -0700

    build(deps): bump the codeql-action group with 4 updates (#1218)

    Bumps the codeql-action group with 4 updates: [github/codeql-action/init](https://github.com/github/codeql-action), [github/codeql-action/autobuild](https://github.com/github/codeql-action), [github/codeql-action/analyze](https://github.com/github/codeql-action) and [github/codeql-action/upload-sarif](https://github.com/github/codeql-action).

    Updates `github/codeql-action/init` from 4.37.7 to 4.37.8
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@ff2f1c6...db488dd)

    Updates `github/codeql-action/autobuild` from 4.37.7 to 4.37.8
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@ff2f1c6...db488dd)

    Updates `github/codeql-action/analyze` from 4.37.7 to 4.37.8
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@ff2f1c6...db488dd)

    Updates `github/codeql-action/upload-sarif` from 4.37.7 to 4.37.8
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@ff2f1c6...db488dd)

    ---
    updated-dependencies:
    - dependency-name: github/codeql-action/init
      dependency-version: 4.37.8
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: codeql-action
    - dependency-name: github/codeql-action/autobuild
      dependency-version: 4.37.8
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: codeql-action
    - dependency-name: github/codeql-action/analyze
      dependency-version: 4.37.8
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: codeql-action
    - dependency-name: github/codeql-action/upload-sarif
      dependency-version: 4.37.8
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: codeql-action
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 7e02b81
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Aug 21 11:57:47 2026 -0700

    build(deps): bump github.com/stretchr/testify from 1.12.0 to 1.12.1 (#1213)

    Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.12.0 to 1.12.1.
    - [Release notes](https://github.com/stretchr/testify/releases)
    - [Commits](stretchr/testify@v1.12.0...v1.12.1)

    ---
    updated-dependencies:
    - dependency-name: github.com/stretchr/testify
      dependency-version: 1.12.1
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 6e0906e
Author: Natalie Gaston <natalie.gaston@intel.com>
Date:   Thu Aug 20 18:38:13 2026 -0700

    fix(config): validate HTTP port and harden Windows browser launch (#1198)

commit a493e12
Author: Sinchana S R <sinchana.s.r@intel.com>
Date:   Fri Aug 21 04:18:50 2026 +0530

    refactor(api): prevent integer overflow in query parameters (#1180)

    * Add validation to prevent integer overflow in query parameters (top, skip, count).
    * Returns 400 instead of 500 on invalid input.

    Co-authored-by: Sudhir Pola <sudhir.pola@intel.com>

commit fe0cf5c
Author: ShradhaGupta31 <shradha.gupta@intel.com>
Date:   Fri Aug 21 04:14:50 2026 +0530

    refactor: reject JWT expiration value at startup if less than 1 sec (#1172)

    - Modified config.go to validate jwtExpiration while console startup
    - Reject non-positive values of jwtExpiration

    Signed-off-by: ShradhaGupta31 <shradha.gupta@intel.com>
    Co-authored-by: Madhavi Losetty <madhavi.losetty@intel.com>
    Co-authored-by: Ganesh Raikhelkar <ganesh.raikhelkar@intel.com>

commit 365531d
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Aug 20 22:38:15 2026 +0000

    build(deps): bump github.com/stretchr/testify from 1.11.1 to 1.12.0 (#1205)

    Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.11.1 to 1.12.0.
    - [Release notes](https://github.com/stretchr/testify/releases)
    - [Commits](stretchr/testify@v1.11.1...v1.12.0)

    ---
    updated-dependencies:
    - dependency-name: github.com/stretchr/testify
      dependency-version: 1.12.0
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Natalie Gaston <natalie.gaston@intel.com>

commit 4c585b1
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Aug 20 15:35:21 2026 -0700

    build(deps): bump step-security/harden-runner from 2.20.1 to 2.21.0 (#1208)

    Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.20.1 to 2.21.0.
    - [Release notes](https://github.com/step-security/harden-runner/releases)
    - [Commits](step-security/harden-runner@b09bb98...05e3151)

    ---
    updated-dependencies:
    - dependency-name: step-security/harden-runner
      dependency-version: 2.21.0
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: DevipriyaS17 <devipriya.s@intel.com>

commit 9414597
Author: DevipriyaS17 <devipriya.s@intel.com>
Date:   Fri Aug 21 04:00:43 2026 +0530

    build(docker): default dev service port bindings to loopback (#1168)

    * build(docker): default dev service port bindings to loopback

    * build(docker): address review comments

    ---------

    Co-authored-by: Sudhir Pola <sudhir.pola@intel.com>

commit 001de52
Author: DevipriyaS17 <devipriya.s@intel.com>
Date:   Fri Aug 21 03:57:13 2026 +0530

    refactor(security): default useTLS to true on device creation (#1169)

    * fix(security): default useTLS to true on device creation

    * fix: add code coverage

    * refactor(security): address review comments

    * refactor(security): fix the codeql error

    ---------

    Co-authored-by: Ganesh Raikhelkar <ganesh.raikhelkar@intel.com>

commit 3003aa0
Author: Madhavi Losetty <madhavi.losetty@intel.com>
Date:   Thu Aug 20 15:20:56 2026 -0700

    refactor: address golangci-lint 2.13.1 findings (#1212)

commit 60d074d
Author: Madhavi Losetty <madhavi.losetty@intel.com>
Date:   Thu Aug 20 13:02:13 2026 -0700

    refactor(config): move config to user dir and enforce owner-only perms (#1078)

    Relocate config to the user directory and harden seedConfig error
    handling, enforcing owner-only file permissions.

    Co-authored-by: MadhaviLosetty <madhavi.losetty@gmail.com>
@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

4 similar comments
@RosieAMT

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RosieAMT

RosieAMT commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RosieAMT

RosieAMT commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RosieAMT

RosieAMT commented Sep 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.40.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants