Skip to content

403 when uploading file with special char #75

@phhoef

Description

@phhoef

When uploading a file with special chars as name, I see a 403 error "Access denied".
As I can upload files with a different name, I assume it's not actually a permission problem.

I add the file with the following code

	name := encName(input.Name) + ext
	resp, err := input.Parent.Files().AddChunked(name,
		bytes.NewReader(input.Content),
		&api.AddChunkedOptions{
			Overwrite: input.Overwrite,
		})

The input.Name is a.b/c;6
I try to encode the name to remove the special chars. I did something similar with pnpjs and the following logic worked for nodejs

func encName(s string) string {
	replacements := map[string]string{
		`"`: `%22`,
		`*`: `%2A`,
		`:`: `%3A`,
		`<`: `%3C`,
		`>`: `%3E`,
		`?`: `%3F`,
		`/`: `%2F`,
		`\`: `%5C`,
		`|`: `%7C`,
	}

	for k, v := range replacements {
		s = strings.ReplaceAll(s, k, v)
	}
	return s
}

Is it possible, that the % is not properly encoded when making the call and some weird url is made?

When using the following replacements, it is working fine

	replacements := map[string]string{
		`"`: `_22_`,
		`*`: `_2A_`,
		`:`: `_3A_`,
		`<`: `_3C_`,
		`>`: `_3E_`,
		`?`: `_3F_`,
		`/`: `_2F_`,
		`\`: `_5C_`,
		`|`: `_7C_`,
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions