Skip to content
Snippets Groups Projects

Path traversal middleware: log the execution time in ms

Merged David Fernandez requested to merge 413766-fix-execution-time-log into master
All threads resolved!

:deciduous_tree: Context

In Rack middleware for path traversal checks (!123477 - merged), we introduced a rack middleware with this idea of checking the request path, if a path traversal is detected, reject the request. See #413766+ for more details.

Since middlewares are executed for all requests, we are not starting with the "reject the request" part. Instead, we simply log the path traversal attempt and additionally we measure the execution time of that check. This is the simulation phase.

In this phase, one of the goals is to measure the impact (execution time) on requests. We certainly don't want to add 1sec of execution time on all requests :scream:.

The middleware is gated behind feature flags so that we can quickly disable it.

We started playing with it on staging and while trying to get the numbers for the execution time, we got only a collection of 0.

What happens is that we compute the execution time in seconds. However, the middleware logic is quite fast. When the duration_s gets into Kibana, there has to be some rounding or truncation and our result gets rounded to 0.

This MR attempts to fix that.

:thinking: What does this MR do and why?

  • Compute the path traversal middleware execution time in ms instead of s.
  • Log the value into duration_ms instead of duration_s.
  • Update the related specs.

Changelog is not needed here as the middleware is behind a feature flag .

:frame_photo: Screenshots or screen recordings

None

:gear: How to set up and validate locally

  1. In a rails console, enable the middleware and enable the execution time logging:
Feature.enable(:check_path_traversal_middleware)
Feature.enable(:log_execution_time_path_traversal_middleware)
  1. Start the server.
  2. Access http://gdk.test:8000/foo%2F../bar
  3. Check log/application_json.log and see:
{"severity":"WARN","time":"2023-10-05T16:57:41.195Z","correlation_id":"01HC0CC327PRP91T226C3J9HMJ","fullpath":"/foo%2F../bar","message":"Potential path traversal attempt detected","duration_ms":0.713,"class_name":"Gitlab::Middleware::PathTraversalCheck"}

Notice the duration_ms field that will report the execution time in ms.

:racehorse: MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Allure report

    allure-report-publisher generated test report!

    e2e-test-on-gdk: :white_check_mark: test report for 1f35035a

    expand test summary
    +-----------------------------------------------------------------------+
    |                            suites summary                             |
    +------------------+--------+--------+---------+-------+-------+--------+
    |                  | passed | failed | skipped | flaky | total | result |
    +------------------+--------+--------+---------+-------+-------+--------+
    | Data Stores      | 18     | 0      | 4       | 0     | 22    | ✅     |
    | Create           | 45     | 0      | 2       | 0     | 47    | ✅     |
    | Govern           | 35     | 0      | 0       | 0     | 35    | ✅     |
    | Plan             | 55     | 0      | 0       | 0     | 55    | ✅     |
    | Verify           | 8      | 0      | 0       | 0     | 8     | ✅     |
    | Package          | 0      | 0      | 1       | 0     | 1     | ➖     |
    | Manage           | 13     | 0      | 1       | 0     | 14    | ✅     |
    | Monitor          | 4      | 0      | 0       | 0     | 4     | ✅     |
    | Framework sanity | 0      | 0      | 1       | 0     | 1     | ➖     |
    +------------------+--------+--------+---------+-------+-------+--------+
    | Total            | 178    | 0      | 9       | 0     | 187   | ✅     |
    +------------------+--------+--------+---------+-------+-------+--------+
    Edited by Ghost User
  • David Fernandez changed the description

    changed the description

  • David Fernandez requested review from @rkumar555

    requested review from @rkumar555

  • Ravi Kumar approved this merge request

    approved this merge request

  • Ravi Kumar requested review from @dbalexandre and removed review request for @rkumar555

    requested review from @dbalexandre and removed review request for @rkumar555

  • :wave: @rkumar555, thanks for approving this merge request.

    This is the first time the merge request has been approved. To ensure full test coverage, a new pipeline will be started shortly.

    For more info, please refer to the following links:

  • Douglas Barbosa Alexandre approved this merge request

    approved this merge request

  • resolved all threads

  • mentioned in commit de1c4a28

  • added workflowstaging label and removed workflowcanary label

  • David Fernandez mentioned in merge request !152784 (merged)

    mentioned in merge request !152784 (merged)

  • Please register or sign in to reply
    Loading