Skip to content

fix: No IP address in request when directAccess is enabled#10542

Open
dblythy wants to merge 1 commit into
parse-community:alphafrom
dblythy:fix/direct-access-request-ip
Open

fix: No IP address in request when directAccess is enabled#10542
dblythy wants to merge 1 commit into
parse-community:alphafrom
dblythy:fix/direct-access-request-ip

Conversation

@dblythy

@dblythy dblythy commented Jul 4, 2026

Copy link
Copy Markdown
Member

Closes #8806

Summary by CodeRabbit

  • Bug Fixes

    • Improved how local requests are identified so server-side hooks now see a consistent loopback IP address (127.0.0.1 or ::1) depending on the environment.
    • This helps avoid unexpected IP-related behavior when requests are made directly to the server.
  • Tests

    • Added coverage to verify the IP passed to cloud hooks is correctly recognized as a loopback address.

@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a getLoopbackAddress() helper in ParseServerRESTController.js that inspects network interfaces to determine and cache a loopback IP (::1 or 127.0.0.1), applying it to config.ip in handleRequest when unset. Adds a corresponding test verifying req.ip under direct access.

Changes

Loopback IP defaulting

Layer / File(s) Summary
Loopback address helper and config.ip wiring
src/ParseServerRESTController.js
Adds os import and cached getLoopbackAddress() helper that checks for internal IPv6 loopback via os.networkInterfaces(), returning ::1 or 127.0.0.1; handleRequest sets config.ip to this value when unset.
Trigger request test for loopback IP
spec/ParseServerRESTController.spec.js
Adds a test registering a beforeSave hook to capture req.ip during a REST POST under direct access, asserting it is 127.0.0.1 or ::1.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ParseServerRESTController
  participant os
  participant CloudTrigger

  Client->>ParseServerRESTController: handleRequest()
  ParseServerRESTController->>ParseServerRESTController: load config
  alt config.ip not set
    ParseServerRESTController->>os: networkInterfaces()
    os-->>ParseServerRESTController: interface list
    ParseServerRESTController->>ParseServerRESTController: getLoopbackAddress() returns ::1 or 127.0.0.1
    ParseServerRESTController->>ParseServerRESTController: set config.ip
  end
  ParseServerRESTController->>CloudTrigger: invoke beforeSave with req.ip set
  CloudTrigger-->>Client: response
Loading

Related Issues: #8806

Suggested labels: bug, low-risk

Suggested reviewers: parse-community maintainers

🐰✨

A hop through interfaces, loopback found,
No more undefined IPs hanging around,
::1 or 127, whichever fits,
Direct access requests now pass the tests!

🚥 Pre-merge checks | ✅ 5 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only says Closes #8806`` and omits the required Issue, Approach, and Tasks sections. Add the template sections with a brief issue summary, implementation approach, and completed task checkboxes.
Engage In Review Feedback ❓ Inconclusive No local evidence of review comments or discussion is present, so engagement with feedback can’t be verified from the repo alone. Provide the PR review thread or a response/commit showing the feedback was discussed and either implemented or retracted.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the fix and uses the required fix: prefix.
Linked Issues check ✅ Passed The code and test address #8806 by ensuring trigger requests get a loopback IP under directAccess: true.
Out of Scope Changes check ✅ Passed The changes stay focused on the directAccess IP bug and related test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Security Check ✅ Passed Change only derives a local loopback IP from os.networkInterfaces and assigns it to internal config; no user-controlled input or auth/path handling changed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (cce91e5) to head (c29d393).
⚠️ Report is 1 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha   #10542   +/-   ##
=======================================
  Coverage   92.66%   92.67%           
=======================================
  Files         193      193           
  Lines       16981    16990    +9     
  Branches      248      248           
=======================================
+ Hits        15736    15745    +9     
  Misses       1224     1224           
  Partials       21       21           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dblythy

dblythy commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/ParseServerRESTController.js (1)

5-18: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider guarding os.networkInterfaces() against failure.

If this call throws (e.g., in a sandboxed/restricted runtime with limited OS permissions), loopbackAddress never gets cached, so every subsequent handleRequest call without a preset config.ip will re-throw synchronously, breaking all direct-access requests in that environment persistently (not just once).

🛡️ Suggested defensive fallback
 function getLoopbackAddress() {
   if (loopbackAddress) {
     return loopbackAddress;
   }
-  const interfaces = os.networkInterfaces();
-  const hasIPv6Loopback = Object.values(interfaces).some(addresses =>
-    addresses?.some(iface => iface.internal && (iface.family === 'IPv6' || iface.family === 6))
-  );
-  loopbackAddress = hasIPv6Loopback ? '::1' : '127.0.0.1';
+  let hasIPv6Loopback = false;
+  try {
+    const interfaces = os.networkInterfaces();
+    hasIPv6Loopback = Object.values(interfaces).some(addresses =>
+      addresses?.some(iface => iface.internal && (iface.family === 'IPv6' || iface.family === 6))
+    );
+  } catch (e) {
+    // Fall back to IPv4 loopback if interfaces cannot be enumerated.
+  }
+  loopbackAddress = hasIPv6Loopback ? '::1' : '127.0.0.1';
   return loopbackAddress;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ParseServerRESTController.js` around lines 5 - 18, The getLoopbackAddress
helper currently assumes os.networkInterfaces() always succeeds, so a throw
leaves loopbackAddress unset and causes repeated synchronous failures on every
handleRequest path that relies on the default address. Update getLoopbackAddress
to defensively catch failures around os.networkInterfaces(), then cache a safe
fallback value (for example the IPv4 loopback) so subsequent calls do not keep
re-throwing; keep the logic contained in getLoopbackAddress and preserve the
existing loopbackAddress memoization behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/ParseServerRESTController.js`:
- Around line 5-18: The getLoopbackAddress helper currently assumes
os.networkInterfaces() always succeeds, so a throw leaves loopbackAddress unset
and causes repeated synchronous failures on every handleRequest path that relies
on the default address. Update getLoopbackAddress to defensively catch failures
around os.networkInterfaces(), then cache a safe fallback value (for example the
IPv4 loopback) so subsequent calls do not keep re-throwing; keep the logic
contained in getLoopbackAddress and preserve the existing loopbackAddress
memoization behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 10851333-d9b3-4ebd-9cf9-2e377c70b05d

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9d53a and c29d393.

📒 Files selected for processing (2)
  • spec/ParseServerRESTController.spec.js
  • src/ParseServerRESTController.js

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No IP address in request when directAccess: true

1 participant