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

403 when uploading file with special char #75

Open
phhoef opened this issue Feb 29, 2024 · 0 comments
Open

403 when uploading file with special char #75

phhoef opened this issue Feb 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@phhoef
Copy link

phhoef commented Feb 29, 2024

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_`,
	}
@phhoef phhoef added the bug Something isn't working label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant