Skip to content

Conversation

@hmcguire-shopify
Copy link
Contributor

One of the changes in Rack 3.2 was a fix to ensure at least one of PATH_INFO or SCRIPT_NAME are non-empty. This causes a Rack::Lint error in Pitchfork for OPTIONS * requests because Pitchfork has a nil PATH_INFO for these.

This commit fixes the issue by setting PATH_INFO to *. It also undoes some of the previous changes from the commit to support Rack 3.1 because they appear to have no effect.

The undone change is the moving of PATH_INFO = "*" and REQUEST_PATH = "*" to the fragment action. From what I can tell, this part of the state machine is not involved with the request uri, and so this if statement is not evaluated in OPTIONS * requests:

  Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;

Then, the actual fix is manually setting the PATH_INFO to * when that's the given REQUEST_URI. Normally, PATH_INFO is handled in the request_uri action, but that action is only run for URIs starting with / (and explicitly excludes *).

@hmcguire-shopify
Copy link
Contributor Author

Looks like this may be difficult to do compatibly from Rack 2 through 3.2 🙁

@byroot
Copy link
Contributor

byroot commented Dec 5, 2025

compatibly from Rack 2 through 3.2

You can always check the rack version and add a small compatibility layer.

@hmcguire-shopify hmcguire-shopify force-pushed the hm-muwxvywlrxnkwqlx branch 5 times, most recently from 6702a97 to b678ae9 Compare December 8, 2025 16:06
@hmcguire-shopify
Copy link
Contributor Author

You can always check the rack version and add a small compatibility layer.

Done 👍 I think this should be good now

lib/pitchfork.rb Outdated
Comment on lines 196 to 198
rescue LoadError
warn 'rack not available, functionality reduced'
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Pitchfork has a runtime dependency on rack. So this shouldn't be needed.

lib/pitchfork.rb Outdated
Comment on lines 18 to 19
singleton_class.attr_accessor :path_info_requires_leading_slash
self.path_info_requires_leading_slash = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just make this a constant.

Rack is a dependency in the gemspec
Copy link
Contributor

@byroot byroot left a comment

Choose a reason for hiding this comment

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

LGTM

e['pitchfork.socket'] = socket
e['rack.hijack'] = self

if Pitchfork::PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if Pitchfork::PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*'
if PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*'

nitpick

One of the changes in Rack 3.2 was a fix to ensure at least one of
PATH_INFO or SCRIPT_NAME are non-empty. This causes a Rack::Lint error
in Pitchfork for `OPTIONS *` requests because Pitchfork has a `nil`
`PATH_INFO` for these.

This commit fixes the issue by setting `PATH_INFO` to `*`. It also undoes
some of the previous changes from the [commit][1] to support Rack 3.1
because they appear to have no effect.

The undone change is the moving of `PATH_INFO = "*"` and `REQUEST_PATH =
"*"` to the `fragment` action. From what I can tell, this part of the
state machine is not involved with the request uri, and so this if
statement is not evaluated in `OPTIONS *` requests:

```
  Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
```

Then, the actual fix is manually setting the `PATH_INFO` to `*` when
that's the given `REQUEST_URI`. Normally, `PATH_INFO` is handled in the
`request_uri` action, but that action is only run for URIs starting with
`/` (and explicitly excludes `*`).

[1]: 65725c5
@hmcguire-shopify hmcguire-shopify merged commit 64bc71c into master Dec 9, 2025
23 of 24 checks passed
@hmcguire-shopify hmcguire-shopify deleted the hm-muwxvywlrxnkwqlx branch December 9, 2025 17:27
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