Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build: Make middleware-mockserver not crash on reading nonexistent files #5579

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

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

mgol
Copy link
Member

@mgol mgol commented Nov 4, 2024

Summary

fs.readFileSync crashes when a non-existing file is passed to it. Some APIs of middleware-mockserver read a file the path of which depends on query parameters, making it possible to crash it by providing such a parameter. The old PHP server doesn't have these issues.

To fix this, wrap all fs.readFileSync occurrences with a function that falls back to the string "ERROR".

Checklist

`fs.readFileSync` crashes when a non-existing file is passed to it. Some APIs
of `middleware-mockserver` read a file the path of which depends on query
parameters, making it possible to crash it by providing such a parameter. The
old PHP server doesn't have these issues.

To fix this, wrap all `fs.readFileSync` occurrences with a function that falls
back to the string `"ERROR"`.
@mgol mgol self-assigned this Nov 4, 2024
@timmywil
Copy link
Member

timmywil commented Nov 4, 2024

I'm curious what prompted this.

@mgol
Copy link
Member Author

mgol commented Nov 4, 2024

I'm curious what prompted this.

@timmywil I was testing whether you can abuse the param-based readFile from

const body = fs.readFileSync(
`${ __dirname }/data/csp-nonce${ testParam }.html` ).toString();
and, while testing, I was surprised to see everything stopped working. Then I realized if I pass anything other than external or globaleval, it will crash the server.

I felt it's a good property of even a dev server to not crash on a simple GET request like that.

@mgol mgol added the Build label Nov 4, 2024
@mgol mgol merged commit d5ebb46 into jquery:main Nov 5, 2024
17 checks passed
@mgol mgol deleted the middleware-crashes branch November 5, 2024 21:54
@mgol mgol added this to the 4.0.0 milestone Nov 5, 2024
@mgol mgol removed the Needs review label Nov 5, 2024
mgol added a commit that referenced this pull request Nov 5, 2024
`fs.readFileSync` crashes when a non-existing file is passed to it. Some APIs
of `middleware-mockserver` read a file the path of which depends on query
parameters, making it possible to crash it by providing such a parameter. The
old PHP server doesn't have these issues.

To fix this, wrap all `fs.readFileSync` occurrences with a function that falls
back to the string `"ERROR"`.

Closes gh-5579

(cherry picked from commit d5ebb46)
@mgol mgol modified the milestones: 4.0.0, 3.7.2 Nov 5, 2024
@mgol
Copy link
Member Author

mgol commented Nov 5, 2024

Landed on main in d5ebb46 and on 3.x-stable in be4f9ec.

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

Successfully merging this pull request may close these issues.

2 participants