-
Notifications
You must be signed in to change notification settings - Fork 569
gopherjs test
+ nodejs require == broken and possible security issue
#303
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
Comments
I thought I would try my hand at this again today, and came to the conclusion that it's not really a straight-forward problem to solve. I think some discussion will be necessary to decide how it should even be approached. Imagine an app, The question is, where should node look for the When I first filed this bug, my assumption was that it should look in the Assuming
This would not (and probably should not), in any way, populate the respective So where does that leave us? There are (at least) 3 scenarios to be dealt with:
As a GopherJS coder, I suppose what at present makes sense to me, would be the ability to provide a But I may be suffering from tunnel vision, and may be missing something obviously better. Are there other thoughts on how to accomplish this, or problems with my understanding? |
#333 is a partial fix for this issue, and I believe it is adequately tested to be merged as soon as someone else signs off on it. Still outstanding, and to be addressed in future PRs:
|
I think a page should never load more than one file generated by GopherJS. For one, you would duplicate all dependencies (especially core packages) that could be shared. Also those two modules could only talk to each other via JS API, not Go API. Instead, GopherJS libraries should simply be installed via @flimzy I think you are right that |
I agree.
I think it is reasonable to discourage this use case, but it may not be possible (and probably neither necessary) to outright prohibit it. Some day someone may write JS bindings for a Go library. That's not a situation that GopherJS currently makes "easy" (by virtue of the fact that a 'main' package is necessary to build a GopherJS package), but it certainly is possible. If then someone else were to write GopherJS bindings for that node library, we'd end up double-including all of those dependencies... hopefully that situation will never arise, though.
If this is an acceptable solution, it probably would be cleaner, and would simultaneously address the security concerns. My first half-attempt at that method had some problems, but they should be easy to overcome. I'll work on that PR. |
There's still the outstanding issue of multiple Go dependencies, each with node dependencies. (I'm not sure if your comment was meant to address that or not... let me spell out that scenario just in case it's not clear).
In this scenario, we need to |
I think it's not the job of GopherJS to care that much about |
That seems quite reasonable... and I was starting to come to a similar conclusion myself after thinking about what I had written yesterday. |
I agree with the "do less and enable more" part. :P I also think GopherJS itself should be just a compiler. The |
Fixed with 158ce0b |
Is this really fixed? The tests still use the temporary directory. |
No it's not. I was confusing this issue with #306, which was already closed. |
I'm trying to better understand this issue, so I have questions/comments. As far as I can tell, the above is not quite true. When
If you look at its implementation, it uses the current time in nanoseconds and process ID to seed a random number generator when coming up with a random filename. Ok, I think I see the problem. It's because Is it possible to either use I think the ideal solution to this problem would be to continue to use a temporary dir in Sorry if I'm suggesting things that won't work, but I'd really like to understand the problem and dismiss potential solutions for concrete reasons before settling to using cwd for writing temporary files. IMO that's best to avoid if possible. Final question, what are the implications of writing temp files to cwd? I see they're removed afterwards, right, so it would just be during a |
I don't think the difference between The core issue is that nodejs doesn't look only in the current directory--it also considers all parent directories (see here). So if the working directory or any parent directory is writable by some untrusted user, there is a potential for abuse. So, if we use In a "normal" nodejs environment this is not, I suppose, considered a security issue, because nodejs packages are typically installed in secure locations, where parent directories are typically only writable by the owner of the file, or root (or perhaps some trusted group). My patch builds and executes the packages in the same directory where the Go package lives. This works fine, as long as we have write access on this directory, but we don't in the case of the upstream Go tests. And we might not in other scenarios as well (I'm not sure). Perhaps an alternative would be to use some sort of per-user temp directory. ( Re: #333, yes, that is an attempt to leave the temp files where they are in
As mentioned above, it breaks when we don't have permission to write to cwd. The only case I've seen this happen is with the upstream Go tests. But perhaps it could happen in other situations (??). It may seem "sloppy", I suppose, to create temp files in cwd, but given that we already expect any build process to write output files there, I wonder if anyone would consider it a problem to write "temporary" output files there? Perhaps this is a matter of opinion more than anything?? (I hope I've addressed each of your questions now) |
You have addressed most/all of my questions, thanks for providing that information.
I see. So it's not a problem when using cwd, even though one of the parent folders might be But it is a problem when using any subdirectory in Is the reason for that being a potential risk because you might not have all required dependencies available, so it would end up looking in parent folders (and be satisfied by an unexpected alternative package; instead of failing to compile altogether because the dependency is missing)?
That's a good point, I think if there's no way to reliably resolve security and other concerns with
I think it's worth investigating, but like I said above, if there's no way, then cwd is fine. It'd be a shame to use cwd for temp files if there's some way not to, IMO. |
That's exactly right. Any missing dependency has the potential to be provided by an untrusted user. And lest we be tempted to think it's a small problem, let me suggest that I think it's virtually guaranteed that many packages will be built with missing node dependencies. Simply executing 'gopherjs build' before 'npm install' is all it would take. And unless GopherJS is going to start trying to manage/enforce node/npm requirements (which I think we all agree is beyond the scope of GopherJS), it's bound to happen--probably frequently.
I'll try to look into this some time this week, and see how possible/messy it would be to approach things this way. |
I dug into this a bit over my lunch hour. There's not an easy way to modify node's environment such that it won't look in This internal list of paths is accessible, from within the nodejs process, as part of the process data structure, specifically
It may be possible to modify this data structure from within the JS, but before So after all this, writing temp files to the CWD looks like a simpler solution to me. What do you think? |
I agree. |
So where does that leave us? Do you have any bright ideas to avoid the environment variable in my PR? |
No, I think we should proceed as is. I can't think of any better way right now, and all the constraints seem to suggest this is the only way to resolve the underlying issue. Perhaps after using the new approach for some time, we'll have ideas for improvements, or perhaps it'll turn out not to be something on anyone's minds. In either case, possible future followup changes can be seen as optional enhancements to this solution. |
- Close file handle to the temp file early, since we are not actually using it. - Clean the temporary file up after test execution finished to reduce the clutter in the current directory. I was also going to move temporary files into the OS's temp directory, but it turns out using current directory is deliberate: gopherjs#303.
- Include Go package name in the temp file name. - Close file handle to the temp file early, since we are not actually using it. - Clean the temporary file up after test execution finished to reduce the clutter in the current directory. I was also going to move temporary files into the OS's temp directory, but it turns out using current directory is deliberate: gopherjs#303.
I'm trying to write some tests for my PouchDB bindings, which naturally require the node pouchdb library. So I was trying this:
But this fails when running
gopherjs test
, because in this case, the file runs from /tmp, andnpm
didn't install my dependencies in/tmp
for obvious reasons. :)For now I worked around the problem thusly:
And my code is working.
But as I was considering the implications of this, I think it's more than a minor inconvenience. It could be a potential security concern, as a malicious user of the same system might put a phony 'pouchdb' library in /tmp, and the next time I run my test...
A couple possible solutions I've thought of:
process.paths
to reflect the location of the Go source, rather than GopherJS's temporary output. If this is easy, it may be the best solution. To avoid the security issue described above, it ought to completely replace the existingprocess.paths
values, not simply add to them..test.1234567
in place of/tmp/1234567
. This might be preferable in the case that other modules (in Node or Go) try to do the same trick, and read files (executable code, or config files, etc) from a path relative to the running file.The text was updated successfully, but these errors were encountered: