Skip to content

Filename '..' causes an Error 500 when used in the TUS protocol #1002

Closed

Description

@individual-it

try to create a file called ..
curl -XPOST https://localhost:9200/remote.php/dav/files/Einstein/ -ueinstein:relativity -k -v -H'Tus-Resumable: 1.0.0' -H'Upload-Length: 10' -H'Upload-Metadata: filename Li4='

OCIS logs:

2020-12-02T15:34:18+05:45 INF access-log from=127.0.0.1:54328 method=POST path=/remote.php/dav/files/Einstein/ service=proxy
goroutine 307 [running]:
runtime/debug.Stack(0x0, 0x28af0c34f9b2a2b5, 0xfd78626c609640a4)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/cs3org/reva/internal/grpc/interceptors/recovery.recoveryFunc(0x400aee0, 0xc000f5a6f0, 0x3452640, 0xc00034cad0, 0x0, 0x0)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/interceptors/recovery/recovery.go:48 +0x26
github.com/grpc-ecosystem/go-grpc-middleware/recovery.recoverFrom(0x400aee0, 0xc000f5a6f0, 0x3452640, 0xc00034cad0, 0x3b4ae98, 0xc0003b0c20, 0x14a42c6)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/recovery/interceptors.go:61 +0x5a
github.com/grpc-ecosystem/go-grpc-middleware/recovery.UnaryServerInterceptor.func1.1(0xc0003b13df, 0x400aee0, 0xc000f5a6f0, 0xc0002b1540, 0xc0003b1488)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/recovery/interceptors.go:29 +0x6d
panic(0x3452640, 0xc00034cad0)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/cs3org/reva/internal/grpc/services/gateway.(*svc).split(0xc00132a000, 0x400aee0, 0xc000f5aa50, 0x56845ef, 0x1, 0x2, 0x0)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/services/gateway/storageprovider.go:2019 +0x513
github.com/cs3org/reva/internal/grpc/services/gateway.(*svc).isSharedFolder(...)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/services/gateway/storageprovider.go:1994
github.com/cs3org/reva/internal/grpc/services/gateway.(*svc).Stat(0xc00132a000, 0x400aee0, 0xc000f5aa50, 0xc0000f4230, 0xc00132a000, 0x341f200, 0x3f51710)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/services/gateway/storageprovider.go:1344 +0x657
github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1._GatewayAPI_Stat_Handler.func1(0x400aee0, 0xc000f5aa50, 0x38c7500, 0xc0000f4230, 0x39888a0, 0xc0003c4100, 0x400aee0, 0xc000f5aa50)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/cs3/gateway/v1beta1/gateway_api.pb.go:2638 +0x89
github.com/cs3org/reva/internal/grpc/interceptors/auth.NewUnary.func1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c3c0, 0x0, 0x0, 0x0, 0x0)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/interceptors/auth/auth.go:96 +0x32b
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0x35a3540, 0x594e918, 0x0, 0x0)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x63
github.com/grpc-ecosystem/go-grpc-middleware/recovery.UnaryServerInterceptor.func1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c3e0, 0x0, 0x0, 0x0, 0x0)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/recovery/interceptors.go:33 +0xf7
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0xc00040e700, 0x7f2139baa460, 0x0, 0xc000f5c4c0)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x63
github.com/cs3org/reva/internal/grpc/interceptors/log.NewUnary.func1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c400, 0x0, 0xc000f5c4a0, 0x1, 0x1)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/interceptors/log/log.go:39 +0x9e
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0x400aee0, 0xc000f5a6f0, 0x38c7500, 0xc0000f4230, 0x2, 0x400aee0, 0xc000f5a6f0, 0xc000f5a6c0)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x63
github.com/cs3org/reva/internal/grpc/interceptors/token.NewUnary.func1(0x400aee0, 0xc000f5a690, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c420, 0x39f6e80, 0xc000fc6480, 0x400aee0, 0xc000f5a690)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/interceptors/token/token.go:44 +0xb4
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0x400aee0, 0xc000f5a690, 0x38c7500, 0xc0000f4230, 0xc000f5a690, 0xc0004a0000, 0x4f, 0x1f4)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x63
github.com/cs3org/reva/internal/grpc/interceptors/appctx.NewUnary.func1(0x400aee0, 0xc000f5a630, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c440, 0x294975a, 0x37b6d00, 0xc000f5c460, 0xc000f5c3a0)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/internal/grpc/interceptors/appctx/appctx.go:36 +0x4fc
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1(0x400aee0, 0xc000f5a630, 0x38c7500, 0xc0000f4230, 0xc000494000, 0xc000f5c360, 0xc000275ac0, 0x14525a8)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x63
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1(0x400aee0, 0xc000f5a630, 0x38c7500, 0xc0000f4230, 0xc000f5c3a0, 0xc000f5c3c0, 0xc001513b30, 0x14ee438, 0x3840140, 0xc000f5a630)
	/home/artur/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/chain.go:34 +0xd5
github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1._GatewayAPI_Stat_Handler(0x3a753c0, 0xc00132a000, 0x400aee0, 0xc000f5a630, 0xc000fc63c0, 0xc0004185d0, 0x400aee0, 0xc000f5a630, 0xc000a247c8, 0x5)
	/home/artur/go/pkg/mod/github.com/cs3org/[email protected]/cs3/gateway/v1beta1/gateway_api.pb.go:2640 +0x14b
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00116e600, 0x402d980, 0xc000543500, 0xc000494000, 0xc000418810, 0x564ee08, 0x0, 0x0, 0x0)
	/home/artur/go/pkg/mod/google.golang.org/[email protected]/server.go:1024 +0x4f4
google.golang.org/grpc.(*Server).handleStream(0xc00116e600, 0x402d980, 0xc000543500, 0xc000494000, 0x0)
	/home/artur/go/pkg/mod/google.golang.org/[email protected]/server.go:1313 +0xd99
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000294980, 0xc00116e600, 0x402d980, 0xc000543500, 0xc000494000)
	/home/artur/go/pkg/mod/google.golang.org/[email protected]/server.go:722 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/home/artur/go/pkg/mod/google.golang.org/[email protected]/server.go:720 +0xa1
2020-12-02T15:34:18+05:45 ERR split: len(parts) < 2: path:/ parts:[] pkg=rgrpc service=storage traceid=b5a2b2f9340caf28a44096606c6278fd
2020-12-02T15:34:18+05:45 ERR unary code=Internal end="02/Dec/2020:15:34:18 +0545" from=tcp://127.0.0.1:47280 pkg=rgrpc service=storage start="02/Dec/2020:15:34:18 +0545" time_ns=313914 traceid=b5a2b2f9340caf28a44096606c6278fd uri=/cs3.gateway.v1beta1.GatewayAPI/Stat user-agent=grpc-go/1.26.0
2020-12-02T15:34:18+05:45 ERR error sending grpc stat request error="rpc error: code = Internal desc = split: len(parts) < 2: path:/ parts:[]" pkg=rhttp service=storage traceid=b5a2b2f9340caf28a44096606c6278fd

Activity

  1. changed the title [-]filename '..' causes an Error 500 when used in the TUS protocol[/-] [+]Filename '..' causes an Error 500 when used in the TUS protocol[/+] on Jan 13, 2021
  2. added
    Category:Defect
    on Jan 13, 2021
  3. kobergj commented on Jun 3, 2024

    @kobergj
    Contributor

    There is no panic anymore (which is good). However server still reacts strangely.
    When trying to create .. file inside a folder, ocis responds 500 Internal Server Error, error log:

    2024-06-03T16:06:21+02:00 ERR failed to initiate upload error="Decomposedfs: error getting parent : decomposedfs: root has no parent" pkg=rgrpc service=storage-users status={"code":15,"message":"error getting upload id: Decomposedfs: error getting parent : decomposedfs: root has no parent","trace":"8fb814691e52ef5210d0a1014b1a067d"} traceid=8fb814691e52ef5210d0a1014b1a067d
    2024-06-03T16:06:21+02:00 ERR Internal Server Error code=500 name=com.owncloud.web.ocdav path=/users/93a2c474-db76-4676-8abc-6cd1e545f13c request-id=jkoberg-20ud0010ge/d9op1AVpBO-001283 service=ocdav status={"code":15,"message":"error getting upload id: Decomposedfs: error getting parent : decomposedfs: root has no parent","trace":"8fb814691e52ef5210d0a1014b1a067d"} traceid=8fb814691e52ef5210d0a1014b1a067
    

    When trying to create .. file on a space root ocis will respond 405 Method Not Allowed with no error log.

    Both is wrong. Ocis should return a 400 Bad Request in both cases.

  4. moved this from Qualification to Prio 3 or less in Infinite Scale Team Boardon Jun 3, 2024
  5. self-assigned this
    on Jun 10, 2024
  6. dragonchaser commented on Jun 10, 2024

    @dragonchaser
    Contributor

    ATM I get 3 different results:

    • First attempt on empty personal space: 403 Forbidden
    • Second attempt: 412 Percondition Failed
    • Third attempt: 201 Created

    This looks somewhat fishy.....

    Update:

    1. Result 2 and 3 are not deterministic...... they can trade places 😕
    2. There seems to be a timing issue as well, when I run it with a debugger setting breakpoints in the InitiateFileUpload func in reva/internal/grpc/services/storageprovider/storageprovider.go I only get 201 Created 😱
  7. dragonchaser commented on Jun 13, 2024

    @dragonchaser
    Contributor

    The approach to disallow uploading .. with the validators in reva makes things worse, fixes this issue, but breaks webdav... back to square 1...

  8. dragonchaser commented on Jun 18, 2024

    @dragonchaser
    Contributor

    Blocked for now, need to clarify with @butonic

  9. butonic commented on Jun 24, 2024

    @butonic
    Contributor

    TL;dr AFAICT we need to always call path.Clean() ... maybe we forgot that somewhere?

    Long version summoning RFC 3986 3.3. Path:

    [...]
    The path segments "." and "..", also known as dot-segments, are
    defined for relative reference within the path name hierarchy. They
    are intended for use at the beginning of a relative-path reference
    (Section 4.2) to indicate relative position within the hierarchical
    tree of names. This is similar to their role within some operating
    systems' file directory structures to indicate the current directory
    and parent directory, respectively. However, unlike in a file
    system, these dot-segments are only interpreted within the URI path
    hierarchy and are removed as part of the resolution process (Section
    5.2).
    [...]

    5.2. Relative Resolution
    This section describes an algorithm for converting a URI reference
    that might be relative to a given base URI into the parsed components
    of the reference's target. The components can then be recomposed, as
    described in Section 5.3, to form the target URI. This algorithm
    provides definitive results that can be used to test the output of
    other implementations. Applications may implement relative reference
    resolution by using some other algorithm, provided that the results
    match what would be given by this one.
    5.2.4. Remove Dot Segments

    The pseudocode also refers to a "remove_dot_segments" routine for
    interpreting and removing the special "." and ".." complete path
    segments from a referenced path. This is done after the path is
    extracted from a reference, whether or not the path was relative, in
    order to remove any invalid or extraneous dot-segments prior to
    forming the target URI. Although there are many ways to accomplish
    this removal process, we describe a simple method using two string
    buffers.

    1. The input buffer is initialized with the now-appended path
      components and the output buffer is initialized to the empty
      string.

    2. While the input buffer is not empty, loop as follows:

      A. If the input buffer begins with a prefix of "../" or "./",
      then remove that prefix from the input buffer; otherwise,

      B. if the input buffer begins with a prefix of "/./" or "/.",
      where "." is a complete path segment, then replace that
      prefix with "/" in the input buffer; otherwise,

      C. if the input buffer begins with a prefix of "/../" or "/..",
      where ".." is a complete path segment, then replace that
      prefix with "/" in the input buffer and remove the last
      segment and its preceding "/" (if any) from the output
      buffer; otherwise,

      D. if the input buffer consists only of "." or "..", then remove
      that from the input buffer; otherwise,

      E. move the first path segment in the input buffer to the end of
      the output buffer, including the initial "/" character (if
      any) and any subsequent characters up to, but not including,
      the next "/" character or the end of the input buffer.

    3. Finally, the output buffer is returned as the result of
      remove_dot_segments.

    Note that dot-segments are intended for use in URI references to
    express an identifier relative to the hierarchy of names in the base
    URI. The remove_dot_segments algorithm respects that hierarchy by
    removing extra dot-segments rather than treat them as an error or
    leaving them to be misinterpreted by dereference implementations.

    The following illustrates how the above steps are applied for two
    examples of merged paths, showing the state of the two buffers after
    each step.

     STEP   OUTPUT BUFFER         INPUT BUFFER
    
      1 :                         /a/b/c/./../../g
      2E:   /a                    /b/c/./../../g
      2E:   /a/b                  /c/./../../g
      2E:   /a/b/c                /./../../g
      2B:   /a/b/c                /../../g
      2C:   /a/b                  /../g
      2C:   /a                    /g
      2E:   /a/g
    
     STEP   OUTPUT BUFFER         INPUT BUFFER
    
      [1](https://datatracker.ietf.org/doc/html/rfc3986#section-1) :                         mid/content=5/../6
      2E:   mid                   /content=5/../6
      2E:   mid/content=5         /../6
      2C:   mid                   /6
      2E:   mid/6
    

    Some applications may find it more efficient to implement the
    remove_dot_segments algorithm by using two segment stacks rather than
    strings.

     Note: Beware that some older, erroneous implementations will fail
     to separate a reference's query component from its path component
     prior to merging the base and reference paths, resulting in an
     interoperability failure if the query component contains the
     strings "/../" or "/./".
    
  10. dragonchaser commented on Jun 25, 2024

    @dragonchaser
    Contributor

    @butonic thx, So I assume it would be sane to disallow ".." as standalone path as proposed in cs3org/reva#4721. This would just leave us with the non-deterministic behavior of the storage list.

  11. butonic commented on Jun 25, 2024

    @butonic
    Contributor

    yes. that should result in a bad request error imo

  12. dragonchaser commented on Jun 25, 2024

    @dragonchaser
    Contributor

    It does randomly 😆

  13. micbar commented on Jul 8, 2024

    @micbar
    Contributor

    Reva bump was merged.

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

Metadata

Metadata

Assignees

Labels

Category:DefectStatus:BlockedType:Bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions