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

Fixing Audit issues LOW-6 to LOW-10 #12

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

erikbosch
Copy link
Contributor

@erikbosch erikbosch commented Jan 17, 2024

In short:

  • Up to now our code quite much relies on that Protobuf messages looks like how they are currently populated by Databroker
  • This PR covers some corner cases like if fields are missing
  • The submodule update is just to use kuksa.val after removal of kuksa-client, to avoid that you see the same file twice in different locations

):

raise_error = False
if (error and error.get('code') != 200):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed in tests that we never will be equal to http.HTTPStatus.OK as it gets translated to the corresponding number

if message.HasField('timestamp'):
# Sanity check, is date before year 2500
# Technically up to 9999 is allowed
if message.timestamp.seconds > 16725225600:
Copy link
Contributor

Choose a reason for hiding this comment

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

why check for year 2500 and not now?

Copy link
Contributor Author

@erikbosch erikbosch Jan 18, 2024

Choose a reason for hiding this comment

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

We could do that, but that then implies that we assume that the client knows current time. There could also be some time skew, especially for subscriptions, so only accepting timestamps that are "older" than client time is maybe too strict.

But this can be discussed - shall we assume that client has a reasonably correct time and discard values that are in the future (maybe add some offset, like accept a few minutes time skew). I believe it does not matter most times you run on a virtual box, but could be more of a problem if you run on target devices without a functional real time clock

For now the test is a very rough sanity test that timestamp does not seem to malformed, and likely our code will no longer be in use year 2500

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SebastianSchildt - any thoughts here? I.e. shall we have a stricter requirement on times received?

Or is that potentially part of a wider overhaul of how we handle time and timestamps? I am thinking - would it make sense to have a dynamic read-only datapoint like Kuksa.Databroker.Time which clients/providers could call to make sure that the client and Databroker has roughly the same understanding of time. Could be useful information for example if token validation fail, or if we would implement a stricter check here which fails as either broker or client does not know the correct time.

Copy link
Contributor

Choose a reason for hiding this comment

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

@erikbosch It might makes sense to put some sanity check here, to make sure the ToDatetime can suceed, but if I look at the finding in the audit, hasn't the fault already happened earlier? Because I see a proto-related abcktrace

File ~/.../site-packages/google/protobuf/internal/well_known_types.py:232, in ,→ Timestamp.ToDatetime(self, tzinfo)
  215 """Converts Timestamp to a datetime.
  ...
  --> 232 delta = datetime.timedelta(
      233     seconds=self.seconds,
      234     microseconds=_RoundTowardZero(self.nanos, _NANOS_PER_MICROSECOND),
235 )
  OverflowError: days=1628906115; must have magnitude <= 999999999}

and as this function already receives and types_pb2.Datapoint does it imply the error happened earlier?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ignore that, I do see that we call this directly with timestamp = message.timestamp.ToDatetime

I would just instead of doing an arbitrary limit, call that function in a try/except block, if it fails we can still return none

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to try/except now, so now we supports dates up to 9999-12-31 🥇

Copy link
Contributor

@lukasmittag lukasmittag left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasmittag lukasmittag merged commit 627a280 into eclipse-kuksa:main Jan 30, 2024
7 checks passed
@SebastianSchildt SebastianSchildt deleted the erik_auit branch June 10, 2024 12:53
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

Successfully merging this pull request may close these issues.

3 participants